protected virtual void ReadAttributes(XmlReader reader, out Adduct embeddedAdduct) { var formula = reader.GetAttribute(ATTR.formula); if (!string.IsNullOrEmpty(formula)) { formula = BioMassCalc.AddH(formula); // Update this old style formula to current by adding the hydrogen we formerly left out due to assuming protonation } else { var text = reader.GetAttribute(ATTR.ion_formula) ?? reader.GetAttribute(ATTR.neutral_formula); if (text != null) { text = text.Trim(); // We've seen some trailing spaces in the wild } formula = text; } string neutralFormula; Molecule mol; // We commonly see the adduct inline with the neutral formula ("C12H5[M+Na]"), so be ready to preserve that if (IonInfo.IsFormulaWithAdduct(formula, out mol, out embeddedAdduct, out neutralFormula)) { formula = neutralFormula; } else { embeddedAdduct = Adduct.EMPTY; } if (string.IsNullOrEmpty(formula)) { AverageMass = ReadAverageMass(reader); MonoisotopicMass = ReadMonoisotopicMass(reader); } Formula = formula; Name = reader.GetAttribute(ATTR.custom_ion_name); if (string.IsNullOrEmpty(Name)) { Name = reader.GetAttribute(ATTR.name) ?? string.Empty; } AccessionNumbers = MoleculeAccessionNumbers.FromSerializableString(reader.GetAttribute(ATTR.id)); Validate(); }
protected virtual void ReadAttributes(XmlReader reader) { Formula = reader.GetAttribute(ATTR.formula); if (!string.IsNullOrEmpty(Formula)) { Formula = BioMassCalc.AddH(Formula); // Update this old style formula to current by adding the hydrogen we formerly left out due to assuming protonation } else { Formula = reader.GetAttribute(ATTR.ion_formula); } if (string.IsNullOrEmpty(Formula)) { AverageMass = reader.GetDoubleAttribute(ATTR.mass_average); MonoisotopicMass = reader.GetDoubleAttribute(ATTR.mass_monoisotopic); } Validate(); }
public void ReporterIonTest() { // Test the code that updates old-style formulas Assert.AreEqual("C5C'H13N2", BioMassCalc.AddH("C5C'H12N2")); Assert.AreEqual("CO2H", BioMassCalc.AddH("CO2")); var docOriginal = new SrmDocument(SrmSettingsList.GetDefault().ChangeTransitionInstrument(instrument => instrument.ChangeMinMz(10))); // H2O2 is not very heavy! IdentityPath path; SrmDocument docPeptide = docOriginal.ImportFasta(new StringReader(">peptide1\nPEPMCIDEPR"), true, IdentityPath.ROOT, out path); // One of the prolines should have caused an extra transition Assert.AreEqual(4, docPeptide.PeptideTransitionCount); Assert.IsTrue(docPeptide.PeptideTransitions.Contains(nodeTran => nodeTran.Transition.Ordinal == 8)); const string formula = "H2O2"; // This was H2O, but that falls below mz=10 at z > 1 const string hydrogenPeroxide = "Hydrogen Perxoide"; var reporterIons = new[] { new MeasuredIon(hydrogenPeroxide, formula, null, null, Adduct.SINGLY_PROTONATED), new MeasuredIon(hydrogenPeroxide, formula, null, null, Adduct.DOUBLY_PROTONATED), new MeasuredIon(hydrogenPeroxide, formula, null, null, Adduct.TRIPLY_PROTONATED), MeasuredIonList.NTERM_PROLINE }; SrmDocument docReporterIon = docPeptide.ChangeSettings(docPeptide.Settings.ChangeTransitionFilter(filter => filter.ChangeMeasuredIons(reporterIons))); AssertEx.IsDocumentTransitionCount(docReporterIon, 7); //Check With Monoisotopic var mass = BioMassCalc.MONOISOTOPIC.CalculateMassFromFormula(formula); for (int i = 0; i < 3; i++) { TransitionDocNode tranNode = docReporterIon.MoleculeTransitions.ElementAt(i); Transition tran = tranNode.Transition; Assert.AreEqual(reporterIons[i].SettingsCustomIon, tran.CustomIon); Assert.AreEqual(tran.Charge, i + 1); Assert.AreEqual(BioMassCalc.CalculateIonMz(mass, tran.Adduct), tranNode.Mz, BioMassCalc.MassElectron / 100); } //Check with Average TransitionPrediction predSettings = docReporterIon.Settings.TransitionSettings.Prediction.ChangeFragmentMassType(MassType.Average); TransitionSettings tranSettings = docReporterIon.Settings.TransitionSettings.ChangePrediction(predSettings); SrmSettings srmSettings = docReporterIon.Settings.ChangeTransitionSettings(tranSettings); SrmDocument averageDocument = docReporterIon.ChangeSettings(srmSettings); mass = BioMassCalc.AVERAGE.CalculateMassFromFormula(formula); for (int i = 0; i < 3; i++) { TransitionDocNode tranNode = averageDocument.MoleculeTransitions.ElementAt(i); Transition tran = tranNode.Transition; Assert.AreEqual(reporterIons[i].SettingsCustomIon, tran.CustomIon); Assert.AreEqual(tran.Charge, i + 1); Assert.AreEqual(BioMassCalc.CalculateIonMz(mass, tran.Adduct), tranNode.Mz, BioMassCalc.MassElectron / 100); } //Make sure the rest of the transitions aren't reporter ions for (int i = 3; i < 7; i++) { Transition tran = docReporterIon.MoleculeTransitions.ElementAt(i).Transition; Assert.AreNotEqual(tran.CustomIon, reporterIons); } var optionalIon = new MeasuredIon(hydrogenPeroxide, formula, null, null, Adduct.SINGLY_PROTONATED, true); SrmDocument optionalDoc = docPeptide.ChangeSettings(docPeptide.Settings.ChangeTransitionFilter(filter => filter.ChangeMeasuredIons(new[] { optionalIon }))); Assert.AreEqual(3, optionalDoc.PeptideTransitionCount); optionalDoc = optionalDoc.ChangeSettings(optionalDoc.Settings.ChangeTransitionFilter(filter => filter.ChangeMeasuredIons(new[] { optionalIon.ChangeIsOptional(false) }))); AssertEx.IsDocumentTransitionCount(optionalDoc, 4); Assert.AreEqual(optionalIon.ChangeIsOptional(false).SettingsCustomIon, optionalDoc.MoleculeTransitions.ElementAt(0).Transition.CustomIon); optionalDoc = optionalDoc.ChangeSettings( optionalDoc.Settings.ChangeTransitionFilter( filter => filter.ChangeMeasuredIons(new[] { optionalIon.ChangeIsOptional(true) }))); TransitionGroupDocNode nodeGroup = optionalDoc.MoleculeTransitionGroups.ElementAt(0); var filteredNodes = nodeGroup.GetPrecursorChoices(optionalDoc.Settings, optionalDoc.Molecules.ElementAt(0).ExplicitMods, true) .Cast <TransitionDocNode>() .Where(node => Equals(node.Transition.CustomIon, optionalIon.SettingsCustomIon)); var unfilteredNodes = nodeGroup.GetPrecursorChoices(optionalDoc.Settings, optionalDoc.Molecules.ElementAt(0).ExplicitMods, false) .Cast <TransitionDocNode>() .Where(node => Equals(node.Transition.CustomIon, optionalIon.SettingsCustomIon)); Assert.AreEqual(0, filteredNodes.Count()); Assert.AreEqual(1, unfilteredNodes.Count()); }