Skip to content

Commit fd89859

Browse files
committed
Merge branch 'HC_fix' into 'master'
Fix HC and OC calculations See merge request mass-spectrometry/corems!113
2 parents 13c7e06 + 93adcc1 commit fd89859

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

corems/molecular_formula/factory/MolecularFormulaFactory.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,20 @@ def isotopologue_count_percentile(self, ):
250250

251251
@property
252252
def O_C(self):
253-
254253
if 'O' in self._d_molecular_formula.keys():
255-
return self._d_molecular_formula.get("O")/self._d_molecular_formula.get("C")
254+
# gather all the Os and Hs, regardless of the isotopic composition
255+
Os =sum([self._d_molecular_formula.get(key) for key in ['O'] + Atoms.isotopes['O'][1] if key in self._d_molecular_formula.keys()])
256+
Cs = sum([self._d_molecular_formula.get(key) for key in ['C'] + Atoms.isotopes['C'][1] if key in self._d_molecular_formula.keys()])
257+
return Os/Cs
256258
else:
257259
return 0
258260

259261
@property
260-
def H_C(self): return self._d_molecular_formula.get("H")/self._d_molecular_formula.get("C")
262+
def H_C(self):
263+
# gather all the Cs and Hs, regardless of the isotopic composition
264+
Cs = sum([self._d_molecular_formula.get(key) for key in ['C'] + Atoms.isotopes['C'][1] if key in self._d_molecular_formula.keys()])
265+
Hs = sum([self._d_molecular_formula.get(key) for key in ['H'] + Atoms.isotopes['H'][1] if key in self._d_molecular_formula.keys()])
266+
return Hs/Cs
261267

262268
@property
263269
def dbe(self): return self._calc_dbe()

support_code/nmdc/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Scripts in this folder (support_code/nmdc) are for development and running locally. They should not be considered the "source of truth" for NMDC's workflows or metadata generation.
2+
3+
Production workflows and metadata generation scripts source locations:
4+
- NOM worklfow and metadata generation scripts live in the EnviroMS repository
5+
- GC-MS metabolomics workflow and metadata generation scripts live in the MetaMS repository

tests/test_molecularFormulaSearch.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_run_molecular_formula_search():
8787
def test_run_molecular_formula_search_adduct():
8888
# Test for generating accurate molecular formula from a single mass using the local sql database
8989
# Now also tests that it is handling isotopes correctly (for non-adducts)
90-
mz = [782.563522, 783.566877] #Na+ adduct of C56H73N1 and it's M+1
90+
mz = [782.563522, 783.566877] #Na+ adduct of C56H73N1 and its M+1
9191
abundance = [1, 0.4]
9292
rp, s2n = [[1, 1],[1, 1]]
9393

@@ -112,8 +112,10 @@ def test_run_molecular_formula_search_adduct():
112112
SearchMolecularFormulas(mass_spectrum_obj, find_isotopologues=True).run_worker_ms_peaks([mass_spectrum_obj[0]])
113113
mass_spectrum_obj.to_dataframe()
114114

115-
assert mass_spectrum_obj[0][0].string == 'C56 H73 N1'
115+
assert mass_spectrum_obj[0][0].string == 'C56 H73 N1'
116+
assert mass_spectrum_obj[0][0].H_C == 73/56
116117
assert mass_spectrum_obj[1][0].string == 'C55 H73 N1 13C1'
118+
assert mass_spectrum_obj[1][0].H_C == 73/56
117119

118120

119121

0 commit comments

Comments
 (0)