Skip to content

Commit efe54b8

Browse files
committed
Add GC-MS workflow test placeholder
1 parent b5b7209 commit efe54b8

1 file changed

Lines changed: 55 additions & 95 deletions

File tree

tests/test_gcms.py

Lines changed: 55 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,92 @@
1-
2-
__author__ = "Yuri E. Corilo"
3-
__date__ = "Jul 02, 2019"
41
import warnings
2+
53
warnings.filterwarnings("ignore")
64

5+
import os
76
import sys
8-
sys.path.append(".")
7+
from multiprocessing import Pool
98

10-
import pytest
11-
from pathlib import Path
12-
13-
from corems.molecular_id.input.nistMSI import ReadNistMSI
9+
from corems.mass_spectra.calc.GC_RI_Calibration import get_rt_ri_pairs
1410
from corems.mass_spectra.input.andiNetCDF import ReadAndiNetCDF
1511
from corems.molecular_id.search.compoundSearch import LowResMassSpectralMatch
16-
from corems.mass_spectra.calc.GC_RI_Calibration import get_rt_ri_pairs
12+
from corems.molecular_id.search.database_interfaces import MetabRefGCInterface
13+
1714

18-
def start_sql_from_file():
19-
20-
ref_lib_path = Path.cwd() / "tests/tests_data/gcms/" / "PNNLMetV20191015.MSL"
21-
sql_obj = ReadNistMSI(ref_lib_path).get_sqlLite_obj()
22-
return sql_obj
15+
def start_gcms_metabref_sql(normalize=False, url="sqlite://"):
16+
# Initialize MetabRef interface
17+
metabref = MetabRefGCInterface()
2318

24-
def test_sql_database():
25-
26-
file_location = Path.cwd() / "tests/tests_data/gcms/" / "FAMES_REF.MSL"
19+
# Pull contents into SQLite
20+
return metabref.get_library(format="sql")
2721

28-
sqlLite_obj = ReadNistMSI(file_location).get_sqlLite_obj()
2922

30-
min_max_rt = (18.037, 19.037)
23+
def start_fames_metabref_sql(normalize=False, url="sqlite://"):
24+
# Initialize MetabRef interface
25+
metabref = MetabRefGCInterface()
3126

32-
min_max_ri = (1637.30, 1737.30)
27+
# Pull contents into SQLite
28+
return metabref.get_fames(format="sql")
3329

34-
sqlLite_obj.query_min_max_ri((1637.30, 1638.30))
35-
sqlLite_obj.query_min_max_rt((17.111, 18.111))
36-
sqlLite_obj.query_min_max_ri_and_rt((1637.30, 1638.30),(17.111, 18.111))
3730

38-
def get_gcms(file_path):
39-
40-
reader_gcms = ReadAndiNetCDF(file_path)
41-
31+
def get_gcms(filepath):
32+
# Initialize reader
33+
reader_gcms = ReadAndiNetCDF(filepath)
34+
35+
# Run reader
4236
reader_gcms.run()
43-
37+
38+
# Get GCMS object
4439
gcms = reader_gcms.get_gcms_obj()
4540

46-
#gcms.process_chromatogram()
41+
# # Process chromatogram
42+
# gcms.process_chromatogram()
4743

4844
return gcms
4945

50-
def get_reference_dict():
5146

52-
file_path = Path.cwd() / "tests/tests_data/gcms/" / "GCMS_FAMES_01_GCMS-01_20191023.cdf"
53-
54-
gcms = get_gcms(file_path)
47+
def run(args):
48+
# Unpack arguments
49+
filepath, ref_dict, cal_filepath = args
5550

56-
sql_obj = start_sql_from_file()
51+
# Parse supplied file
52+
gcms = get_gcms(filepath)
5753

58-
if not file_path: return None
59-
60-
else:
61-
62-
gcms_ref_obj = get_gcms(file_path)
54+
# Process chromatogram
55+
gcms.process_chromatogram()
6356

64-
rt_ri_pairs = get_rt_ri_pairs(gcms_ref_obj, sql_obj)
57+
# Calibrate retention index
58+
gcms.calibrate_ri(ref_dict, cal_filepath)
6559

66-
return rt_ri_pairs, file_path
60+
# Initialize GCMS refeerence database from MetabRef
61+
sql_obj = start_gcms_metabref_sql()
6762

68-
def run(args):
69-
70-
file_path, ref_dict, cal_file_path = args
71-
72-
gcms = get_gcms(file_path)
73-
74-
gcms.calibrate_ri(ref_dict, cal_file_path)
75-
76-
gcms.peaks_rt_tic()
77-
78-
gcms.peaks_rt_tic(json_string=True)
79-
80-
sql_obj = start_sql_from_file()
63+
# Initialize spectral match
8164
lowResSearch = LowResMassSpectralMatch(gcms, sql_obj=sql_obj)
82-
# !!!!!! READ !!!!! use the previous two lines if db/pnnl_lowres_gcms_compounds.sqlite does not exist
83-
# and comment the next line
84-
#lowResSearch = LowResMassSpectralMatch(gcms)
65+
66+
# Run spectral match
8567
lowResSearch.run()
8668

8769
return gcms
8870

89-
def calibrate_and_search(out_put_file_name):
90-
91-
import csv
92-
93-
ref_dict, cal_file_path = get_reference_dict()
94-
95-
if ref_dict:
96-
97-
file_path = Path.cwd() / "tests/tests_data/gcms/" / "GCMS_FAMES_01_GCMS-01_20191023.cdf"
98-
gcms = run((file_path, ref_dict, cal_file_path))
99-
100-
gcms.to_csv(out_put_file_name)
101-
gcms.to_excel(out_put_file_name)
102-
gcms.to_pandas(out_put_file_name)
103-
104-
df = gcms.to_dataframe()
105-
json_data = gcms.to_json()
106-
107-
#print(json_data)
108-
109-
gcms.plot_processed_chromatogram()
110-
111-
gcms.plot_gc_peaks()
112-
113-
gcms.plot_chromatogram()
114-
115-
gcms.plot_smoothed_chromatogram()
11671

117-
gcms.plot_baseline_subtraction()
72+
def test_gcms_workflow():
73+
# # Define paths
74+
# filepath = None
75+
# calibration_filepath = None
11876

119-
gcms.plot_detected_baseline()
77+
# # Set token
78+
# TOKEN_PATH = "metabref.token"
79+
# MetabRefGCInterface().set_token(TOKEN_PATH)
12080

121-
gcms.chromatogram_settings.use_deconvolution = False
122-
gcms.process_chromatogram()
123-
81+
# # Parse supplied calibration data
82+
# gcms_ref_obj = get_gcms(calibration_filepath)
12483

125-
def test_run_gcms_pipeline():
84+
# # Build calibration SQLite database from MetabRef
85+
# fames_sql_obj = start_fames_metabref_sql()
12686

127-
out_put_file_name = 'test_gcms'
128-
calibrate_and_search(out_put_file_name)
87+
# # Determine calibration pairs
88+
# rt_ri_pairs = get_rt_ri_pairs(gcms_ref_obj, sql_obj=fames_sql_obj)
12989

130-
if __name__ == "__main__":
131-
#test_sql_database()
132-
test_run_gcms_pipeline()
90+
# # Execute
91+
# run((filepath, rt_ri_pairs, calibration_filepath))
92+
pass

0 commit comments

Comments
 (0)