def __init__(self, sm_config_path): self.sm_config_path = sm_config_path self.sm_config = SMConfig.get_conf() self.db = DB(self.sm_config['db']) self.ds_id = '2000-01-01-00_00_00' self.base_search_res_path = join(proj_root(), 'tests/reports', 'spheroid_untreated_search_res.csv') self.ds_name = 'sci_test_spheroid_untreated' self.data_dir_path = join(self.sm_config['fs']['base_path'], self.ds_name) self.input_path = join(proj_root(), 'tests/data/untreated') self.ds_config_path = join(self.input_path, 'config.json') self.metrics = ['chaos', 'spatial', 'spectral']
def run_search(): cmd = ['python', join(proj_root(), 'scripts/run_molecule_search.py'), ds_name, input_dir_path, ds_config_path] check_call(cmd)
def run_search(): cmd = [ 'python', join(proj_root(), 'scripts/run_molecule_search.py'), ds_name, input_dir_path, '--ds-config', ds_config_path ] check_call(cmd)
def create_test_db(): db_config = dict(database='postgres', user='******', host='localhost') db = DB(db_config, autocommit=True) db.alter('DROP DATABASE IF EXISTS sm_test') db.alter('CREATE DATABASE sm_test') db.close() local('psql -h localhost -U sm sm_test < {}'.format(join(proj_root(), 'scripts/create_schema.sql')))
def create_ds(ds_id=None, upload_dt=None, input_path=None, meta=None, ds_config=None): ds_id = ds_id or '2000-01-01' upload_dt = upload_dt or datetime.now() input_path = input_path or join(proj_root(), 'tests/data/imzml_example_ds') meta = meta or {'Data_Type': 'Imaging MS'} mol_dbs = ['HMDB-v4'] adducts = ['+H'] return Dataset(ds_id, 'imzml_example', input_path, upload_dt, meta, ds_config, mol_dbs=mol_dbs, adducts=adducts)
def create_test_db(): db_config = dict(database='postgres', user='******', host='localhost') db = DB(db_config, autocommit=True) db.alter('DROP DATABASE IF EXISTS sm_test') db.alter('CREATE DATABASE sm_test') db.close() local('psql -h localhost -U sm sm_test < {}'.format( join(proj_root(), 'scripts/create_schema.sql')))
def create_ds(ds_id=None, upload_dt=None, input_path=None, meta=None, ds_config=None): ds_id = ds_id or '2000-01-01' upload_dt = upload_dt or datetime.now() input_path = input_path or join(proj_root(), 'tests/data/imzml_example_ds') meta = meta or {'Data_Type': 'Imaging MS'} return Dataset(ds_id, 'imzml_example', input_path, upload_dt, meta, ds_config)
def test_lcms_geometry_factory(): lcms_file_path = join(proj_root(), 'tests/data/lcms_acq_geometry_example/apple_surface_swab.mzML') factory = LcmsGeometryFactory(lcms_file_path.encode()) geometry = factory.create() assert geometry[ACQ_GEOMETRY_KEYS.LENGTH_UNIT] == 's' assert not geometry[ACQ_GEOMETRY_KEYS.AcqGridSection.section_name][ACQ_GEOMETRY_KEYS.AcqGridSection.REGULAR_GRID] assert len(geometry[ACQ_GEOMETRY_KEYS.AcqGridSection.section_name][ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_CORRD_LIST]) == 285 assert geometry[ACQ_GEOMETRY_KEYS.PixelSizeSection.section_name] == { ACQ_GEOMETRY_KEYS.PixelSizeSection.REGULAR_SIZE: True, ACQ_GEOMETRY_KEYS.PixelSizeSection.PIXEL_SIZE_X : 0, ACQ_GEOMETRY_KEYS.PixelSizeSection.PIXEL_SIZE_Y : 0 }
def test_lcms_geometry_factory(): lcms_file_path = join( proj_root(), 'tests/data/lcms_acq_geometry_example/apple_surface_swab.mzML') factory = LcmsGeometryFactory(lcms_file_path.encode()) geometry = factory.create() assert geometry[ACQ_GEOMETRY_KEYS.LENGTH_UNIT] == 's' assert not geometry[ACQ_GEOMETRY_KEYS.AcqGridSection.section_name][ ACQ_GEOMETRY_KEYS.AcqGridSection.REGULAR_GRID] assert len(geometry[ACQ_GEOMETRY_KEYS.AcqGridSection.section_name][ ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_CORRD_LIST]) == 285 assert geometry[ACQ_GEOMETRY_KEYS.PixelSizeSection.section_name] == { ACQ_GEOMETRY_KEYS.PixelSizeSection.REGULAR_SIZE: True, ACQ_GEOMETRY_KEYS.PixelSizeSection.PIXEL_SIZE_X: 0, ACQ_GEOMETRY_KEYS.PixelSizeSection.PIXEL_SIZE_Y: 0 }
def _configure_spark(self): logger.info('Configuring Spark') sconf = SparkConf() for prop, value in self.sm_config['spark'].iteritems(): if prop.startswith('spark.'): sconf.set(prop, value) if 'aws' in self.sm_config: sconf.set("spark.hadoop.fs.s3a.access.key", self.sm_config['aws']['aws_access_key_id']) sconf.set("spark.hadoop.fs.s3a.secret.key", self.sm_config['aws']['aws_secret_access_key']) sconf.set("spark.hadoop.fs.s3a.impl", "org.apache.hadoop.fs.s3a.S3AFileSystem") # sconf.set("spark.python.profile", "true") self.sc = SparkContext(master=self.sm_config['spark']['master'], conf=sconf, appName='SM engine') if not self.sm_config['spark']['master'].startswith('local'): self.sc.addPyFile(join(local_path(proj_root()), 'sm.zip'))
def test_db(sm_config, request): db_config = dict(**sm_config['db']) db_config['database'] = 'postgres' db = DB(db_config, autocommit=True) db.alter('DROP DATABASE IF EXISTS sm_test') db.alter('CREATE DATABASE sm_test') db.close() local('psql -h {} -U {} sm_test < {}'.format( sm_config['db']['host'], sm_config['db']['user'], Path(proj_root()) / 'scripts/create_schema.sql')) def fin(): db = DB(db_config, autocommit=True) try: db.alter('DROP DATABASE IF EXISTS sm_test') except Exception as e: logging.getLogger('engine').warning( 'Drop sm_test database failed: %s', e) finally: db.close() request.addfinalizer(fin)
"FROM iso_image_metrics m " "JOIN formula_db sf_db ON sf_db.id = m.db_id " "JOIN agg_formula f ON f.id = m.sf_id AND sf_db.id = f.db_id " "JOIN job j ON j.id = m.job_id " "JOIN dataset ds ON ds.id = j.ds_id " "JOIN theor_peaks tp ON tp.db_id = sf_db.id AND tp.sf_id = m.sf_id AND tp.adduct = m.adduct " "WHERE sf_db.name = %s AND ds.name = %s " "AND ROUND(sigma::numeric, 6) = %s AND charge = %s AND pts_per_mz = %s") if __name__ == "__main__": parser = argparse.ArgumentParser(description='Exporting search results into a csv file') parser.add_argument('ds_name', type=str, help='Dataset name') parser.add_argument('csv_path', type=str, help='Path for the csv file') parser.add_argument('--config', dest='sm_config_path', type=str, help='SM config path') parser.set_defaults(sm_config_path=path.join(proj_root(), 'conf/config.json')) args = parser.parse_args() SMConfig.set_path(args.sm_config_path) db = DB(SMConfig.get_conf()['db']) ds_config = db.select_one(DS_CONFIG_SEL, args.ds_name)[0] isotope_gen_config = ds_config['isotope_generation'] charge = '{}{}'.format(isotope_gen_config['charge']['polarity'], isotope_gen_config['charge']['n_charges']) export_rs = db.select(EXPORT_SEL, ds_config['database']['name'], args.ds_name, isotope_gen_config['isocalc_sigma'], charge, isotope_gen_config['isocalc_pts_per_mz']) header = ','.join(['formula_db', 'ds_name', 'sf', 'adduct', 'chaos', 'img_corr', 'pat_match', 'isocalc_sigma', 'isocalc_charge', 'isocalc_pts_per_mz', 'first_peak_mz']) + '\n' with open(args.csv_path, 'w') as f: f.write(header)
local('rm -rf {}'.format(self.data_dir_path)) if __name__ == '__main__': parser = argparse.ArgumentParser(description='Scientific tests runner') parser.add_argument('-r', '--run', action='store_true', help='compare current search results with previous') parser.add_argument('-s', '--save', action='store_true', help='store current search results') parser.add_argument('--config', dest='sm_config_path', default=join(proj_root(), 'conf/config.json'), help='path to sm config file') parser.add_argument('--mock-img-store', action='store_true', help='whether to mock the Image Store Service') args = parser.parse_args() SMConfig.set_path(args.sm_config_path) init_loggers(SMConfig.get_conf()['logs']) sci_tester = SciTester(args.sm_config_path) if args.run: run_search_successful = False search_results_different = False try:
) parser = argparse.ArgumentParser(description=help_msg) parser.add_argument('db_name', type=str, help='Database name') parser.add_argument('csv_file', type=str, help='Path to a database csv file') parser.add_argument('--sep', dest='sep', type=str, help='CSV file fields separator') parser.add_argument('--yes', dest='confirmed', type=bool, help='Don\'t ask for a confirmation') parser.add_argument('--config', type=str, help='SM config path') parser.set_defaults(sep='\t', confirmed=False) args = parser.parse_args() if args.config: sm_config = json.load(open(args.config)) else: sm_config = json.load(open(path.join(proj_root(), 'conf/config.json'))) db = DB(sm_config['db'], autocommit=True) del_prev_formula_db(db, args.db_name, args.confirmed) insert_new_formula_db(db, args.db_name) insert_new_formulas(db, args.db_name, args.csv_file, args.sep.decode('string-escape')) insert_agg_formulas(db, args.db_name)
from sm.engine.util import proj_root from sm.engine.sm_daemon import SMDaemon from sm.engine.search_job import SearchJob from sm.engine.queue import SM_ANNOTATE, SM_DS_STATUS, QueueConsumer from sm.engine import DB, ESExporter, QueuePublisher, Dataset, SMapiDatasetManager, DatasetStatus from sm.engine.tests.util import test_db, sm_config, ds_config logging.basicConfig(level=logging.DEBUG) ACTION_QDESC = SM_ANNOTATE ACTION_QDESC['name'] = 'sm_test' STATUS_QDESC = SM_DS_STATUS STATUS_QDESC['name'] = 'sm_status_test' SM_CONFIG_PATH = join(proj_root(), 'conf/test_config.json') @fixture def fill_db(test_db, sm_config, ds_config): upload_dt = '2000-01-01 00:00:00' ds_id = '2000-01-01' meta = {'Data_Type': 'Imaging MS'} db = DB(sm_config['db']) db.insert('INSERT INTO dataset values(%s, %s, %s, %s, %s, %s, %s)', rows=[(ds_id, 'ds_name', 'input_path', upload_dt, json.dumps(meta), json.dumps(ds_config), DatasetStatus.FINISHED)]) def create_api_ds_man(db=None,
from unittest.mock import MagicMock import pytest from elasticsearch import Elasticsearch from elasticsearch_dsl import Search from fabric.api import local from pysparkling import Context import pandas as pd from sm.engine.db import DB from sm.engine.mol_db import MolecularDB from sm.engine.util import proj_root, SMConfig, init_loggers from sm.engine.es_export import ESIndexManager TEST_CONFIG_PATH = 'conf/test_config.json' SMConfig.set_path(Path(proj_root()) / TEST_CONFIG_PATH) init_loggers(SMConfig.get_conf()['logs']) @pytest.fixture(scope='session') def sm_config(): return SMConfig.get_conf(update=True) class SparkContext(Context): def parallelize(self, x, numSlices=None): return super().parallelize(x, numPartitions=numSlices) @pytest.fixture(scope='module')
from os.path import join from pprint import pprint from subprocess import check_call import numpy as np from fabric.api import local from fabric.context_managers import warn_only from sm.engine.db import DB from sm.engine.util import proj_root, SMConfig # def sm_config(): # with open(join(proj_root(), 'conf/config.json')) as f: # return json.load(f) SMConfig.set_path(join(proj_root(), 'conf/config.json')) sm_config = SMConfig.get_conf() ds_name = 'sci_test_spheroid_12h' data_dir_path = join(SMConfig.get_conf()['fs']['base_path'], ds_name) input_dir_path = join(proj_root(), 'test/data/sci_test_search_job_spheroid_dataset') ds_config_path = join(input_dir_path, 'config.json') SEARCH_RES_SELECT = ( "select sf, adduct, stats " "from iso_image_metrics s " "join formula_db sf_db on sf_db.id = s.db_id " "join agg_formula f on f.id = s.sf_id AND sf_db.id = f.db_id " "join job j on j.id = s.job_id " "join dataset ds on ds.id = j.ds_id "
def test_ims_geometry_factory(): imzml_parser_mock = MagicMock(ImzMLParser) imzml_parser_mock.imzmldict = TestGeometryVariants.regular ims_file_path = join( proj_root(), 'tests/data/imzml_example_ds/Example_Continuous.imzML') factory_reg_geom = ImsGeometryFactory(ims_file_path) factory_reg_geom.parser = imzml_parser_mock assert factory_reg_geom.create() == { ACQ_GEOMETRY_KEYS.LENGTH_UNIT: 'nm', ACQ_GEOMETRY_KEYS.AcqGridSection.section_name: { ACQ_GEOMETRY_KEYS.AcqGridSection.REGULAR_GRID: True, ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_COUNT_X: TestGeometryVariants.regular['max count of pixels x'], ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_COUNT_Y: TestGeometryVariants.regular['max count of pixels y'], ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_SPACING_X: TestGeometryVariants.regular['pixel size x'], ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_SPACING_Y: TestGeometryVariants.regular['pixel size y'] }, ACQ_GEOMETRY_KEYS.PixelSizeSection.section_name: { ACQ_GEOMETRY_KEYS.PixelSizeSection.REGULAR_SIZE: True, ACQ_GEOMETRY_KEYS.PixelSizeSection.PIXEL_SIZE_X: TestGeometryVariants.regular['pixel size x'], ACQ_GEOMETRY_KEYS.PixelSizeSection.PIXEL_SIZE_Y: TestGeometryVariants.regular['pixel size y'] } } imzml_parser_mock.imzmldict = TestGeometryVariants.pix_count_only factory_pix_count_geom = ImsGeometryFactory(ims_file_path) factory_pix_count_geom.parser = imzml_parser_mock assert factory_pix_count_geom.create() == { ACQ_GEOMETRY_KEYS.LENGTH_UNIT: 'nm', ACQ_GEOMETRY_KEYS.AcqGridSection.section_name: { ACQ_GEOMETRY_KEYS.AcqGridSection.REGULAR_GRID: True, ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_COUNT_X: TestGeometryVariants.pix_count_only['max count of pixels x'], ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_COUNT_Y: TestGeometryVariants.pix_count_only['max count of pixels y'], ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_SPACING_X: 0, ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_SPACING_Y: 0 }, ACQ_GEOMETRY_KEYS.PixelSizeSection.section_name: { ACQ_GEOMETRY_KEYS.PixelSizeSection.REGULAR_SIZE: True, ACQ_GEOMETRY_KEYS.PixelSizeSection.PIXEL_SIZE_X: 0, ACQ_GEOMETRY_KEYS.PixelSizeSection.PIXEL_SIZE_Y: 0 } } imzml_parser_mock.imzmldict = TestGeometryVariants.empty factory_empty_geom = ImsGeometryFactory(ims_file_path) factory_empty_geom.parser = imzml_parser_mock assert factory_empty_geom.create() == { ACQ_GEOMETRY_KEYS.LENGTH_UNIT: 'nm', ACQ_GEOMETRY_KEYS.AcqGridSection.section_name: { ACQ_GEOMETRY_KEYS.AcqGridSection.REGULAR_GRID: True, ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_COUNT_X: 0, ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_COUNT_Y: 0, ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_SPACING_X: 0, ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_SPACING_Y: 0 }, ACQ_GEOMETRY_KEYS.PixelSizeSection.section_name: { ACQ_GEOMETRY_KEYS.PixelSizeSection.REGULAR_SIZE: True, ACQ_GEOMETRY_KEYS.PixelSizeSection.PIXEL_SIZE_X: 0, ACQ_GEOMETRY_KEYS.PixelSizeSection.PIXEL_SIZE_Y: 0 } }
# 'WHERE d.name = %s ' # 'ORDER BY t.target_add, t.sf_id') EXPORT_SEL = ('SELECT adds.sf_id, adds.target_add, f.sf, adds.decoy_add ' 'FROM target_decoy_add adds ' 'JOIN agg_formula f ON f.id = adds.sf_id ' 'JOIN job j ON j.id = adds.job_id ' 'JOIN dataset ds ON ds.id = j.ds_id AND adds.db_id = f.db_id' 'WHERE ds.name = %s ' 'ORDER BY adds.target_add, adds.sf_id') if __name__ == '__main__': parser = argparse.ArgumentParser(description='Exporting target/decoy sets into a csv file') parser.add_argument('ds_name', type=str, help='Dataset name') parser.add_argument('csv_path', type=str, help='Path for the csv file') parser.add_argument('--config', dest='sm_config_path', type=str, help='SM config path') parser.set_defaults(sm_config_path=path.join(proj_root(), 'conf/config.json')) args = parser.parse_args() SMConfig.set_path(args.sm_config_path) db = DB(SMConfig.get_conf()['db']) export_rs = db.select(EXPORT_SEL, args.ds_name) header = ','.join(['sf_id', 'target_add', 'sf', 'decoy_add']) + '\n' with open(args.csv_path, 'w') as f: f.write(header) f.writelines([','.join(map(str, row)) + '\n' for row in export_rs]) logger.info('Exported all search results for "%s" dataset into "%s" file', args.ds_name, args.csv_path)
def __init__(self, db_config): self.db = DB(db_config) self.base_search_res_path = join(proj_root(), 'tests/reports', 'spheroid_12h_search_res.csv') self.metrics = ['chaos', 'spatial', 'spectral']
from sm.engine.sm_daemon import SMDaemon from sm.engine.search_job import SearchJob from sm.engine.queue import SM_ANNOTATE, SM_DS_STATUS, QueueConsumer from sm.engine import DB, ESExporter, QueuePublisher, Dataset, SMapiDatasetManager, DatasetStatus from sm.engine.tests.util import test_db, sm_config, ds_config logging.basicConfig(level=logging.DEBUG) ACTION_QDESC = SM_ANNOTATE ACTION_QDESC['name'] = 'sm_test' STATUS_QDESC = SM_DS_STATUS STATUS_QDESC['name'] = 'sm_status_test' SM_CONFIG_PATH = join(proj_root(), 'conf/test_config.json') @fixture def fill_db(test_db, sm_config, ds_config): upload_dt = '2000-01-01 00:00:00' ds_id = '2000-01-01' meta = {'Data_Type': 'Imaging MS'} db = DB(sm_config['db']) db.insert('INSERT INTO dataset (id, name, input_path, upload_dt, metadata, config, ' 'status, is_public, mol_dbs, adducts) values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)', rows=[(ds_id, 'ds_name', 'input_path', upload_dt, json.dumps(meta), json.dumps(ds_config), DatasetStatus.FINISHED, True, ['HMDB-v4'], ['+H'])])
def zip_engine(): local('cd {}; zip -rq sm.zip engine'.format(proj_root()))
ds = create_ds_from_files(self.ds_id, self.ds_name, self.input_path) from sm.engine import SearchJob ds_man.add(ds, search_job_factory=SearchJob, del_first=True) def clear_data_dirs(self): with warn_only(): local('rm -rf {}'.format(self.data_dir_path)) if __name__ == '__main__': parser = argparse.ArgumentParser(description='Scientific tests runner') parser.add_argument('-r', '--run', action='store_true', help='compare current search results with previous') parser.add_argument('-s', '--save', action='store_true', help='store current search results') parser.add_argument('--config', dest='sm_config_path', default=join(proj_root(), 'conf/config.json'), help='path to sm config file') parser.add_argument('--mock-img-store', action='store_true', help='whether to mock the Image Store Service') args = parser.parse_args() SMConfig.set_path(args.sm_config_path) init_loggers(SMConfig.get_conf()['logs']) sci_tester = SciTester(args.sm_config_path) if args.run: run_search_successful = False search_results_different = False try: sci_tester.run_search(args.mock_img_store) run_search_successful = True
from pprint import pprint from subprocess import check_call import numpy as np from fabric.api import local from fabric.context_managers import warn_only from sm.engine.db import DB from sm.engine.util import proj_root, SMConfig # def sm_config(): # with open(join(proj_root(), 'conf/config.json')) as f: # return json.load(f) SMConfig.set_path(join(proj_root(), 'conf/config.json')) sm_config = SMConfig.get_conf() ds_name = 'sci_test_spheroid_12h' data_dir_path = join(SMConfig.get_conf()['fs']['base_path'], ds_name) input_dir_path = join(proj_root(), 'test/data/sci_test_search_job_spheroid_dataset') ds_config_path = join(input_dir_path, 'config.json') SEARCH_RES_SELECT = ("select sf, adduct, stats " "from iso_image_metrics s " "join formula_db sf_db on sf_db.id = s.db_id " "join agg_formula f on f.id = s.sf_id AND sf_db.id = f.db_id " "join job j on j.id = s.job_id " "join dataset ds on ds.id = j.ds_id " "where ds.name = %s and sf_db.name = %s " "ORDER BY sf, adduct ")
def test_ims_geometry_factory(): imzml_parser_mock = MagicMock(ImzMLParser) imzml_parser_mock.imzmldict = TestGeometryVariants.regular ims_file_path = join(proj_root(), 'tests/data/imzml_example_ds/Example_Continuous.imzML') factory_reg_geom = ImsGeometryFactory(ims_file_path) factory_reg_geom.parser = imzml_parser_mock assert factory_reg_geom.create() == { ACQ_GEOMETRY_KEYS.LENGTH_UNIT: 'nm', ACQ_GEOMETRY_KEYS.AcqGridSection.section_name: { ACQ_GEOMETRY_KEYS.AcqGridSection.REGULAR_GRID: True, ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_COUNT_X : TestGeometryVariants.regular['max count of pixels x'], ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_COUNT_Y : TestGeometryVariants.regular['max count of pixels y'], ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_SPACING_X : TestGeometryVariants.regular['pixel size x'], ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_SPACING_Y : TestGeometryVariants.regular['pixel size y'] }, ACQ_GEOMETRY_KEYS.PixelSizeSection.section_name: { ACQ_GEOMETRY_KEYS.PixelSizeSection.REGULAR_SIZE: True, ACQ_GEOMETRY_KEYS.PixelSizeSection.PIXEL_SIZE_X : TestGeometryVariants.regular['pixel size x'], ACQ_GEOMETRY_KEYS.PixelSizeSection.PIXEL_SIZE_Y : TestGeometryVariants.regular['pixel size y'] } } imzml_parser_mock.imzmldict = TestGeometryVariants.pix_count_only factory_pix_count_geom = ImsGeometryFactory(ims_file_path) factory_pix_count_geom.parser = imzml_parser_mock assert factory_pix_count_geom.create() == { ACQ_GEOMETRY_KEYS.LENGTH_UNIT: 'nm', ACQ_GEOMETRY_KEYS.AcqGridSection.section_name: { ACQ_GEOMETRY_KEYS.AcqGridSection.REGULAR_GRID: True, ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_COUNT_X : TestGeometryVariants.pix_count_only['max count of pixels x'], ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_COUNT_Y : TestGeometryVariants.pix_count_only['max count of pixels y'], ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_SPACING_X : 0, ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_SPACING_Y : 0 }, ACQ_GEOMETRY_KEYS.PixelSizeSection.section_name: { ACQ_GEOMETRY_KEYS.PixelSizeSection.REGULAR_SIZE: True, ACQ_GEOMETRY_KEYS.PixelSizeSection.PIXEL_SIZE_X : 0, ACQ_GEOMETRY_KEYS.PixelSizeSection.PIXEL_SIZE_Y : 0 } } imzml_parser_mock.imzmldict = TestGeometryVariants.empty factory_empty_geom = ImsGeometryFactory(ims_file_path) factory_empty_geom.parser = imzml_parser_mock assert factory_empty_geom.create() == { ACQ_GEOMETRY_KEYS.LENGTH_UNIT: 'nm', ACQ_GEOMETRY_KEYS.AcqGridSection.section_name: { ACQ_GEOMETRY_KEYS.AcqGridSection.REGULAR_GRID: True, ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_COUNT_X : 0, ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_COUNT_Y : 0, ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_SPACING_X : 0, ACQ_GEOMETRY_KEYS.AcqGridSection.PIXEL_SPACING_Y : 0 }, ACQ_GEOMETRY_KEYS.PixelSizeSection.section_name: { ACQ_GEOMETRY_KEYS.PixelSizeSection.REGULAR_SIZE: True, ACQ_GEOMETRY_KEYS.PixelSizeSection.PIXEL_SIZE_X : 0, ACQ_GEOMETRY_KEYS.PixelSizeSection.PIXEL_SIZE_Y : 0 } }
"JOIN dataset ds ON ds.id = j.ds_id " "JOIN theor_peaks tp ON tp.db_id = sf_db.id AND tp.sf_id = m.sf_id AND tp.adduct = m.adduct " "WHERE sf_db.name = %s AND ds.name = %s " "AND ROUND(sigma::numeric, 6) = %s AND charge = %s AND pts_per_mz = %s") if __name__ == "__main__": parser = argparse.ArgumentParser( description='Exporting search results into a csv file') parser.add_argument('ds_name', type=str, help='Dataset name') parser.add_argument('csv_path', type=str, help='Path for the csv file') parser.add_argument('--config', dest='sm_config_path', type=str, help='SM config path') parser.set_defaults( sm_config_path=path.join(proj_root(), 'conf/config.json')) args = parser.parse_args() SMConfig.set_path(args.sm_config_path) db = DB(SMConfig.get_conf()['db']) ds_config = db.select_one(DS_CONFIG_SEL, args.ds_name)[0] isotope_gen_config = ds_config['isotope_generation'] charge = '{}{}'.format(isotope_gen_config['charge']['polarity'], isotope_gen_config['charge']['n_charges']) export_rs = db.select(EXPORT_SEL, ds_config['database']['name'], args.ds_name, isotope_gen_config['isocalc_sigma'], charge, isotope_gen_config['isocalc_pts_per_mz']) header = '\t'.join(['formula_db', 'db_ids', 'sf_name', 'sf', 'adduct']) +'\t' + '\t'.join(metrics) + '\t' + \ '\t'.join(['fdr', 'isocalc_sigma', 'isocalc_charge', 'isocalc_pts_per_mz', 'first_peak_mz']) + '\n'