@@ -574,7 +574,7 @@ def annotate_multiple_charged_ions(source, db_out, ppm, lib, add=False):
574
574
return
575
575
576
576
577
- def annotate_molecular_formulae (peaklist , lib_adducts , ppm , db_out , db_in = "http://multiomics-int.cs .bham.ac.uk" , rules = True , max_mz = None ):
577
+ def annotate_molecular_formulae (peaklist , lib_adducts , ppm , db_out , db_in = "http://mfdb .bham.ac.uk" , rules = True , max_mz = None ):
578
578
579
579
conn = sqlite3 .connect (db_out )
580
580
cursor = conn .cursor ()
@@ -607,10 +607,10 @@ def annotate_molecular_formulae(peaklist, lib_adducts, ppm, db_out, db_in="http:
607
607
conn_mem = DbMolecularFormulaeMemory (db_in )
608
608
max_mz = None
609
609
else :
610
- url = '{}/mass_range' .format (db_in )
611
- url_test = '{}// mass?mass=180.06339&tol=0.0&unit =ppm&rules=1' .format (db_in )
610
+ url = '{}/api/formula/ mass_range' .format (db_in )
611
+ url_test = '{}/api/formula/ mass?mass=180.06339&tol=0.0&tol_unit =ppm&rules=1' .format (db_in )
612
612
o = urlparse (url )
613
- if o .scheme != "http" and o .netloc != "multiomics-int.cs .bham.ac.uk" :
613
+ if o .scheme != "http" and o .netloc != "mfdb .bham.ac.uk" :
614
614
raise ValueError ("No database or local db available" )
615
615
else :
616
616
r = requests .get (url_test )
@@ -636,21 +636,23 @@ def annotate_molecular_formulae(peaklist, lib_adducts, ppm, db_out, db_in="http:
636
636
if "conn_mem" in locals ():
637
637
records = conn_mem .select_mf (min_tol - lib_adducts .lib [adduct ], max_tol - lib_adducts .lib [adduct ], rules )
638
638
else :
639
- params = {"lower" : min_tol - lib_adducts .lib [adduct ], "upper" : max_tol - lib_adducts .lib [adduct ], "rules" : int (rules )}
639
+ params = {"lower" : min_tol - lib_adducts .lib [adduct ],
640
+ "upper" : max_tol - lib_adducts .lib [adduct ],
641
+ "rules" : int (rules )}
640
642
response = requests .get (url , params = params )
641
643
records = response .json ()["records" ]
642
644
643
645
for record in records :
646
+ record ["id" ] = name
644
647
if "CHNOPS" not in record : # MFdb API specific
645
648
record ["CHNOPS" ] = True # MFdb API specific
646
- record ["id" ] = name
647
- if "ExactMass" in record : # TODO: Remove when API has been updated
648
- record ["exact_mass" ] = record ["ExactMass" ]
649
- del record ["ExactMass" ]
649
+ if "rules" in record :
650
+ record .update (record ["rules" ])
651
+ del record ["rules" ]
652
+ if "atoms" in record :
653
+ record .update (record ["atoms" ])
654
+ del record ["atoms" ]
650
655
record ["exact_mass" ] = record ["exact_mass" ] + lib_adducts .lib [adduct ]
651
- if "DoubleBondEquivalents" in record : # TODO: Remove when API has been updated
652
- record ["double_bond_equivalents" ] = record ["DoubleBondEquivalents" ]
653
- del record ["DoubleBondEquivalents" ]
654
656
record ["mz" ] = mz
655
657
record ["ppm_error" ] = calculate_ppm_error (mz , record ["exact_mass" ])
656
658
comp = OrderedDict ([(item , record [item ]) for item in record if item in nist_database .keys ()])
@@ -659,7 +661,7 @@ def annotate_molecular_formulae(peaklist, lib_adducts, ppm, db_out, db_in="http:
659
661
records = _remove_elements_from_compositions (records , keep = ["C" , "H" , "N" , "O" , "P" , "S" ])
660
662
values .extend ([list (record .values ()) for record in records ])
661
663
662
- time .sleep (0.05 )
664
+ time .sleep (0.02 )
663
665
if len (values ) > 0 :
664
666
cursor .executemany ("""insert into molecular_formulae ({}) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
665
667
""" .format ("," .join (map (str , list (record .keys ())))), values )
0 commit comments