def search(self): for spectrum in self.spectrum_dataset: if spectrum.has_precursor_charge(): charge_list = [spectrum.precursor_charge] min_charge = 1 if spectrum.precursor_charge > 0 else -1 else: if self.maximum_charge < 0: charge_list = list(charge_range_(-1, self.maximum_charge)) min_charge = -1 else: charge_list = list(charge_range_(1, self.maximum_charge)) min_charge = 1 precursor_candidates_masses = [ (neutral_mass(spectrum.precursor_mz, c, self.charge_carrier), c) for c in charge_list ] precursor_candidate_structures = [] for candidate_mass, candidate_charge in precursor_candidates_masses: precursor_candidate_structures.extend( (s, candidate_charge) for s in self.structure_database.search_mass( candidate_mass, self.precursor_mass_tolerance)) solutions = [] for precursor, charge in precursor_candidate_structures: solution = match( spectrum.peaklist, precursor, self.product_ion_mass_tolerance, charge_range=(min_charge, charge), charge_carrier=self.charge_carrier) solutions.append(solution) solution_set = SolutionSet(spectrum, solutions, spectrum.name) yield solution_set
def test_deconvolution(self): scan = self.make_scan() algorithm_type = AveragineDeconvoluter deconresult = deconvolute_peaks( scan.peak_set, { "averagine": peptide, "scorer": PenalizedMSDeconVFitter(5., 1.), "use_subtraction": False, }, left_search_limit=3, deconvoluter_type=algorithm_type) dpeaks = deconresult.peak_set assert len(dpeaks) == 6 for point in points: peak = dpeaks.has_peak(neutral_mass(point[0], point[1])) self.assertIsNotNone(peak)
def test_deconvolution(self): scan = self.make_scan() algorithm_type = AveragineDeconvoluter deconresult = deconvolute_peaks( scan.peak_set, { "averagine": peptide, "scorer": PenalizedMSDeconVFitter(5., 1.), "use_subtraction": False }, deconvoluter_type=algorithm_type) dpeaks = deconresult.peak_set assert len(dpeaks) == 6 for point in points: peak = dpeaks.has_peak(neutral_mass(point[0], point[1])) self.assertIsNotNone(peak)
def scale(self, mz, charge=1, charge_carrier=PROTON): neutral = neutral_mass(mz, charge, charge_carrier) scale = neutral / self.base_mass scaled = {} for elem, count in self.base_composition.items(): scaled[elem] = round(count * scale) scaled_mass = calculate_mass(scaled) delta_hydrogen = round(scaled_mass - neutral) H = scaled["H"] if H > delta_hydrogen: scaled["H"] = H - delta_hydrogen else: scaled["H"] = 0 return scaled
def test_graph_deconvolution(self): scan = self.make_scan() scan.pick_peaks() self.assertIsNotNone(scan.peak_set) algorithm_type = AveraginePeakDependenceGraphDeconvoluter deconresult = deconvolute_peaks( scan.peak_set, { "averagine": peptide, "scorer": PenalizedMSDeconVFitter(5., 1.) }, deconvoluter_type=algorithm_type) dpeaks = deconresult.peak_set deconvoluter = deconresult.deconvoluter for point in points: peak = dpeaks.has_peak(neutral_mass(point[0], point[1])) self.assertIsNotNone(peak) fp = scan.has_peak(peak.mz) self.assertAlmostEqual( deconvoluter.peak_dependency_network.find_solution_for(fp).mz, peak.mz, 3)
def test_graph_deconvolution(self): scan = self.make_scan() scan.pick_peaks() self.assertIsNotNone(scan.peak_set) algorithm_type = AveraginePeakDependenceGraphDeconvoluter deconresult = deconvolute_peaks( scan.peak_set, { "averagine": peptide, "scorer": PenalizedMSDeconVFitter(5., 1.) }, deconvoluter_type=algorithm_type) dpeaks = deconresult.peak_set assert len(dpeaks) == 2 deconvoluter = deconresult.deconvoluter for point in points: peak = dpeaks.has_peak(neutral_mass(point[0], point[1])) self.assertIsNotNone(peak) fp = scan.has_peak(peak.mz) self.assertAlmostEqual( deconvoluter.peak_dependency_network.find_solution_for(fp).mz, peak.mz, 3)
def scale(self, mz, charge=1, charge_carrier=PROTON): """Given an m/z and a charge state, interpolate the composition of the polymer with the matching neutral mass Parameters ---------- mz : float The reference m/z to calculate the neutral mass to interpolate from charge : int, optional The reference charge state to calculate the neutral mass. Defaults to 1 charge_carrier : float, optional The mass of the charge carrier. Defaults to the mass of a proton. Returns ------- Mapping The interpolated composition for the calculated neutral mass, rounded to the nearest integer and hydrogen corrected. References ---------- Senko, M. W., Beu, S. C., & McLafferty, F. W. (1995). Determination of monoisotopic masses and ion populations for large biomolecules from resolved isotopic distributions. Journal of the American Society for Mass Spectrometry, 6(4), 229–233. http://doi.org/10.1016/1044-0305(95)00017-8 """ neutral = neutral_mass(mz, charge, charge_carrier) scale = neutral / self.base_mass scaled = {} for elem, count in self.base_composition.items(): scaled[elem] = round(count * scale) scaled_mass = calculate_mass(scaled) delta_hydrogen = round(scaled_mass - neutral) H = scaled["H"] if H > delta_hydrogen: scaled["H"] = H - delta_hydrogen else: scaled["H"] = 0 return scaled