Skip to content

Commit ea73a1b

Browse files
committed
Update lipid workflow test to use metabref database
1 parent 4e1a4ff commit ea73a1b

1 file changed

Lines changed: 17 additions & 49 deletions

File tree

tests/test_wf_lipidomics.py

Lines changed: 17 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -154,56 +154,24 @@ def test_lipidomics_workflow():
154154
# Plot a mass feature
155155
myLCMSobj.mass_features[0].plot(return_fig=False)
156156

157-
"""
158-
# This code should be left as an example for how to generate example json data
159-
import dataclasses
160-
161-
mzs = [i.mz for k, i in myLCMSobj.mass_features.items()]
157+
# Query the lipidomics database to prepare a small search library for the mass features
162158
metabref = MetabRefLCInterface()
163-
metabref.set_token("tmp_data/thermo_raw_NMDC/metabref.token")
164-
spectra_library, lipid_metadata = metabref.get_lipid_library(
165-
mz_list=mzs[1:10],
166-
polarity="negative",
167-
mz_tol_ppm=5,
168-
mz_tol_da_api=0.01,
169-
format="json",
170-
normalize=True
171-
)
172-
# Save the json spectra library and lipid metadata to a text file and then load it back in
173-
import json
174-
with open('tests/tests_data/lcms/metabref_spec_lib.json', "w") as final:
175-
json.dump(spectra_library, final)
176-
lipid_metadata_raw = {
177-
k: dataclasses.asdict(v) for k, v in lipid_metadata.items()
178-
}
179-
with open('tests/tests_data/lcms/metabref_lipid_metadata.json', "w") as final:
180-
json.dump(lipid_metadata_raw, final)
181-
"""
182-
metabref = MetabRefLCInterface()
183-
184-
# Load an example json spectral library and convert to flashentropy format
185-
with open("tests/tests_data/lcms/metabref_spec_lib.json") as f:
186-
spectra_library_json = json.load(f)
187-
spectra_library_fe = metabref._to_flashentropy(
188-
spectra_library_json,
189-
normalize=True,
190-
fe_kwargs={
191-
"normalize_intensity": True,
192-
"min_ms2_difference_in_da": 0.02, # for cleaning spectra
193-
"max_ms2_tolerance_in_da": 0.01, # for setting search space
194-
"max_indexed_mz": 3000,
195-
"precursor_ions_removal_da": None,
196-
"noise_threshold": 0,
197-
},
198-
)
199-
200-
# Load the associated lipid metadata and convert to correct class
201-
with open("tests/tests_data/lcms/metabref_lipid_metadata.json") as f:
202-
lipid_metadata_json = json.load(f)
203-
lipid_metadata = {
204-
k: metabref._dict_to_dataclass(v, LipidMetadata)
205-
for k, v in lipid_metadata_json.items()
206-
}
159+
mzs = [i.mz for k, i in myLCMSobj.mass_features.items()]
160+
spectra_library_fe, lipid_metadata = metabref.get_lipid_library(
161+
mz_list=mzs[1:10],
162+
polarity="negative",
163+
mz_tol_ppm=5,
164+
format="flashentropy",
165+
normalize=True,
166+
fe_kwargs={
167+
"normalize_intensity": True,
168+
"min_ms2_difference_in_da": 0.02, # for cleaning spectra
169+
"max_ms2_tolerance_in_da": 0.01, # for setting search space
170+
"max_indexed_mz": 3000,
171+
"precursor_ions_removal_da": None,
172+
"noise_threshold": 0,
173+
},
174+
)
207175

208176
# Perform a spectral search on the mass features
209177
hcd_ms2_scan_df = myLCMSobj.scan_df[

0 commit comments

Comments
 (0)