def test_cli(self, ): dirpath = tempfile.mkdtemp() #dirpath = os.path.join(os.path.dirname(__file__), 'original_results') infile = os.path.join(os.path.dirname(__file__), 'msp_files', "massbank", "AC000001.txt") call = "msp2db --msp_pth {} --source massbank -o {} -t sqlite " \ "--schema massbank".format(infile, os.path.join(dirpath, 'test_sqlite_cli.db')) print(call) os.system(call) db_pth = os.path.join(dirpath, 'test_sqlite_cli.db') # get original database info conn = sqlite3.connect( os.path.join(os.path.dirname(__file__), 'original_results', 'test_sqlite_cli.db')) cursor = conn.cursor() db_original = db_dict(cursor) conn2 = sqlite3.connect(db_pth) cursor2 = conn2.cursor() db_new = db_dict(cursor2) self.compare_db_d(db_new, db_original)
def test_cli_compound_lookup_false(self, ): dirpath = tempfile.mkdtemp() infile = os.path.join(os.path.dirname(__file__), 'msp_files', "massbank", "AC000001.txt") call = "msp2db --msp_pth {} --source massbank -o {} -t sqlite " \ "--ignore_compound_lookup " \ "--schema massbank".format(infile, os.path.join(dirpath, 'test_sqlite_cli_ignore_comp.db')) print(call) os.system(call) db_pth = os.path.join(dirpath, 'test_sqlite_cli_ignore_comp.db') conn2 = sqlite3.connect(db_pth) cursor2 = conn2.cursor() d_new = db_dict(cursor2) match = re.search('.*(UNKNOWN).*', str(d_new['metab_compound'][0][0])) if match: comp = match.group(1) else: comp = '' self.assertEqual(comp, 'UNKNOWN') self.assertEqual(d_new['metab_compound'][0][1], "unknown name") self.assertEqual(d_new['metab_compound'][0][2], None) self.assertEqual(d_new['metab_compound'][0][3], None) self.assertEqual(d_new['metab_compound'][0][4], None) self.assertEqual(d_new['metab_compound'][0][5], None) self.assertEqual(d_new['metab_compound'][0][6], None) self.assertEqual(d_new['metab_compound'][0][7], None) self.assertEqual(d_new['metab_compound'][0][8], None)
def test_example_multi_file(self): dirpath = tempfile.mkdtemp() #dirpath = os.path.join(os.path.dirname(__file__), 'original_results') db_pth = os.path.join(dirpath, 'test_msp_dir.db') create_db(file_pth=db_pth) dir_pth = os.path.join(os.path.dirname(__file__), "msp_files", "massbank") libdata = LibraryData(msp_pth=dir_pth, db_pth=db_pth, db_type='sqlite', schema='massbank', source='test', mslevel=None, chunk=200) db_new = libdata.get_db_dict() # get original database info conn = sqlite3.connect( os.path.join(os.path.dirname(__file__), 'original_results', 'test_msp_dir.db')) cursor = conn.cursor() db_original = db_dict(cursor) self.compare_db_d(db_new, db_original)
def test_mona_files(self): self.maxDiff = None dirpath = tempfile.mkdtemp() #dirpath = os.path.join(os.path.dirname(__file__), 'original_results') db_pth = os.path.join(dirpath, 'test_msp_mona.db') create_db(file_pth=db_pth) libdata = LibraryData(msp_pth=os.path.join( os.path.dirname(__file__), 'msp_files', 'mona', 'MoNA-export-Pathogen_Box-small.msp'), db_pth=db_pth, db_type='sqlite', schema='mona', source='pathogen', mslevel=None, chunk=2) libdata = LibraryData(msp_pth=os.path.join( os.path.dirname(__file__), 'msp_files', 'mona', 'MoNA-export-MetaboBASE-small.msp'), db_pth=db_pth, db_type='sqlite', schema='mona', source='massbank', mslevel=None, chunk=2) libdata = LibraryData(msp_pth=os.path.join( os.path.dirname(__file__), 'msp_files', 'mona', 'MoNA-export-MassBank-small.msp'), db_pth=db_pth, db_type='sqlite', schema='mona', source='metabobase', mslevel=None, chunk=2) db_new = libdata.get_db_dict() # get original database info conn = sqlite3.connect( os.path.join(os.path.dirname(__file__), 'original_results', 'test_msp_mona.db')) cursor = conn.cursor() db_original = db_dict(cursor) self.compare_db_d(db_new, db_original)
def test_cli_compound_lookup_false(self, ): dirpath = tempfile.mkdtemp() infile = os.path.join(os.path.dirname(__file__), 'msp_files', "massbank", "AC000001.txt") call = "msp2db --msp_pth {} --source massbank -o {} -t sqlite " \ "--ignore_compound_lookup " \ "--schema massbank".format(infile, os.path.join(dirpath, 'test_sqlite_cli_ignore_comp.db')) print(call) os.system(call) db_pth = os.path.join(dirpath, 'test_sqlite_cli_ignore_comp.db') conn2 = sqlite3.connect(db_pth) cursor2 = conn2.cursor() d_new = db_dict(cursor2) self.assertEqual(d_new['metab_compound'], [])