Skip to content

Commit d30f746

Browse files
authored
Update cli.py
1 parent bfe7a40 commit d30f746

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

onsite/phosphors/cli.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ def find_spectrum_by_mz(exp, target_mz, rt=None, ppm_tolerance=10):
444444

445445
# ----------------------- Multiprocessing worker utilities -----------------------
446446
_WORKER_EXP = None
447-
447+
_WORKER_SCAN_MAP = None
448448

449449
def _worker_get_exp(mzml_file):
450450
global _WORKER_EXP
@@ -458,8 +458,16 @@ def _worker_get_exp(mzml_file):
458458
_ = find_spectrum_by_mz(exp, 0.0, None)
459459
_WORKER_EXP = exp
460460
return _WORKER_EXP
461-
462-
461+
462+
463+
def _worker_get_scan_map(exp):
464+
"""Get or build the scan map for the worker process. Cached per worker."""
465+
global _WORKER_SCAN_MAP
466+
if _WORKER_SCAN_MAP is None:
467+
_WORKER_SCAN_MAP = build_scan_to_spectrum_map(exp)
468+
return _WORKER_SCAN_MAP
469+
470+
463471
def _worker_process_pid(task):
464472
try:
465473
mzml_path = task["mzml_path"]
@@ -475,7 +483,7 @@ def _worker_process_pid(task):
475483
if pid_info.get("spectrum_reference"):
476484
scan_number = extract_scan_number_from_reference(pid_info["spectrum_reference"])
477485
if scan_number is not None:
478-
scan_map = build_scan_to_spectrum_map(exp)
486+
scan_map = _worker_get_scan_map(exp)
479487
spectrum = find_spectrum_by_scan(exp, scan_number, scan_map)
480488

481489
# Fallback to m/z and RT matching if scan number lookup failed

0 commit comments

Comments
 (0)