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_example_single_file(self, example_file_pth, name): # Parse all example files dirpath = tempfile.mkdtemp() db_pth = os.path.join(dirpath, name + '.db') create_db(file_pth=db_pth) libdata = LibraryData(msp_pth=example_file_pth, db_pth=db_pth, db_type="sqlite", schema='massbank', source='test', mslevel=None, chunk=200) return libdata, db_pth
def test_create_db(self, ): dirpath = tempfile.mkdtemp() # Parse all example files db_pth = os.path.join(os.path.dirname(__file__), dirpath, 'test_sqlite_db_create.db') create_db(file_pth=db_pth) print(db_pth) conn = sqlite3.connect(db_pth) cursor = conn.cursor() # test tables exist self.assertTrue(check_table_exists_sqlite(cursor, 'library_spectra')) self.assertTrue( check_table_exists_sqlite(cursor, 'library_spectra_meta')) self.assertTrue( check_table_exists_sqlite(cursor, 'library_spectra_source')) self.assertTrue(check_table_exists_sqlite(cursor, 'metab_compound'))
import os from msp2db.parse import LibraryData from msp2db.db import create_db ts = time.time() st = datetime.datetime.fromtimestamp(ts).strftime('%Y_%m_%d_%H_%M_%S') db_pth = os.path.join( sys.argv[1], 'spectral_library_massbank_gnps_lipidblast_hmdb_{}.db'.format(st)) ############################################################# # Create database ############################################################# create_db(file_pth=db_pth) print("#############################################################") print('# GNPS') print("#############################################################") libdata = LibraryData(msp_pth='/media/sf_DATA/mona/MoNA-export-GNPS.msp', db_pth=db_pth, db_type='sqlite', schema='mona', source='gnps', mslevel=None, chunk=200) print("#############################################################") print('# HMDB') print("#############################################################")