Skip to content

Commit c5783f1

Browse files
committed
Update variables names for NIST database
1 parent 11cd321 commit c5783f1

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

beams/annotation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def calculate_ppm_error(mass, theo_mass):
3131
def _remove_elements_from_compositions(records, keep):
3232

3333
path_nist_database = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'nist_database.txt')
34-
nist_mass = nist_database_to_pyteomics(path_nist_database)
34+
nist_database = nist_database_to_pyteomics(path_nist_database)
3535

36-
elements = [e for e in nist_mass if e not in keep]
36+
elements = [e for e in nist_database if e not in keep]
3737
for record in records:
3838
for e in elements:
3939
if "composition" in record:
@@ -616,7 +616,7 @@ def annotate_molecular_formulae(peaklist, lib_adducts, ppm, db_out, db_in="http:
616616
r.raise_for_status()
617617

618618
path_nist_database = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'nist_database.txt')
619-
nist_mass = nist_database_to_pyteomics(path_nist_database)
619+
nist_database = nist_database_to_pyteomics(path_nist_database)
620620

621621
for i in range(len(peaklist.iloc[:, 0])):
622622
mz = float(peaklist["mz"].iloc[i])
@@ -652,7 +652,7 @@ def annotate_molecular_formulae(peaklist, lib_adducts, ppm, db_out, db_in="http:
652652
del record["DoubleBondEquivalents"]
653653
record["mz"] = mz
654654
record["ppm_error"] = calculate_ppm_error(mz, record["exact_mass"])
655-
comp = OrderedDict([(item, record[item]) for item in record if item in nist_mass.keys()])
655+
comp = OrderedDict([(item, record[item]) for item in record if item in nist_database.keys()])
656656
record["molecular_formula"] = composition_to_string(comp)
657657
record["adduct"] = adduct
658658
records = _remove_elements_from_compositions(records, keep=["C", "H", "N", "O", "P", "S"])
@@ -858,7 +858,7 @@ def annotate_drug_products(peaklist, db_out, list_smiles, lib_adducts, ppm, phas
858858
);""")
859859

860860
path_nist_database = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'nist_database.txt')
861-
nist_db = nist_database_to_pyteomics(path_nist_database)
861+
nist_database = nist_database_to_pyteomics(path_nist_database)
862862

863863
records = []
864864
for smiles_parent in list_smiles:

beams/in_out.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def read_molecular_formulae(filename, separator="\t", calculate=True, filename_a
4848

4949
if calculate:
5050
path_nist_database = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'nist_database.txt')
51-
nist_db = nist_database_to_pyteomics(path_nist_database)
51+
nist_database = nist_database_to_pyteomics(path_nist_database)
5252

5353
df = read_csv(filename, sep=separator, float_precision="round_trip")
5454
records = []
@@ -60,7 +60,7 @@ def read_molecular_formulae(filename, separator="\t", calculate=True, filename_a
6060
sum_CHNOPS = sum([comp[e] for e in comp if e in ["C", "H", "N", "O", "P", "S"]])
6161
record["CHNOPS"] = sum_CHNOPS == sum(list(comp.values()))
6262
if calculate:
63-
record["exact_mass"] = round(pyteomics_mass.mass.calculate_mass(formula=str(row.molecular_formula), mass_data=nist_db), 6)
63+
record["exact_mass"] = round(pyteomics_mass.mass.calculate_mass(formula=str(row.molecular_formula), mass_data=nist_database), 6)
6464
else:
6565
record["exact_mass"] = float(row.exact_mass)
6666
record.update(HC_HNOPS_rules(str(row.molecular_formula)))
@@ -77,7 +77,7 @@ def read_compounds(filename, separator="\t", calculate=True, filename_atoms=""):
7777

7878
if calculate:
7979
path_nist_database = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'nist_database.txt')
80-
nist_db = nist_database_to_pyteomics(path_nist_database)
80+
nist_database = nist_database_to_pyteomics(path_nist_database)
8181

8282
df = read_csv(filename, sep=separator, float_precision="round_trip")
8383
records = []
@@ -89,7 +89,7 @@ def read_compounds(filename, separator="\t", calculate=True, filename_atoms=""):
8989
sum_CHNOPS = sum([comp[e] for e in comp if e in ["C", "H", "N", "O", "P", "S"]])
9090
record["CHNOPS"] = sum_CHNOPS == sum(list(comp.values()))
9191
if calculate:
92-
record["exact_mass"] = round(pyteomics_mass.calculate_mass(formula=str(str(row.molecular_formula)), mass_data=nist_db),6)
92+
record["exact_mass"] = round(pyteomics_mass.calculate_mass(formula=str(str(row.molecular_formula)), mass_data=nist_database),6)
9393
else:
9494
record["exact_mass"] = float(row.exact_mass)
9595
record["compound_id"] = row.compound_id

tests/test_libraries.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ def test_mass_differences(self):
4141
self.assertEqual(lib_differences.lib, [])
4242

4343
def test_nist_database_to_pyteomics(self):
44-
nist_mass = nist_database_to_pyteomics(os.path.join(self.path, "beams", "data", "nist_database.txt"))
45-
self.assertEqual(nist_mass["C"][0], (12.0, 1.0))
46-
self.assertEqual(nist_mass["H"][0], (1.00782503223, 1.0))
47-
self.assertEqual(nist_mass["N"][0], (14.00307400443, 1.0))
48-
self.assertEqual(nist_mass["O"][0], (15.99491461957, 1.0))
49-
self.assertEqual(nist_mass["P"][0], (30.97376199842, 1.0))
50-
self.assertEqual(nist_mass["S"][0], (31.9720711744, 1.0))
44+
nist_database = nist_database_to_pyteomics(os.path.join(self.path, "beams", "data", "nist_database.txt"))
45+
self.assertEqual(nist_database["C"][0], (12.0, 1.0))
46+
self.assertEqual(nist_database["H"][0], (1.00782503223, 1.0))
47+
self.assertEqual(nist_database["N"][0], (14.00307400443, 1.0))
48+
self.assertEqual(nist_database["O"][0], (15.99491461957, 1.0))
49+
self.assertEqual(nist_database["P"][0], (30.97376199842, 1.0))
50+
self.assertEqual(nist_database["S"][0], (31.9720711744, 1.0))
5151

5252

5353
if __name__ == '__main__':

0 commit comments

Comments
 (0)