Skip to content

Commit 4e1a4ff

Browse files
committed
Remove using header from MetabRef queries
1 parent 8e84b33 commit 4e1a4ff

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

corems/molecular_id/search/database_interfaces.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,16 @@ def get_header(self):
9292

9393
return header
9494

95-
def get_query(self, url):
95+
def get_query(self, url, use_header=True):
9696
"""
9797
Request payload from URL according to `get` protocol.
9898
9999
Parameters
100100
----------
101101
url : str
102102
URL for request.
103+
use_header: bool
104+
Whether or not the query should include the header
103105
104106
Returns
105107
-------
@@ -109,7 +111,10 @@ def get_query(self, url):
109111
"""
110112

111113
# Query URL via `get`
112-
response = requests.get(url, headers=self.get_header())
114+
if use_header:
115+
response = requests.get(url, headers=self.get_header())
116+
else:
117+
response = requests.get(url)
113118

114119
# Check response
115120
response.raise_for_status()
@@ -352,6 +357,16 @@ def _dict_to_dataclass(self, metabref_lib, data_class):
352357
if key not in input_dict.keys():
353358
input_dict[key] = None
354359
return data_class(**input_dict)
360+
361+
def get_query(self, url, use_header=False):
362+
"""Overwrites the get_query method on the parent class to default to not use a header
363+
364+
Notes
365+
-----
366+
As of January 2025, the metabref database no longer requires a token and therefore no header is needed
367+
368+
"""
369+
return super().get_query(url, use_header)
355370

356371

357372
class MetabRefGCInterface(MetabRefInterface):

support_code/nmdc/lipidomics/lipidomics_workflow.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def run_lipid_sp_ms1(
408408
return mz_dict
409409

410410

411-
def prep_metadata(mz_dicts, out_dir, token_path):
411+
def prep_metadata(mz_dicts, out_dir):
412412
"""Prepare metadata for ms2 spectral search
413413
414414
Parameters
@@ -436,9 +436,6 @@ def prep_metadata(mz_dicts, out_dir, token_path):
436436
metadata["mzs"].update(d)
437437

438438
metabref = MetabRefLCInterface()
439-
if token_path is not None:
440-
metabref.set_token(token_path)
441-
metabref.set_token("tmp_data/thermo_raw_collection/metabref.token")
442439

443440
print("Preparing positive lipid library")
444441
if metadata["mzs"]["positive"] is not None:
@@ -530,7 +527,6 @@ def run_lipid_workflow(
530527
file_dir,
531528
out_dir,
532529
params_toml,
533-
token_path,
534530
scan_translator=None,
535531
verbose=True,
536532
ms1_molecular_search=True,
@@ -546,9 +542,6 @@ def run_lipid_workflow(
546542
Path to output directory
547543
params_toml : str or Path
548544
Path to toml file with parameters
549-
550-
token_path : str or Path
551-
Path to token file for MetabRefLCInterface
552545
verbose : bool
553546
Whether to print verbose output
554547
cores : int
@@ -593,7 +586,7 @@ def run_lipid_workflow(
593586
pool.close()
594587
pool.join()
595588
# Prepare ms2 spectral search space
596-
metadata = prep_metadata(mz_dicts, out_dir, token_path)
589+
metadata = prep_metadata(mz_dicts, out_dir)
597590

598591
# Run ms2 spectral search and export final results
599592
if cores == 1 or len(files_list) == 1:
@@ -613,10 +606,9 @@ def run_lipid_workflow(
613606
if __name__ == "__main__":
614607
# Set input variables to run
615608
cores = 1
616-
file_dir = Path("/Users/heal742/Library/CloudStorage/OneDrive-PNNL/Documents/_DMS_data/_NMDC/_blanchard_lipidomics")
617-
out_dir = Path("tmp_data/_test_241218")
609+
file_dir = Path("/Users/heal742/LOCAL/corems_dev/corems/tmp_data/thermo_raw_mini")
610+
out_dir = Path("tmp_data/_test_250115")
618611
params_toml = Path("/Users/heal742/LOCAL/05_NMDC/02_MetaMS/data_processing/configurations/emsl_lipidomics_corems_params.toml")
619-
metab_ref_token = Path("tmp_data/thermo_raw_collection/metabref.token")
620612
verbose = True
621613
scan_translator = Path("tmp_data/thermo_raw_collection/scan_translator.toml")
622614

@@ -631,7 +623,6 @@ def run_lipid_workflow(
631623
file_dir=file_dir,
632624
out_dir=out_dir,
633625
params_toml=params_toml,
634-
token_path=metab_ref_token,
635626
scan_translator=scan_translator,
636627
verbose=verbose,
637628
cores=cores,

0 commit comments

Comments
 (0)