def convert_to_identification_item_dict(spectrum_match, seen=None, id_tracker=None): if seen is None: seen = set() charge = spectrum_match.scan.precursor_information.charge if spectrum_match.target.id not in seen: return None data = { "charge_state": charge, "experimental_mass_to_charge": mass_charge_ratio( spectrum_match.scan.precursor_information.neutral_mass, charge), "calculated_mass_to_charge": mass_charge_ratio(spectrum_match.target.total_mass, charge), "peptide_id": id_tracker(spectrum_match.target), "peptide_evidence_id": spectrum_match.target.id, "score": { "name": "GlycReSoft:score", "value": spectrum_match.score }, "params": [ { "name": "GlycReSoft:q-value", "value": spectrum_match.q_value }, ], "id": spectrum_match.id } return data
def decharge(self, include_envelopes=True, charge_carrier=PROTON, new_charge=1): """Transfomr multiply charged deconvoluted peaks into singly charged deconvoluted peaks. This operation returns a copy of the peak set, the input peak set is unchanged. Parameters ---------- include_envelopes : bool, optional Whether or not to charge-transform the isotopic envelope fitted in :attr:`DeconvolutedPeak.envelope` (the default is True) charge_carrier : float, optional The charge carrier mass to use when recalculating m/z (the default is PROTON) new_charge : int, optional The new charge to set all peaks to, the default being +1 Returns ------- DeconvolutedPeakSet """ peaks = [] for peak in self: mz = mass_charge_ratio(peak.neutral_mass, new_charge, charge_carrier=charge_carrier) if include_envelopes: envelope = Envelope([ EnvelopePair( mass_charge_ratio( calc_neutral_mass(p.mz, peak.charge, charge_carrier), new_charge, charge_carrier), p.intensity) for p in peak.envelope ]) else: envelope = peak.envelope new_peak = DeconvolutedPeak(peak.neutral_mass, peak.intensity, new_charge, peak.signal_to_noise, None, peak.full_width_at_half_max, peak.a_to_a2_ratio, peak.most_abundant_mass, peak.average_mass, peak.score, envelope, mz, peak.fit, peak.chosen_for_msms, peak.area) peaks.append(new_peak) new_peak_set = self.__class__(peaks) new_peak_set.reindex() return new_peak_set
def __init__(self, neutral_mass, intensity, charge, signal_to_noise, index, full_width_at_half_max, a_to_a2_ratio=0, most_abundant_mass=0, average_mass=0, score=0, envelope=None, mz=0, fit=None, chosen_for_msms=False, area=0): if index is None: index = _Index() if envelope is None: envelope = () self.neutral_mass = neutral_mass self.intensity = intensity self.signal_to_noise = signal_to_noise self.index = index self.full_width_at_half_max = full_width_at_half_max self.charge = charge self.a_to_a2_ratio = a_to_a2_ratio self.most_abundant_mass = most_abundant_mass self.average_mass = average_mass self.score = score self.envelope = Envelope(envelope) self.mz = mz or mass_charge_ratio(self.neutral_mass, self.charge) self.fit = fit self.chosen_for_msms = chosen_for_msms self.area = area
def convert_to_identification_item_dict(spectrum_match, seen=None, id_tracker=None): if seen is None: seen = set() charge = spectrum_match.scan.precursor_information.charge if spectrum_match.target.id not in seen: return None data = { "charge_state": charge, "experimental_mass_to_charge": mass_charge_ratio( spectrum_match.scan.precursor_information.neutral_mass, charge), "calculated_mass_to_charge": mass_charge_ratio( spectrum_match.target.total_mass, charge), "peptide_id": id_tracker(spectrum_match.target), "peptide_evidence_id": spectrum_match.target.id, "score": {"name": "GlycReSoft:score", "value": spectrum_match.score}, "params": [ {"name": "GlycReSoft:q-value", "value": spectrum_match.q_value}, ], "id": spectrum_match.id } return data
def mass(self, charge=0, charge_carrier=Composition("Na").mass): """Calculate the mass of this structure from its elemental composition. Parameters ---------- charge : int, optional Instead of calculating neutral mass, calculate the mass to charge ratio with charge = `charge` charge_carrier : float, optional The charge carrier to use when charge is non-zero. By default this is a sodium. Returns ------- float """ if charge == 0: return self.structure.mass() return mass_charge_ratio(self.structure.mass(), z=charge, charge_carrier=charge_carrier)
def _poisson_approximate(mass, n_peaks, charge=1): lmbda = mass / 1800.0 p_i = 1.0 factorial_acc = 1 total = 1.0 intensities = [1.0] for i in range(1, n_peaks): p_i *= lmbda factorial_acc *= i cur_intensity = p_i / factorial_acc intensities.append( cur_intensity if not math.isinf(cur_intensity) else 0.0) total += intensities[i] result = [] iso_shift = isotopic_shift(charge) mz = mass_charge_ratio(mass, charge) for i, intens in enumerate(intensities): result.append(Peak(mz + i * iso_shift, intens / total, charge)) return TheoreticalIsotopicPattern(result, origin=mz)
def __init__(self, neutral_mass, intensity, charge, signal_to_noise, index, full_width_at_half_max, a_to_a2_ratio=None, most_abundant_mass=None, average_mass=None, score=None, envelope=None, mz=None, fit=None, chosen_for_msms=False, area=0): if index is None: index = _Index() self.neutral_mass = neutral_mass self.intensity = intensity self.signal_to_noise = signal_to_noise self.index = index self.full_width_at_half_max = full_width_at_half_max self.charge = charge self.a_to_a2_ratio = a_to_a2_ratio self.most_abundant_mass = most_abundant_mass self.average_mass = average_mass self.score = score self.envelope = Envelope(envelope) self.mz = mz or mass_charge_ratio(self.neutral_mass, self.charge) self.fit = fit self.chosen_for_msms = chosen_for_msms self.area = area
def convert_to_identification_item_dict(spectrum_match, seen=None, id_tracker=None): if seen is None: seen = set() charge = spectrum_match.scan.precursor_information.charge if spectrum_match.target.id not in seen: return None data = { "charge_state": charge, "experimental_mass_to_charge": mass_charge_ratio( spectrum_match.scan.precursor_information.neutral_mass, charge), "calculated_mass_to_charge": mass_charge_ratio( spectrum_match.target.total_mass, charge), "peptide_id": id_tracker(spectrum_match.target), "peptide_evidence_id": spectrum_match.target.id, "score": mparam({ "name": "GlycReSoft:total score", "value": spectrum_match.score, "accession": "MS:XXX10A", }), "params": [ components.CVParam(**{ "name": "glycan dissociating, peptide preserving", "accession": "MS:XXX111", "cvRef": "PSI-MS"}), components.CVParam(**{ "name": "glycan eliminated, peptide dissociating", "accession": "MS:XXX114", "cvRef": "PSI-MS"}), { "name": "scan start time", "value": spectrum_match.scan.scan_time, "unit_name": "minute" } ], "id": spectrum_match.id } if spectrum_match.is_multiscore(): score_params = [ mparam("GlycReSoft:peptide score", spectrum_match.score_set.peptide_score, "MS:XXX10C"), mparam("GlycReSoft:glycan score", spectrum_match.score_set.glycan_score, "MS:XXX10B"), mparam("GlycReSoft:glycan coverage", spectrum_match.score_set.glycan_coverage, "MS:XXX10H"), mparam("GlycReSoft:joint q-value", spectrum_match.q_value, "MS:XXX10G"), mparam("GlycReSoft:peptide q-value", spectrum_match.q_value_set.peptide_q_value, "MS:XXX10E"), mparam("GlycReSoft:glycan q-value", spectrum_match.q_value_set.glycan_q_value, "MS:XXX10F"), mparam("GlycReSoft:glycopeptide q-value", spectrum_match.q_value_set.glycopeptide_q_value, "MS:XXX10D"), ] data['params'].extend(score_params) else: data['params'].extend([ mparam("GlycReSoft:glycopeptide q-value", spectrum_match.q_value, "MS:XXX10D"), ]) if spectrum_match.mass_shift.name != Unmodified.name: data['params'].append( mparam("GlycReSoft:mass shift", "%s:%0.3f:%0.3f" % ( spectrum_match.mass_shift.name, spectrum_match.mass_shift.mass, spectrum_match.mass_shift.tandem_mass), "MS:XXX10I")) return data