Functions
goslin_rest : Configuration of the API
Module configuring and instantiating the API-REST of Goslin.
Creation of the local database
- main.goslin_rest.create_local_database(path)
Create a local database from the LipidMaps Structure Database.
This local database is created from the SDF file containing the LipidMaps Structure Database and is stored in the LIPIDMAPS_DATABASE variable in the form of a list.
Raise a FileNotFoundError if the SDF file is not found so that the local database is not created.
See the main.goslin_fct.parse_sdf()
for more detail.
Instantiation of the API
- main.goslin_rest.create(log_level='info')
Creates an instance of the Goslin application.
- Configure the endpoints :
/
/about
/grammars
/validate
Retrieve the metadata about the version of the API.
Configure the logs : info, debug and error
Configure the Swagger documentation of the API.
- Parameters:
log_level (str, optional) – Level of log with which you want to launch the application. Only takes “info”, “debug” or “error” as value, no matter the letter case (“info by default).
See the Swagger documentation for more information on the endpoints.
See main.goslin_fct.get_version_metadata()
for more details about the metadata.
Setting the arguments
- main.goslin_rest.arguments(parser)
Define the arguments.
–log_level : The level of log with which you want to launch the application. (default : “info”). Only takes “info”, “debug” or “error” as value, no matter the letter case.
–port or -p : The port on which you want the application to listen. It must be an integer between 0 and 35565.
–version : The version of the microservice aligned with the version of the tool.
- Parameters:
parser (argparse.ArgumentParser object) – Parser of arguments
- main.goslin_rest.valid_port(port)
Custom type checker used during the configuration of the –port argument.
- Parameters:
port (int) – A port to validate.
- Raises:
argparse.ArgumentTypeError – When the port put in paramater is not between 0 and 65535
- main.goslin_rest.create_parser_args()
Create the arguments parser to read the given arguments during the launch of the application.
goslin_fct : Core functions of the API
Module with the necessary functions for Goslin API-REST.
- main.goslin_fct.all_parser(lipid_name)
Parse a lipid name with all available grammars in a predefined order.
Stop at the first grammar that successfully parses the lipid name. Grammars’ order: Shorthand, Goslin, FattyAcid, LipidMaps, SwissLipids, Hmdb
- Parameters:
lipid_name (str) – One lipid name
- Returns:
If successful (Tuple) –
lipid : A LipidAdduct object with all the informations generated
grammar : The name of the grammar used to parse the lipid name
If uncompleted (at least one grammar succeeded to begin the parsing of the lipid name) (Dictionnary) –
messages : A dictionary with for all grammars, the string that a grammar managed to reach before failing to parse the lipid name
If faialed (no grammar succeeded to begin te parsing of the lipid name) (Exception) –
LipidException : An Exception raised when the Lipid is not found
- main.goslin_fct.build_json_failure(name)
Build the JSON part of the response for one lipid after a failed parsing.
Add the informations generated by pygoslin for one lipid name when no grammars succeed to begin reading the lipid name.
- Parameters:
name (str) – Name of the lipid just tried to be parsed by pygoslin
- main.goslin_fct.build_json_success(res, name)
Build the JSON part of the response for one lipid after a successful parsing.
Add the informations generated by pygoslin for one lipid name when the parsing was successful.
- Parameters:
res (Tuple of length 2) – Result from the function all_parser
name (str) – Name of the lipid just tried to be parsed by pygoslin
- main.goslin_fct.build_json_uncompleted(res, name)
Build the JSON part of the response for one lipid after a uncompleted parsing.
Add the informations generated by pygoslin for one lipid name when at least on grammars succeed to begin reading the lipid name.
- Parameters:
res (dict) – Result from the function all_parser
name (str) – Name of the lipid just tried to be parsed by pygoslin
- main.goslin_fct.get_lipidmaps_class_name(num_line)
Retrieve the LipidMaps class name of a lipid from the lipid-list.csv file.
This file comes from with the pygoslin package. The class name can be retrieved thanks to a number of line obtain by pygoslin after the parsing of the lipid. This line number corresponds for the parsed lipid to its LipidsMaps class name present in the “lipid-list” CSV file.
- Parameters:
num_line (int) – Line number from the file corresponding to the lipid class considered. This number is obtained by the parsing of the lipid with pygoslin.
- Returns:
The LipidMaps class name corresponding to the lipid
- Return type:
str
- main.goslin_fct.get_lipidmaps_info(lipid_name)
Checks if the standardized name is contained in the LipidsMaps database.
If the strandardized name is present in the database then retrieve the informations wanted (LipidMaps ID, InCHI key and SwissLipids ID if present).
- Parameters:
lipid_name (str) – Standardized lipid name obtained after the parsing with pygoslin
- Returns:
dict – If the standradized name is in the database, return a dictionary with a dictionnary with the information retrieve from the database for each entry corresponding to this name in the LipidMaps Structure Database.
bool – False if the standardized name is not in the LipidMaps database
- main.goslin_fct.get_version_metadata()
Retrieve the information about the version of the microservice.
Update the “METADATA” variable store in the vars module with diverse information on the version of the Goslin microservice. - The Sha-1 and short Sha-1 of the last commit use as the version of the microservice. - The timestamps when the application was built.
- main.goslin_fct.parse_sdf(filesdf)
Parse SDF file to retrieve the LipidMaps ID, the InCHI key and the standardized name.
Update the variable “LIPIDMAPS_DATABASE” store in the vars module with a list of dictionnary where each dictionnary contained the wanted information obtained from the LipidMaps Structure Database for each entry of this database. Structure of the dictionnary :
“LIPIDMAPS_ID” : ID of the LipidMaps entry for a molecule
“INCHI_KEY” : InCHI key corresponding to this molecule
“STANDARDIZED_NAME” : Standardized name of this molecule
“SWISSLIPIDS_ID” : ID of the SwissLipids entry for the same molecule if present (None if not)
- Parameters:
filesdf (str) – URL to the SDF file containing the LipidMaps Structure Database.