def getMZ(self, charge, agentFormula='H', agentCharge=1): """Get m/z of current sequence. Charge, agent formula and agent charge can be set.""" # get current mass and calculate mz return basics.mz(self.getMass(), charge, agentFormula=agentFormula, agentCharge=agentCharge)
def getCharges(peaklist, maxCharge, massTolerance, intTolerance): """Calculate charges for peaks of given peaklist by isotopes differences and averagine distribution. maxCharge: (int) maximu charge searched massTolerance: (float) m/z tolerance for the next isotope intTolerance: (float) intensity tolerance for the next isotope in %/100 """ # check peaklist if not isinstance(peaklist, objects.peaklist): peaklist = objects.peaklist(peaklist) # get averagine distribution averagineKeys = averagine.averagineDist.keys() averagineKeys.sort() # clear previous results peaklist = deepcopy(peaklist) for x in range(len(peaklist)): peaklist[x].charge = None peaklist[x].isotope = None # precalc delta mass for each charge delta = {} for x in range(abs(maxCharge)): delta[x+1] = 1.00287/(x+1) charges = delta.keys() charges.reverse() # set polarity polarity = 1 if maxCharge < 0: polarity = -1 # walk in peaklist for x in range(len(peaklist)): # skip identified peaks if peaklist[x].isotope != None: continue else: cluster = [peaklist[x]] # try all charges for z in charges: y = 1 isotope = 0 # get isotopic pattern pattern = None mass = basics.mz(peaklist[x].mz, 0, z*polarity) for key in averagineKeys: if key >= mass: pattern = averagine.averagineDist[key] break if not pattern: pattern = averagine.makeAveragineDist(config.averagineFormula, massRange=mass) # search for next isotope within tolerance while x+y < len(peaklist) and ((peaklist[x+y].mz - cluster[-1].mz) - delta[z]) <= massTolerance: if abs((peaklist[x+y].mz - cluster[-1].mz) - delta[z]) <= massTolerance: # add peak to cluster cluster.append(peaklist[x+y]) peaklist[x+y].charge = z*polarity isotope += 1 # check number if isotopes if not pattern or len(pattern)<=isotope: break # check isotope intensity to avoid skiping of overlaped peaks calcIntens = ((cluster[-2].intensity-cluster[-2].baseline) / pattern[isotope-1][1]) * pattern[isotope][1] if abs(peaklist[x+y].intensity - peaklist[x+y].baseline - calcIntens) < (calcIntens * intTolerance): peaklist[x+y].isotope = isotope y += 1 # skip other charges if one isotope at least was found if len(cluster) > 1: peaklist[x].charge = z*polarity peaklist[x].isotope = 0 break return peaklist