def make_sf_adduct_optimusfilter(sum_formulae,adducts,output_filename,sigma=0.001,resolution=10000,charge=1): from pyMS.pyisocalc import pyisocalc # Extract variables from config dict # Check if already genrated and load if possible, otherwise calculate fresh with open(output_filename,'a') as f_out: for sum_formula in sum_formulae: #print sum_formula for adduct in adducts: try: sf = pyisocalc.complex_to_simple(sum_formula+adduct) if sf is None: # not possible to form adduct continue isotope_ms = pyisocalc.isodist(sf, plot=False, sigma=sigma, charges=charge, resolution=resolution) except KeyError as e: if str(e).startswith("KeyError:"): print str(e) continue except ValueError as e: if str(e).startswith("Element not recognised"): print str(e) continue except: print sf=="", sum_formula, adduct raise f_out.write("{} [M{}],-1,{}\n".format(sum_formula,adduct,isotope_ms.get_spectrum(source='centroids')[0][0]))
def calculate_isotope_patterns(sum_formulae, adduct='', isocalc_sig=0.01, isocalc_resolution=200000., isocalc_do_centroid=True, charge=1, verbose=True): from pyMS.pyisocalc import pyisocalc ### Generate a mz list of peak centroids for each sum formula with the given adduct mz_list = {} for n, sum_formula in enumerate(sum_formulae): try: if verbose: print sum_formula, adduct sf = pyisocalc.complex_to_simple(sum_formula + adduct) except KeyError as e: if str(e).startswith("KeyError: "): print str(e) continue except ValueError as e: if str(e).startswith("Element not recognised"): print str(e) continue else: print sum_formula, adduct raise if sf == None: #negative atoms as a result of simplification print 'negative adduct for {} : {}'.format(sum_formula, adduct) continue try: isotope_ms = pyisocalc.isodist(sf, plot=False, sigma=isocalc_sig, charges=charge, resolution=isocalc_resolution, do_centroid=isocalc_do_centroid) except KeyError as e: if str(e).startswith("KeyError: "): print str(e) continue if not sum_formula in mz_list: mz_list[sum_formula] = {} mz_list[sum_formula][adduct] = isotope_ms.get_spectrum( source='centroids') return mz_list
def calculate_isotope_patterns(sum_formulae, adduct='', isocalc_sig=0.01, isocalc_resolution=200000., isocalc_do_centroid=True, charge=1,verbose=True): from pyMS.pyisocalc import pyisocalc ### Generate a mz list of peak centroids for each sum formula with the given adduct mz_list = {} for n, sum_formula in enumerate(sum_formulae): try: if verbose: print sum_formula, adduct sf = pyisocalc.complex_to_simple(sum_formula+adduct) except KeyError as e: if str(e).startswith("KeyError: "): print str(e) continue except ValueError as e: if str(e).startswith("Element not recognised"): print str(e) continue else: print sum_formula, adduct raise if sf == None: #negative atoms as a result of simplification print 'negative adduct for {} : {}'.format(sum_formula,adduct) continue try: isotope_ms = pyisocalc.isodist(sf, plot=False, sigma=isocalc_sig, charges=charge, resolution=isocalc_resolution, do_centroid=isocalc_do_centroid) except KeyError as e: if str(e).startswith("KeyError: "): print str(e) continue if not sum_formula in mz_list: mz_list[sum_formula] = {} mz_list[sum_formula][adduct] = isotope_ms.get_spectrum(source='centroids') return mz_list