diff --git a/MSMetaEnhancer/app.py b/MSMetaEnhancer/app.py index db2c226..9c9da0e 100644 --- a/MSMetaEnhancer/app.py +++ b/MSMetaEnhancer/app.py @@ -83,7 +83,8 @@ async def annotate_spectra( # start converters status checker and wait for first status try: - monitor.start() + if not monitor.is_alive(): + monitor.start() monitor.first_check.wait() # create all possible jobs if not given diff --git a/MSMetaEnhancer/libs/utils/Monitor.py b/MSMetaEnhancer/libs/utils/Monitor.py index d4c5ec0..7ec4fcd 100644 --- a/MSMetaEnhancer/libs/utils/Monitor.py +++ b/MSMetaEnhancer/libs/utils/Monitor.py @@ -55,7 +55,7 @@ def run(self): Such a converter is considered available. This is checked periodically to always have up-to-date information. """ - while not self.stop_request.isSet(): + while not self.stop_request.is_set(): for converter in self.converters.values(): url = self.get_base_url(converter) converter.is_available = self.check_service(url) diff --git a/README.md b/README.md index 0095e5f..bac190f 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,11 @@ Troják et al., (2022). MSMetaEnhancer: A Python package for mass spectra metada import asyncio from MSMetaEnhancer import Application +from MSMetaEnhancer.libs.converters.web import CTS, CIR, IDSM, PubChem, BridgeDb +from MSMetaEnhancer.libs.converters.compute import RDKit +from MSMetaEnhancer.libs.utils.ConverterBuilder import ConverterBuilder + +ConverterBuilder.register([CTS, CIR, IDSM, PubChem, BridgeDb, RDKit]) app = Application() diff --git a/tests/test_integration.py b/tests/test_integration.py new file mode 100644 index 0000000..d622652 --- /dev/null +++ b/tests/test_integration.py @@ -0,0 +1,41 @@ +import asyncio +import os + +from MSMetaEnhancer import Application +from MSMetaEnhancer.libs.converters.web import CTS, CIR, IDSM, PubChem, BridgeDb +from MSMetaEnhancer.libs.converters.compute import RDKit +from MSMetaEnhancer.libs.utils.ConverterBuilder import ConverterBuilder + +ConverterBuilder.register([CTS, CIR, IDSM, PubChem, BridgeDb, RDKit]) + + +def test_integration(tmp_path): + app = Application() + + # import your .msp file + app.load_data("tests/test_data/sample.msp", file_format="msp") + + # curate given metadata (e.g. fix CAS numbers) + app.curate_metadata() + + # specify requested services (these are supported) + services = ["CTS", "CIR", "IDSM", "PubChem", "BridgeDb", "RDKit"] + + # specify requested jobs + jobs = [ + ("compound_name", "inchi", "IDSM"), + ("inchi", "formula", "IDSM"), + ("inchi", "inchikey", "IDSM"), + ("inchi", "iupac_name", "IDSM"), + ("inchi", "canonical_smiles", "IDSM"), + ] + + # run asynchronous annotations of spectra data + asyncio.run(app.annotate_spectra(services, jobs)) + + # export .msp file + outpath = os.path.join(tmp_path, "sample_out.msp") + app.save_data(outpath, file_format="msp") + assert os.path.isfile(outpath) + + os.remove(outpath)