Annotator
- class MSMetaEnhancer.libs.Annotator.Annotator
Bases:
objectAnnotator is responsible for annotation process of single spectra.
- async annotate(metadata, jobs, repeat=False)
Runs all jobs to add annotations to given dictionary containing metadata
The method goes through specified jobs of form (Source, Target, Converter) and tries to obtain ‘Target’ attribute based on ‘Source’ attribute using ‘Converter’ converter.
- Parameters:
metadata – given metadata
jobs – specified list of jobs to be executed
repeat – if some metadata was added, all jobs are executed again
- Returns:
annotated dictionary
- async execute_job_with_cache(job, metadata, cache, warning)
Execute given job in cached mode. Cache is converter specific and spectra specific.
Raises TargetAttributeNotRetrieved
- Parameters:
job – given job to be executed
metadata – data to be annotated by the job
cache – given cache for this spectra
warning – object storing warnings related to current metadata
- Returns:
updated metadata and cache
- set_converters(converters)
Curator
- class MSMetaEnhancer.libs.Curator.Curator
Bases:
objectCurator makes sure that all data is curated before the actual annotation can proceed. Currently, fixing CAS numbers to correct format is supported.
Additionally, it supports metadata validation to make sure the produced data are correct.
- curate_casno(metadata)
Curate metadata of particular spectra.
- Parameters:
metadata – given metadata
- Returns:
curated metadata
- curate_metadata(metadata_list)
Iterates over given metadata and curates individual entries.
- Parameters:
metadata_list – given metadata
- Returns:
curated metadata
- static filter_invalid_metadata(metadata, log, job)
Validates metadata and filters out invalid ones.
- Parameters:
metadata – metadata content
log – object storing logs related to current metadata
job – executed job
- Returns:
only valid metadata
- static fix_cas_number(cas_number)
Adds dashes to CAS number.
- Parameters:
cas_number – given CAS number
- Returns:
CAS number enriched by dashes (if needed)
Converter
- class MSMetaEnhancer.libs.Converter.Converter
Bases:
ABCGeneral class for conversions.
- abstract async convert(source, target, data)
Converts specified {source} attribute (provided in {data}) to {target} attribute.
- Parameters:
source – given attribute name
target – required attribute name
data – given attribute value
- Returns:
obtained value of target attribute
- property converter_name
- create_top_level_conversion_methods(conversions, asynch=True)
Method to create and set dynamic methods defined in conversions
- Parameters:
conversions – triples of form (from, to, method)
asynch – whether to create asynchronous methods
- get_conversion_functions() list
Method to compute all available conversion functions.
Assumes that the functions always have from {source}_to_{target}
- Returns:
a list of available conversion functions
- MSMetaEnhancer.libs.Converter.create_top_level_method(obj: Converter, source: str, target: str, method: str, asynch: bool = True)
Assign a new method to {obj} called {source}_to_{target} which calls {method}.
- Parameters:
obj – given object (typically a Converter)
source – attribute name used as source of data
target – attribute name obtained using this dynamic method
method – method which is called in the object with single argument
asynch – whether to create asynchronous methods