Skip to content

Commit

Permalink
Merge branch 'HC_fix' into 'master'
Browse files Browse the repository at this point in the history
Fix HC and OC calculations

See merge request mass-spectrometry/corems!113
  • Loading branch information
corilo committed Aug 8, 2024
2 parents 13c7e06 + 93adcc1 commit fd89859
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
12 changes: 9 additions & 3 deletions corems/molecular_formula/factory/MolecularFormulaFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,20 @@ def isotopologue_count_percentile(self, ):

@property
def O_C(self):

if 'O' in self._d_molecular_formula.keys():
return self._d_molecular_formula.get("O")/self._d_molecular_formula.get("C")
# gather all the Os and Hs, regardless of the isotopic composition
Os =sum([self._d_molecular_formula.get(key) for key in ['O'] + Atoms.isotopes['O'][1] if key in self._d_molecular_formula.keys()])
Cs = sum([self._d_molecular_formula.get(key) for key in ['C'] + Atoms.isotopes['C'][1] if key in self._d_molecular_formula.keys()])
return Os/Cs
else:
return 0

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

@property
def dbe(self): return self._calc_dbe()
Expand Down
5 changes: 5 additions & 0 deletions support_code/nmdc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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.

Production workflows and metadata generation scripts source locations:
- NOM worklfow and metadata generation scripts live in the EnviroMS repository
- GC-MS metabolomics workflow and metadata generation scripts live in the MetaMS repository
6 changes: 4 additions & 2 deletions tests/test_molecularFormulaSearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_run_molecular_formula_search():
def test_run_molecular_formula_search_adduct():
# Test for generating accurate molecular formula from a single mass using the local sql database
# Now also tests that it is handling isotopes correctly (for non-adducts)
mz = [782.563522, 783.566877] #Na+ adduct of C56H73N1 and it's M+1
mz = [782.563522, 783.566877] #Na+ adduct of C56H73N1 and its M+1
abundance = [1, 0.4]
rp, s2n = [[1, 1],[1, 1]]

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

assert mass_spectrum_obj[0][0].string == 'C56 H73 N1'
assert mass_spectrum_obj[0][0].string == 'C56 H73 N1'
assert mass_spectrum_obj[0][0].H_C == 73/56
assert mass_spectrum_obj[1][0].string == 'C55 H73 N1 13C1'
assert mass_spectrum_obj[1][0].H_C == 73/56



Expand Down

0 comments on commit fd89859

Please sign in to comment.