public void SpecialFragmentTest() { var docOriginal = new SrmDocument(SrmSettingsList.GetDefault()); IdentityPath path; var 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)); // y8 // Switch to the legacy version of the proline fragment where min length is 1 var docLegacyProline = docPeptide.ChangeSettings(docPeptide.Settings.ChangeTransitionFilter(filter => filter.ChangeMeasuredIons(new[] { MeasuredIonList.NTERM_PROLINE_LEGACY }))); Assert.AreEqual(5, docLegacyProline.PeptideTransitionCount); // Allow b-ions var docLegacyProlineB = docLegacyProline.ChangeSettings(docLegacyProline.Settings.ChangeTransitionFilter(filter => filter.ChangePeptideIonTypes(new[] { IonType.b, IonType.y }))); Assert.AreEqual(9, docLegacyProlineB.PeptideTransitionCount); // Add C-terminal Glu and Asp to the original peptide document var docGluAsp = docPeptide.ChangeSettings(docPeptide.Settings.ChangeTransitionFilter(filter => filter.ChangeMeasuredIons(new List <MeasuredIon>(filter.MeasuredIons) { MeasuredIonList.CTERM_GLU_ASP }))); Assert.AreEqual(5, docGluAsp.PeptideTransitionCount); Assert.IsTrue(docGluAsp.PeptideTransitions.Contains(nodeTran => nodeTran.Transition.Ordinal == 3)); // y3 // Use the legacy version instead var docGluAspLegacy = docPeptide.ChangeSettings(docPeptide.Settings.ChangeTransitionFilter(filter => filter.ChangeMeasuredIons(new List <MeasuredIon>(filter.MeasuredIons) { MeasuredIonList.CTERM_GLU_ASP_LEGACY }))); Assert.AreEqual(6, docGluAspLegacy.PeptideTransitionCount); Assert.IsTrue(docGluAspLegacy.PeptideTransitions.Contains(nodeTran => nodeTran.Transition.Ordinal == 2)); // y2 // Add Proline to the C-terminal modification var docGluAspPro = docPeptide.ChangeSettings(docPeptide.Settings.ChangeTransitionFilter(filter => filter.ChangeMeasuredIons(new[] { new MeasuredIon("C-term GAP", "EDP", null, SequenceTerminus.C, 1) }))); Assert.AreEqual(8, docGluAspPro.PeptideTransitionCount); Assert.IsTrue(docGluAspPro.PeptideTransitions.Contains(nodeTran => nodeTran.Transition.Ordinal == 2 || // y2 nodeTran.Transition.Ordinal == 8)); // y8 // Restrict var docGluAspProRestrict = docPeptide.ChangeSettings(docPeptide.Settings.ChangeTransitionFilter(filter => filter.ChangeMeasuredIons(new[] { new MeasuredIon("C-term GAP", "EDP", "P", SequenceTerminus.C, 1) }))); Assert.AreEqual(6, docGluAspProRestrict.PeptideTransitionCount); Assert.IsFalse(docGluAspProRestrict.PeptideTransitions.Contains(nodeTran => nodeTran.Transition.Ordinal == 2 || // not y2 nodeTran.Transition.Ordinal == 8)); // not y8 }
public void MultiLabelTypeListTest() { int startRev = 0; SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault().ChangeTransitionInstrument(inst => inst.ChangeMaxMz(1800))); // Add some FASTA IdentityPath pathRoot = IdentityPath.ROOT; SrmDocument docFasta = document.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST_LIB), false, pathRoot, out _); const int initProt = 2, initPep = 26, initTran = 89; AssertEx.IsDocumentState(docFasta, ++startRev, initProt, initPep, initTran); // Add multiple heavy types var settings = docFasta.Settings.ChangePeptideModifications(mods => new PeptideModifications(mods.StaticModifications, new[] { new TypedModifications(LABEL_TYPE13_C, HEAVY_MODS_13_C), new TypedModifications(LABEL_TYPE15_N, HEAVY_MODS_15_N) })); var docMulti = docFasta.ChangeSettings(settings); // CONSIDER: make explicit S-Lens, cone voltage, CE etc roundtrip? // docMulti.MoleculeTransitionGroups.FirstOrDefault().ChangeExplicitValues(ExplicitTransitionGroupValues.TEST) // Make sure transition lists export to various formats and roundtrip VerifyExportRoundTrip(new ThermoMassListExporter(docMulti), docFasta); // Add Oxidation (M) as a static modification to challenge new mass list importing flexibility VerifyExportRoundTrip(new AbiMassListExporter(AddOxidationM(docMulti)), AddOxidationM(docFasta)); VerifyExportRoundTrip(new AgilentMassListExporter(docMulti), docFasta); VerifyExportRoundTrip(new WatersMassListExporter(docMulti), docFasta); }
public void NeutralLossListTest() { TestSmallMolecules = false; // No concept of neutral loss for small molecules var phosphoLossMod = new StaticMod("Phospho Loss", "S, T, Y", null, false, "HPO3", LabelAtoms.None, RelativeRT.Matching, null, null, new[] { new FragmentLoss("H3PO4"), }); SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault().ChangePeptideModifications(mods => mods.ChangeStaticModifications(new List <StaticMod>(mods.StaticModifications) { phosphoLossMod }))); IdentityPath path = IdentityPath.ROOT; SrmDocument docFasta = document.ImportFasta(new StringReader(TEXT_FASTA_YEAST_7), false, path, out path); Assert.AreEqual(0, GetLossCount(docFasta, 1)); // Insert losses into the first transition group var pathPeptide = docFasta.GetPathTo((int)SrmDocument.Level.Molecules, 0); var nodePep = (PeptideDocNode)docFasta.FindNode(pathPeptide); var nodeGroup = (TransitionGroupDocNode)nodePep.Children[0]; var listChildren = new List <DocNode>(nodeGroup.Children); foreach (var nodeTran in nodeGroup.GetTransitions(docFasta.Settings, nodePep.ExplicitMods, nodeGroup.PrecursorMz, null, null, null, false)) { if (!nodeTran.HasLoss) { continue; } var tran = nodeTran.Transition; int matchIndex = listChildren.IndexOf(node => Equals(tran, ((TransitionDocNode)node).Transition)); if (matchIndex == -1) { continue; } while (matchIndex < listChildren.Count && Equals(tran, ((TransitionDocNode)listChildren[matchIndex]).Transition)) { matchIndex++; } listChildren.Insert(matchIndex, nodeTran); } var docLosses = (SrmDocument)docFasta.ReplaceChild(pathPeptide, nodeGroup.ChangeChildren(listChildren)); int lossCount = GetLossCount(docLosses, 1); Assert.IsTrue(lossCount > 0); var docRoundTripped = AssertEx.RoundTripTransitionList(new ThermoMassListExporter(docLosses)); Assert.AreEqual(lossCount, GetLossCount(docRoundTripped, 1)); docRoundTripped = AssertEx.RoundTripTransitionList(new AgilentMassListExporter(docLosses)); Assert.AreEqual(lossCount, GetLossCount(docRoundTripped, 1)); }
public void MultiLabelExplicitSerialTest() { // Create a simple document and add two peptides SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault()); const string pepSequence1 = "QFVLSCVILR"; const string pepSequence2 = "DIEVYCDGAITTK"; var reader = new StringReader(string.Join("\n", new[] { ">peptides1", pepSequence1, pepSequence2 })); IdentityPath path; document = document.ImportFasta(reader, true, IdentityPath.ROOT, out path); Assert.AreEqual(2, document.PeptideCount); // Add some modifications in two new label types var modCarb = new StaticMod("Carbamidomethyl Cysteine", "C", null, "C2H3ON"); var modOther = new StaticMod("Another Cysteine", "C", null, "CO8N2"); var staticMods = new[] { modCarb, modOther }; var mod15N = new StaticMod("All 15N", null, null, null, LabelAtoms.N15, null, null); var modK13C = new StaticMod("13C K", "K", ModTerminus.C, null, LabelAtoms.C13, null, null); var modR13C = new StaticMod("13C R", "R", ModTerminus.C, null, LabelAtoms.C13, null, null); var modV13C = new StaticMod("Heavy V", "V", null, null, LabelAtoms.C13 | LabelAtoms.N15, null, null); var heavyMods = new[] { mod15N, modK13C, modR13C, modV13C }; var labelTypeAA = new IsotopeLabelType("heavy AA", IsotopeLabelType.FirstHeavy); var labelTypeAll = new IsotopeLabelType("heavy All", IsotopeLabelType.FirstHeavy + 1); var settings = document.Settings; settings = settings.ChangePeptideModifications(mods => new PeptideModifications(mods.StaticModifications, new[] { new TypedModifications(labelTypeAA, new[] { modK13C, modR13C }), new TypedModifications(labelTypeAll, new[] { mod15N }) })); document = document.ChangeSettings(settings); Assert.AreEqual(6, document.PeptideTransitionGroupCount); // Add modifications to light and heavy AA in the first peptide path = document.GetPathTo((int)SrmDocument.Level.Molecules, 0); var nodePepMod = (PeptideDocNode)document.FindNode(path); var explicitMod = new ExplicitMods(nodePepMod.Peptide, new[] { new ExplicitMod(pepSequence1.IndexOf('C'), modOther) }, new[] { new TypedExplicitModifications(nodePepMod.Peptide, labelTypeAA, new ExplicitMod[0]) }); document = document.ChangePeptideMods(path, explicitMod, staticMods, heavyMods); Assert.AreEqual(5, document.PeptideTransitionGroupCount); // Add a modification to heavy All in the second peptide path = document.GetPathTo((int)SrmDocument.Level.Molecules, 1); nodePepMod = (PeptideDocNode)document.FindNode(path); explicitMod = new ExplicitMods(nodePepMod.Peptide, null, new[] { new TypedExplicitModifications(nodePepMod.Peptide, labelTypeAll, new[] { new ExplicitMod(pepSequence2.IndexOf('V'), modV13C) }) }); document = document.ChangePeptideMods(path, explicitMod, staticMods, heavyMods); Assert.AreEqual(5, document.PeptideTransitionGroupCount); AssertEx.Serializable(document, 3, AssertEx.DocumentCloned); }
public void DynamicMinMzTest() { var revisionIndex = 1; var settings = SrmSettingsList.GetDefault().ChangeTransitionFilter(filter => filter.ChangePeptideIonTypes(new[] { IonType.y, IonType.b }) .ChangeFragmentRangeFirstName("ion 1") .ChangeFragmentRangeLastName("last ion")); var docOriginal = new SrmDocument(settings); IdentityPath path; var docPeptides = docOriginal.ImportFasta(new StringReader(">peptides\nESTIGNSAFELLLEVAK\nTVYHAGTK"), true, IdentityPath.ROOT, out path); AssertEx.IsDocumentState(docPeptides, revisionIndex++, 1, 2, 2, 40); // Both precursors should contain 1 and 2 ions foreach (var nodeGroup in docPeptides.PeptideTransitionGroups) { Assert.IsTrue(nodeGroup.Children.Contains(node => ((TransitionDocNode)node).Transition.Ordinal == 1)); Assert.IsTrue(nodeGroup.Children.Contains(node => ((TransitionDocNode)node).Transition.Ordinal == 2)); } // Switch to using dynamic minimum for product ions settings = settings.ChangeTransitionInstrument(instrument => instrument.ChangeIsDynamicMin(true)); var docDynamicMin = docPeptides.ChangeSettings(settings); AssertEx.IsDocumentState(docDynamicMin, revisionIndex++, 1, 2, 35); var arrayNodeGroups = docDynamicMin.PeptideTransitionGroups.ToArray(); // The larger precursor should no longer have 1 or 2 ions Assert.IsFalse(arrayNodeGroups[0].Children.Contains(node => ((TransitionDocNode)node).Transition.Ordinal == 1 || ((TransitionDocNode)node).Transition.Ordinal == 2)); // But the smaller precursor should retain at least one of both Assert.IsTrue(arrayNodeGroups[1].Children.Contains(node => ((TransitionDocNode)node).Transition.Ordinal == 1)); Assert.IsTrue(arrayNodeGroups[1].Children.Contains(node => ((TransitionDocNode)node).Transition.Ordinal == 2)); // Use a minimum that is high enough to exclude the smaller precursor settings = settings.ChangeTransitionInstrument(instrument => instrument.ChangeMinMz(500)); var docHighMinDynamicMz = docDynamicMin.ChangeSettings(settings); AssertEx.IsDocumentState(docHighMinDynamicMz, revisionIndex++, 1, 2, 1, 22); // Because of the dynamic minimum for product ions, the remaining precursor should not have changed var nodeGroupHigh = docHighMinDynamicMz.PeptideTransitionGroups.ToArray()[0]; Assert.AreSame(arrayNodeGroups[0], nodeGroupHigh); // Remove dynamic minimum, and verify that product ions are removed settings = settings.ChangeTransitionInstrument(instrument => instrument.ChangeIsDynamicMin(false)); var docHighMinMz = docHighMinDynamicMz.ChangeSettings(settings); AssertEx.IsDocumentState(docHighMinMz, revisionIndex, 1, 2, 1, 17); // No library test, because it is hard to test. Many of the library // spectra are likely gathered with LTQs which apply the same dynamic // minimum to the ms/ms peaks they measure. }
public void MultiLabelExplicitSerialTest() { // Create a simple document and add two peptides SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault()); const string pepSequence1 = "QFVLSCVILR"; const string pepSequence2 = "DIEVYCDGAITTK"; var reader = new StringReader(string.Join("\n", new[] {">peptides1", pepSequence1, pepSequence2})); IdentityPath path; document = document.ImportFasta(reader, true, IdentityPath.ROOT, out path); Assert.AreEqual(2, document.PeptideCount); // Add some modifications in two new label types var modCarb = new StaticMod("Carbamidomethyl Cysteine", "C", null, "C2H3ON"); var modOther = new StaticMod("Another Cysteine", "C", null, "CO8N2"); var staticMods = new[] {modCarb, modOther}; var mod15N = new StaticMod("All 15N", null, null, null, LabelAtoms.N15, null, null); var modK13C = new StaticMod("13C K", "K", ModTerminus.C, null, LabelAtoms.C13, null, null); var modR13C = new StaticMod("13C R", "R", ModTerminus.C, null, LabelAtoms.C13, null, null); var modV13C = new StaticMod("Heavy V", "V", null, null, LabelAtoms.C13 | LabelAtoms.N15, null, null); var heavyMods = new[] { mod15N, modK13C, modR13C, modV13C }; var labelTypeAA = new IsotopeLabelType("heavy AA", IsotopeLabelType.FirstHeavy); var labelTypeAll = new IsotopeLabelType("heavy All", IsotopeLabelType.FirstHeavy + 1); var settings = document.Settings; settings = settings.ChangePeptideModifications(mods => new PeptideModifications(mods.StaticModifications, new[] { new TypedModifications(labelTypeAA, new[] {modK13C, modR13C}), new TypedModifications(labelTypeAll, new[] {mod15N}) })); document = document.ChangeSettings(settings); Assert.AreEqual(6, document.PeptideTransitionGroupCount); // Add modifications to light and heavy AA in the first peptide path = document.GetPathTo((int) SrmDocument.Level.Molecules, 0); var nodePepMod = (PeptideDocNode) document.FindNode(path); var explicitMod = new ExplicitMods(nodePepMod.Peptide, new[] {new ExplicitMod(pepSequence1.IndexOf('C'), modOther)}, new[] {new TypedExplicitModifications(nodePepMod.Peptide, labelTypeAA, new ExplicitMod[0])}); document = document.ChangePeptideMods(path, explicitMod, staticMods, heavyMods); Assert.AreEqual(5, document.PeptideTransitionGroupCount); // Add a modification to heavy All in the second peptide path = document.GetPathTo((int)SrmDocument.Level.Molecules, 1); nodePepMod = (PeptideDocNode)document.FindNode(path); explicitMod = new ExplicitMods(nodePepMod.Peptide, null, new[] { new TypedExplicitModifications(nodePepMod.Peptide, labelTypeAll, new[] {new ExplicitMod(pepSequence2.IndexOf('V'), modV13C)}) }); document = document.ChangePeptideMods(path, explicitMod, staticMods, heavyMods); Assert.AreEqual(5, document.PeptideTransitionGroupCount); AssertEx.Serializable(document, 3, AssertEx.DocumentCloned); }
public void RemoveDuplicatePeptidesTest() { // First try removals with no impact SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault0_6()); IdentityPath path; SrmDocument docFasta = document.ImportFasta(new StringReader(string.Format(TEXT_FASTA_YEAST_FRAGMENT, 1)), false, IdentityPath.ROOT, out path); AssertEx.IsDocumentState(docFasta, 1, 1, 11, 36); var refinementSettings = new RefinementSettings { RemoveDuplicatePeptides = true }; SrmDocument docFasta2 = refinementSettings.Refine(docFasta); Assert.AreSame(docFasta, docFasta2); docFasta2 = docFasta.ImportFasta(new StringReader(string.Format(TEXT_FASTA_YEAST_FRAGMENT, 2)), false, IdentityPath.ROOT, out path); // Adding same sequence twice, even with different custom names is ignored Assert.AreSame(docFasta, docFasta2); // Try a successful removal of duplicates that leaves no peptides SrmDocument docPeptides = document.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES1), true, IdentityPath.ROOT, out path); SrmDocument docPeptides2 = docPeptides.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES1), true, IdentityPath.ROOT, out path); AssertEx.IsDocumentState(docPeptides2, 2, 2, 26, 82); SrmDocument docPeptides3 = refinementSettings.Refine(docPeptides2); Assert.AreNotSame(docPeptides2, docPeptides3); AssertEx.IsDocumentState(docPeptides3, 3, 2, 0, 0); // Try again leaving a single peptide docPeptides2 = docPeptides.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES1 + "\n" + TEXT_BOVINE_SINGLE_PEPTIDE), true, IdentityPath.ROOT, out path); docPeptides3 = refinementSettings.Refine(docPeptides2); Assert.AreNotSame(docPeptides2, docPeptides3); AssertEx.IsDocumentState(docPeptides3, 3, 2, 1, 3); }
public void NeutralLossListTest() { TestSmallMolecules = false; // No concept of neutral loss for small molecules var phosphoLossMod = new StaticMod("Phospho Loss", "S, T, Y", null, false, "HPO3", LabelAtoms.None, RelativeRT.Matching, null, null, new[] { new FragmentLoss("H3PO4"), }); SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault().ChangePeptideModifications(mods => mods.ChangeStaticModifications(new List<StaticMod>(mods.StaticModifications) { phosphoLossMod }))); IdentityPath path = IdentityPath.ROOT; SrmDocument docFasta = document.ImportFasta(new StringReader(TEXT_FASTA_YEAST_7), false, path, out path); Assert.AreEqual(0, GetLossCount(docFasta, 1)); // Insert losses into the first transition group var pathPeptide = docFasta.GetPathTo((int) SrmDocument.Level.Molecules, 0); var nodePep = (PeptideDocNode) docFasta.FindNode(pathPeptide); var nodeGroup = (TransitionGroupDocNode) nodePep.Children[0]; var listChildren = new List<DocNode>(nodeGroup.Children); foreach (var nodeTran in nodeGroup.GetTransitions(docFasta.Settings, nodePep.ExplicitMods, nodeGroup.PrecursorMz, null, null, null, false)) { if (!nodeTran.HasLoss) continue; var tran = nodeTran.Transition; int matchIndex = listChildren.IndexOf(node => Equals(tran, ((TransitionDocNode)node).Transition)); if (matchIndex == -1) continue; while (matchIndex < listChildren.Count && Equals(tran, ((TransitionDocNode)listChildren[matchIndex]).Transition)) { matchIndex++; } listChildren.Insert(matchIndex, nodeTran); } var docLosses = (SrmDocument) docFasta.ReplaceChild(pathPeptide, nodeGroup.ChangeChildren(listChildren)); int lossCount = GetLossCount(docLosses, 1); Assert.IsTrue(lossCount > 0); var docRoundTripped = AssertEx.RoundTripTransitionList(new ThermoMassListExporter(docLosses)); Assert.AreEqual(lossCount, GetLossCount(docRoundTripped, 1)); docRoundTripped = AssertEx.RoundTripTransitionList(new AgilentMassListExporter(docLosses)); Assert.AreEqual(lossCount, GetLossCount(docRoundTripped, 1)); }
private static SrmDocument CreateLibraryDocument(SrmSettings settings, string textFasta, bool peptideList, TestDocumentContainer docContainer, BackgroundLoader libraryManager, out int startRev) { startRev = 0; SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault0_6()); Assert.IsTrue(docContainer.SetDocument(document, null)); // Register after first set document libraryManager.Register(docContainer); // Add libraries SrmDocument docLibraries = document.ChangeSettings(settings); ++startRev; // Add some FASTA IdentityPath path = IdentityPath.ROOT; SrmDocument docFasta = docLibraries.ImportFasta(new StringReader(textFasta), peptideList, path, out path); ++startRev; // Until libraries are loaded, only the sequences should appear if (!peptideList) { AssertEx.IsDocumentState(docFasta, startRev, textFasta.Count(c => c == '>'), 0, 0); } // Run the library load Assert.IsTrue(docContainer.SetDocument(docFasta, document, true)); ++startRev; // After library load completes peptides and transitions should have expected library info SrmDocument docLoaded = docContainer.Document; // Check expected library inforamation foreach (var nodePeptide in docLoaded.Peptides) { Assert.IsNull(nodePeptide.Rank); } foreach (var nodeTran in docLoaded.PeptideTransitions) { Assert.IsTrue(nodeTran.HasLibInfo); Assert.IsTrue(nodeTran.LibInfo.Rank <= 3); } return(docLoaded); }
private static SrmDocument CreateMixedDoc() { SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault0_6()); IdentityPath path; // Add fasta sequences SrmDocument docFasta = document.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST), false, IdentityPath.ROOT, out path); AssertEx.IsDocumentState(docFasta, 1, 2, 98, 311); // Insert peptide list at beginnning SrmDocument docMixed = docFasta.ImportFasta(new StringReader(SrmDocEditTest.TEXT_BOVINE_PEPTIDES1), true, docFasta.GetPathTo(0), out path); AssertEx.IsDocumentState(docMixed, 2, 3, 111, 352); return(docMixed); }
public void MoveNodeTest() { SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault()); IdentityPath path = IdentityPath.ROOT; SrmDocument docFasta = document.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST), false, path, out path); // 1. From peptide group to root SrmDocument docMoved = docFasta.MoveNode(docFasta.GetPathTo(0), IdentityPath.ROOT, out path); Assert.AreEqual(1, docMoved.FindNodeIndex(path)); Assert.AreSame(docFasta.Children[0], docMoved.Children[1]); Assert.AreSame(docFasta.Children[1], docMoved.Children[0]); // 2. From peptide group to before other peptide group docMoved = docFasta.MoveNode(docFasta.GetPathTo(1), docFasta.GetPathTo(0), out path); Assert.AreEqual(0, docMoved.FindNodeIndex(path)); Assert.AreSame(docFasta.Children[0], docMoved.Children[1]); Assert.AreSame(docFasta.Children[1], docMoved.Children[0]); // Some peptide lists IdentityPath pathPeptides; SrmDocument docPeptides = docFasta.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES2), true, docFasta.GetPathTo(1), out pathPeptides); docPeptides = docPeptides.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES1), true, IdentityPath.ROOT, out path); docPeptides = docPeptides.MoveNode(path, pathPeptides, out pathPeptides); Assert.AreEqual(1, docPeptides.FindNodeIndex(pathPeptides)); // 3. Peptide from one group to another IdentityPath fromParent = docPeptides.GetPathTo(2); IdentityPath from = new IdentityPath(fromParent, ((DocNodeParent)docPeptides.FindNode(fromParent)).Children[0].Id); SrmDocument docPeptides2 = docPeptides.MoveNode(from, pathPeptides, out path); Assert.AreEqual(pathPeptides, path.Parent); Assert.AreEqual(((DocNodeParent)docPeptides.Children[1]).Children.Count, ((DocNodeParent)docPeptides2.Children[1]).Children.Count - 1); Assert.AreEqual(((DocNodeParent)docPeptides.Children[2]).Children.Count, ((DocNodeParent)docPeptides2.Children[2]).Children.Count + 1); // Though moved to a different group, this should not have changed the overall // peptide order, since it was moved from the beginning of one group to the end // of the group before it. Assert.AreEqual(docPeptides.FindNodeIndex(from), docPeptides2.FindNodeIndex(path)); // 4. To before another peptide from = new IdentityPath(fromParent, ((DocNodeParent)docPeptides2.FindNode(fromParent)).Children[0].Id); IdentityPath path2; SrmDocument docPeptides3 = docPeptides2.MoveNode(from, path, out path2); Assert.AreEqual(pathPeptides, path.Parent); Assert.AreEqual(((DocNodeParent)docPeptides2.Children[1]).Children.Count, ((DocNodeParent)docPeptides3.Children[1]).Children.Count - 1); Assert.AreEqual(((DocNodeParent)docPeptides2.Children[2]).Children.Count, ((DocNodeParent)docPeptides3.Children[2]).Children.Count + 1); // Relative to all peptides, index should be 1 less than before Assert.AreEqual(docPeptides2.FindNodeIndex(from), docPeptides3.FindNodeIndex(path2) + 1); // 5. To within another peptide IdentityPath to = new IdentityPath(path, ((DocNodeParent)docPeptides3.FindNode(path)).Children[0].Id); SrmDocument docPeptides4 = docPeptides3.MoveNode(path2, to, out path); // Should not have changed to count in the group Assert.AreEqual(((DocNodeParent)docPeptides3.Children[1]).Children.Count, ((DocNodeParent)docPeptides4.Children[1]).Children.Count); // Relative to all peptides, should have been returned to original order Assert.AreEqual(docPeptides2.FindNodeIndex(from), docPeptides4.FindNodeIndex(path)); // Make sure expected exceptions are thrown Assert.IsNull(docPeptides4.FindNode(from)); AssertEx.ThrowsException <IdentityNotFoundException>(() => docPeptides4.MoveNode(from, to, out path)); AssertEx.ThrowsException <InvalidOperationException>(() => docPeptides2.MoveNode(from, docPeptides2.GetPathTo(0), out path)); AssertEx.ThrowsException <InvalidOperationException>(() => docPeptides3.MoveNode(docPeptides2.GetPathTo((int)SrmDocument.Level.Molecules, 0), to, out path)); AssertEx.ThrowsException <InvalidOperationException>(() => docPeptides3.MoveNode(docPeptides2.GetPathTo((int)SrmDocument.Level.Transitions, 0), to, out path)); }
public void TestPaste() { ClearDefaultModifications(); _yeastDoc = new SrmDocument(SrmSettingsList.GetDefault().ChangeTransitionInstrument(instrument => instrument.ChangeMaxMz(1600))); _yeastDoc = _yeastDoc.ChangeSettings(_yeastDoc.Settings.ChangeTransitionFilter(filter => filter.ChangeMeasuredIons(new MeasuredIon[0]))); IdentityPath path; _yeastDocReadOnly = _yeastDoc = _yeastDoc.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST_LIB), false, IdentityPath.ROOT, out path); _study7DocReadOnly = _study7Doc = CreateStudy7Doc(); IdentityPath pathRoot = IdentityPath.ROOT; // Test pasting into document with same implicit modifications does not create any extra explicit modifications. var study7EmptyDoc = (SrmDocument) _study7Doc.ChangeChildren(new DocNode[0]); var study7PasteDoc = CopyPaste(_study7Doc, null, study7EmptyDoc, pathRoot); var arrayPeptides = _study7Doc.Peptides.ToArray(); var arrayPastePeptides = study7PasteDoc.Peptides.ToArray(); Assert.AreEqual(arrayPeptides.Length, arrayPastePeptides.Length); AssertEx.DocsEqual(_study7Doc, study7PasteDoc); // DocsEqual gives a more verbose failure message using XML output // Test implicit mods in source document become explicit mods in target document. ResetDocuments(); _yeastDoc = (SrmDocument) _yeastDoc.ChangeChildren(new DocNode[0]); var settings = _yeastDoc.Settings; _yeastDoc = _yeastDoc.ChangeSettings(settings.ChangePeptideModifications(mods => mods.ChangeStaticModifications(new StaticMod[0]))); _yeastDoc = CopyPaste(_study7Doc, null, _yeastDoc, pathRoot); var pepMods = _yeastDoc.Settings.PeptideSettings.Modifications; Assert.IsTrue(pepMods.StaticModifications != null); Assert.IsTrue(pepMods.HasHeavyModifications); Assert.IsFalse(pepMods.StaticModifications.Contains(mod => !mod.IsExplicit)); Assert.IsFalse(pepMods.HeavyModifications.Contains(mod => !mod.IsExplicit)); // Test explicit mods are dropped if the target document has matching implicit modifications. study7PasteDoc = CopyPaste(_yeastDoc, null, study7EmptyDoc, pathRoot); Assert.AreEqual(_study7Doc, study7PasteDoc); // Add new label type to source document. ResetDocuments(); const string labelTypeName13C = "heavy 13C"; var labelType13C = new IsotopeLabelType(labelTypeName13C, IsotopeLabelType.light.SortOrder + 1); _yeastDoc = ChangePeptideModifications(_yeastDoc, new[] {new TypedModifications(labelType13C, HEAVY_MODS_13_C)}); Assert.IsTrue(_yeastDoc.PeptideTransitionGroups.Contains(nodeGroup => Equals(nodeGroup.TransitionGroup.LabelType, labelType13C))); // Test pasting into the same document with new label type. _yeastDoc = CopyPaste(_yeastDoc, null, _yeastDoc, pathRoot); // Check all transition have correct label type references. Assert.IsFalse(_yeastDoc.PeptideTransitionGroups.Contains(nodeGroup => { IsotopeLabelType labelType = nodeGroup.TransitionGroup.LabelType; return !ReferenceEquals(labelType, _yeastDoc.Settings.PeptideSettings.Modifications.GetModificationsByName(labelType.Name).LabelType); })); // Check new document still serializes correctly. AssertEx.Serializable(_yeastDoc, AssertEx.DocumentCloned); // Test pasting into new document drops label types from source document that are not found in the target document. _yeastDoc = CopyPaste(_yeastDoc, null, new SrmDocument(SrmSettingsList.GetDefault()), pathRoot); Assert.IsNull(_yeastDoc.Settings.PeptideSettings.Modifications.GetModificationsByName(labelTypeName13C)); // If only specific children are selected, test that only these children get copied. ResetDocuments(); var arrayTrans = _study7Doc.PeptideTransitions.ToArray(); IList<DocNode> selNodes = new List<DocNode>(); for (int i = 0; i < arrayTrans.Length; i += 2) { selNodes.Add(arrayTrans[i]); } _study7Doc = CopyPaste(_study7Doc, selNodes, _study7Doc, pathRoot); Assert.AreEqual(arrayTrans.Length + selNodes.Count, _study7Doc.PeptideTransitionCount); // Test after pasting to a peptide list, all children have been updated to point to the correct parent. ResetDocuments(); _study7Doc = CopyPaste(_yeastDoc, new[] { _yeastDoc.Peptides.ToArray()[0] }, _study7Doc, _study7Doc.GetPathTo((int) SrmDocument.Level.MoleculeGroups, 0)); Assert.AreEqual(_yeastDoc.Peptides.ToArray()[0].Peptide, _study7Doc.Peptides.ToArray()[0].Peptide); Assert.AreEqual(_study7Doc.Peptides.ToArray()[0].Peptide, _study7Doc.PeptideTransitionGroups.ToArray()[0].TransitionGroup.Peptide); Assert.AreEqual(_study7Doc.PeptideTransitionGroups.ToArray()[0].TransitionGroup, _study7Doc.PeptideTransitions.ToArray()[0].Transition.Group); // If only specific transition are selected for a peptide, but all transition groups are included, test AutoManageChildren is true. ResetDocuments(); selNodes = new List<DocNode>(); foreach (TransitionGroupDocNode transGroup in _study7Doc.PeptideTransitionGroups) { selNodes.Add(transGroup.Children[0]); } // TODO: Fix this and make it pass // var emptyDoc = (SrmDocument)_study7Doc.ChangeChildren(new List<DocNode>()); // _study7Doc = CopyPaste(_study7Doc, selNodes, emptyDoc, pathRoot); _study7Doc = (SrmDocument)_study7Doc.ChangeChildren(new List<DocNode>()); _study7Doc = CopyPaste(_study7Doc, selNodes, _study7Doc, pathRoot); foreach (PeptideDocNode peptide in _study7Doc.Peptides) Assert.IsTrue(peptide.AutoManageChildren); // Test pasting in modifications with the same name as but different definition from existing modifications not allowed. ResetDocuments(); _yeastDoc = ChangePeptideModifications(_yeastDoc, new[] { new TypedModifications(IsotopeLabelType.heavy, HEAVY_C_K_DIFDEF) }); SetDefaultModifications(_study7Doc); AssertEx.ThrowsException<Exception>(() => _yeastDoc.Settings.UpdateDefaultModifications(false)); // Test variable modifications kept if target document has matching variable modifications turned on. ResetDocuments(); settings = _yeastDoc.Settings; var modsDefault = settings.PeptideSettings.Modifications; var listVariableMods = new List<StaticMod>(modsDefault.StaticModifications) { VAR_MET_OXIDIZED }; _yeastDoc = _yeastDoc.ChangeSettings(settings.ChangePeptideModifications(mods => mods.ChangeStaticModifications(listVariableMods.ToArray()))); // Make sure there is an implicitly modified peptide in the yeast document Assert.IsTrue(_yeastDoc.Peptides.Contains(nodePep => nodePep.Peptide.Sequence.Contains("C"))); Assert.IsTrue(_yeastDoc.Peptides.Contains(nodePep => nodePep.HasVariableMods)); _yeastDoc = CopyPaste(_yeastDoc, null, _yeastDoc, pathRoot); Assert.IsFalse(_yeastDoc.Peptides.Contains(nodePep => nodePep.HasExplicitMods && !nodePep.HasVariableMods)); // Otherwise the variable modifications become only explicit modifications. var yeastDocVar = _yeastDoc; _yeastDoc = _yeastDoc.ChangeSettings(_yeastDoc.Settings.ChangePeptideModifications(mods => modsDefault)); _yeastDoc = CopyPaste(yeastDocVar, null, _yeastDoc, pathRoot); Assert.IsFalse(_yeastDoc.Settings.PeptideSettings.Modifications.HasVariableModifications); Assert.IsTrue(_yeastDoc.Peptides.Contains(nodePep => nodePep.HasExplicitMods)); Assert.IsFalse(_yeastDoc.Peptides.Contains(nodePep => nodePep.HasVariableMods)); }
public void VariableModBasicTest() { SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault0_6()); // Make sure default document produces no variable modifications IdentityPath path = IdentityPath.ROOT; var docYeast = document.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST), false, path, out path); Assert.AreEqual(0, GetVariableModCount(docYeast)); // Add a single variable modification var settings = document.Settings; var modsDefault = settings.PeptideSettings.Modifications; var listStaticMods = new List<StaticMod>(modsDefault.StaticModifications) {VAR_MET_OXIDIZED}; var docMetOxidized = document.ChangeSettings(settings.ChangePeptideModifications(mods => mods.ChangeStaticModifications(listStaticMods.ToArray()))); // Make sure variable modifications are added as expected to imported FASTA path = IdentityPath.ROOT; var docMoYeast = docMetOxidized.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST), false, path, out path); Assert.AreEqual(21, GetVariableModCount(docMoYeast)); AssertEx.IsDocumentState(docMoYeast, 2, 2, 119, 374); // Exclude unmodified peptides var docNoMoExclude = docMoYeast.ChangeSettings(docMoYeast.Settings.ChangePeptideFilter(f => f.ChangeExclusions(new[] { new PeptideExcludeRegex("Non-Oxidized Meth", "M\\[", true, true) }))); Assert.AreEqual(GetVariableModCount(docMoYeast), GetVariableModCount(docNoMoExclude)); Assert.AreEqual(docNoMoExclude.PeptideCount, GetVariableModCount(docNoMoExclude)); AssertEx.IsDocumentState(docNoMoExclude, 3, 2, 21, 63); // Exclude multiply modified peptides var docMultMoExclude = docNoMoExclude.ChangeSettings(docNoMoExclude.Settings.ChangePeptideFilter(f => f.ChangeExclusions(new List<PeptideExcludeRegex>(f.Exclusions) { new PeptideExcludeRegex("Multi-Oxidized Meth", "M\\[.*M\\[", false, true) }))); Assert.AreEqual(docMultMoExclude.PeptideCount, GetVariableModCount(docMultMoExclude)); AssertEx.IsDocumentState(docMultMoExclude, 4, 2, 18, 56); // And that removing the variable modification removes the variably modifide peptides var docYeast2 = docMoYeast.ChangeSettings(docMoYeast.Settings.ChangePeptideModifications(mods => modsDefault)); Assert.AreEqual(0, GetVariableModCount(docYeast2)); Assert.AreEqual(docYeast, docYeast2); Assert.AreNotSame(docYeast, docYeast2); // Even when automanage children is turned off var docNoAuto = (SrmDocument)docMoYeast.ChangeChildren((from node in docYeast2.MoleculeGroups select node.ChangeAutoManageChildren(false)).ToArray()); var docYeastNoAuto = docNoAuto.ChangeSettings(docYeast.Settings); Assert.AreEqual(0, GetVariableModCount(docYeastNoAuto)); // Shouldn't come back, if the mods are restored var docMoNoAuto = docYeastNoAuto.ChangeSettings(docMetOxidized.Settings); Assert.AreEqual(0, GetVariableModCount(docMoNoAuto)); Assert.AreSame(docYeastNoAuto.Children, docMoNoAuto.Children); // Make sure loss modification result in smaller m/z values var listModsLoss = new List<StaticMod>(modsDefault.StaticModifications) { VAR_ASP_WATER_LOSS }; var docAspLoss = docYeast2.ChangeSettings(docYeast2.Settings.ChangePeptideModifications(mods => mods.ChangeStaticModifications(listModsLoss.ToArray()))); Assert.AreEqual(145, GetVariableModCount(docAspLoss)); VerifyModificationOrder(docAspLoss, false); // Add multiple variable modifications listStaticMods.Add(VAR_ASP_WATER_ADD); var docVarMulti = docYeast2.ChangeSettings(docYeast2.Settings.ChangePeptideModifications(mods => mods.ChangeStaticModifications(listStaticMods.ToArray()))); Assert.AreEqual(220, GetVariableModCount(docVarMulti)); int maxModifiableMulti = GetMaxModifiableCount(docVarMulti); Assert.IsTrue(maxModifiableMulti > GetMaxModifiedCount(docVarMulti)); VerifyModificationOrder(docVarMulti, true); // Repeat with a single variable modification on multiple amino acids // and verify that this creates the same number of variably modified peptides var listModsMultiAA = new List<StaticMod>(modsDefault.StaticModifications) { VAR_MET_ASP_OXIDIZED }; var docVarMultiAA = docYeast2.ChangeSettings(docYeast2.Settings.ChangePeptideModifications(mods => mods.ChangeStaticModifications(listModsMultiAA.ToArray()))); Assert.AreEqual(220, GetVariableModCount(docVarMultiAA)); VerifyModificationOrder(docVarMultiAA, true); // And also multiple modifications on the same amino acid residue listStaticMods.Add(VAR_MET_AMONIA_ADD); var docVarAaMulti = docVarMulti.ChangeSettings(docVarMulti.Settings.ChangePeptideModifications(mods => mods.ChangeStaticModifications(listStaticMods.ToArray()))); Assert.AreEqual(315, GetVariableModCount(docVarAaMulti)); int maxModifiableAaMulti = GetMaxModifiableCount(docVarAaMulti); Assert.AreEqual(maxModifiableMulti, maxModifiableAaMulti, "Unexptected change in the maximum number of modifiable amino acids"); Assert.IsTrue(maxModifiableAaMulti > GetMaxModifiedCount(docVarAaMulti)); VerifyModificationOrder(docVarAaMulti, true); // Reduce the maximum number of variable modifications allowed var docVar2AaMulti = docVarAaMulti.ChangeSettings(docVarAaMulti.Settings.ChangePeptideModifications(mods => mods.ChangeMaxVariableMods(2))); Assert.AreEqual(242, GetVariableModCount(docVar2AaMulti)); Assert.AreEqual(2, GetMaxModifiedCount(docVar2AaMulti)); VerifyModificationOrder(docVar2AaMulti, true); var docVar1AaMulti = docVar2AaMulti.ChangeSettings(docVar2AaMulti.Settings.ChangePeptideModifications(mods => mods.ChangeMaxVariableMods(1))); Assert.AreEqual(128, GetVariableModCount(docVar1AaMulti)); Assert.AreEqual(1, GetMaxModifiedCount(docVar1AaMulti)); VerifyModificationOrder(docVar1AaMulti, true); var docVarAaMultiReset = docVar1AaMulti.ChangeSettings(docVarAaMulti.Settings); Assert.AreEqual(315, GetVariableModCount(docVarAaMultiReset)); // Repeat with auto-manage turned off to make sure it also removes // variable modifications which are made invalide by changing the limit var docMultiNoAuto = (SrmDocument)docVarAaMulti.ChangeChildren((from node in docVarAaMulti.MoleculeGroups select node.ChangeAutoManageChildren(false)).ToArray()); var docMulti2NoAuto = docMultiNoAuto.ChangeSettings(docVar2AaMulti.Settings); Assert.IsTrue(ArrayUtil.ReferencesEqual(docVar2AaMulti.Molecules.ToArray(), docMulti2NoAuto.Molecules.ToArray())); var docMulti1NoAuto = docMulti2NoAuto.ChangeSettings(docVar1AaMulti.Settings); Assert.IsTrue(ArrayUtil.ReferencesEqual(docVar1AaMulti.Molecules.ToArray(), docMulti1NoAuto.Molecules.ToArray())); var docMultiNoAutoReset = docMulti1NoAuto.ChangeSettings(docVarAaMulti.Settings); Assert.AreSame(docMulti1NoAuto.Children, docMultiNoAutoReset.Children); // Add heavy modifications to an earlier document to verify // that heavy precursors all get greater precursor m/z values than // their light versions var docVarHeavy = docVarMulti.ChangeSettings(docVarMulti.Settings.ChangePeptideModifications( mods => mods.ChangeHeavyModifications(HEAVY_MODS))); foreach (var nodePep in docVarHeavy.Peptides) { if (nodePep.Peptide.NextAA == '-') continue; Assert.AreEqual(2, nodePep.Children.Count); Assert.AreEqual(GetPrecursorMz(nodePep, 0), GetPrecursorMz(nodePep, 1)-3, 0.02); } // Repeat with a modification specifying multiple amino acids // and make sure the resulting m/z values are the same var docVarHeavyMulti = docVarMulti.ChangeSettings(docVarMulti.Settings.ChangePeptideModifications( mods => mods.ChangeHeavyModifications(HEAVY_MODS_MULTI))); var varHeavyGroups = docVarHeavy.PeptideTransitionGroups.ToArray(); var varHeavyMultiPeptides = docVarHeavyMulti.PeptideTransitionGroups.ToArray(); Assert.AreEqual(varHeavyGroups.Length, varHeavyMultiPeptides.Length); for (int i = 0; i < varHeavyGroups.Length; i++) Assert.AreEqual(varHeavyGroups[i].PrecursorMz, varHeavyMultiPeptides[i].PrecursorMz); }
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, 1), new MeasuredIon(hydrogenPeroxide, formula, null, null, 2), new MeasuredIon(hydrogenPeroxide, formula, null, null, 3), MeasuredIonList.NTERM_PROLINE }; SrmDocument docReporterIon = docPeptide.ChangeSettings(docPeptide.Settings.ChangeTransitionFilter(filter => filter.ChangeMeasuredIons(reporterIons))); AssertEx.IsDocumentTransitionCount(docReporterIon, 7); //Check With Monoisotopic double 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].CustomIon, tran.CustomIon); Assert.AreEqual(tran.Charge, i + 1); Assert.AreEqual(BioMassCalc.MONOISOTOPIC.CalculateIonMz(formula, i + 1), tranNode.Mz, BioMassCalc.MassElectron/100); Assert.AreEqual(BioMassCalc.CalculateIonMz(mass, i + 1), 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].CustomIon, tran.CustomIon); Assert.AreEqual(tran.Charge, i + 1); Assert.AreEqual(BioMassCalc.AVERAGE.CalculateIonMz(formula, i + 1), tranNode.Mz, BioMassCalc.MassElectron / 100); Assert.AreEqual(BioMassCalc.CalculateIonMz(mass, i + 1), 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,1, 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).CustomIon, 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 = TransitionGroupTreeNode.GetChoices(nodeGroup, optionalDoc.Settings, optionalDoc.Molecules.ElementAt(0).ExplicitMods, true) .Cast<TransitionDocNode>() .Where(node => Equals(node.Transition.CustomIon, optionalIon.CustomIon)); var unfilteredNodes = TransitionGroupTreeNode.GetChoices(nodeGroup, optionalDoc.Settings, optionalDoc.Molecules.ElementAt(0).ExplicitMods, false) .Cast<TransitionDocNode>() .Where(node => Equals(node.Transition.CustomIon, optionalIon.CustomIon)); Assert.AreEqual(0,filteredNodes.Count()); Assert.AreEqual(1,unfilteredNodes.Count()); }
public void MultiLabelTypeTest() { int startRev = 0; SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault().ChangeTransitionInstrument(inst => inst.ChangeMaxMz(1800))); // Add some FASTA IdentityPath pathRoot = IdentityPath.ROOT; SrmDocument docFasta = document.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST_LIB), false, pathRoot, out _); const int initProt = 2, initPep = 26, initTran = 89; AssertEx.IsDocumentState(docFasta, ++startRev, initProt, initPep, initTran); // Add multiple heavy types var settings = docFasta.Settings.ChangePeptideModifications(mods => new PeptideModifications(mods.StaticModifications, new[] { new TypedModifications(LABEL_TYPE13_C, HEAVY_MODS_13_C), new TypedModifications(LABEL_TYPE15_N, HEAVY_MODS_15_N) })); var docMulti = docFasta.ChangeSettings(settings); // Make sure the contents of the resulting document are as expected. int countProteinTermTran, countProteinTerm; VerifyMultiLabelContent(docFasta, docMulti, out countProteinTerm, out countProteinTermTran); int multiGroupCount = initPep * 3 - countProteinTerm; int multiTranCount = initTran * 3 - countProteinTermTran; AssertEx.IsDocumentState(docMulti, ++startRev, initProt, initPep, multiGroupCount, multiTranCount); // Turn off auto-manage children on all peptides var listPepGroups = new List <DocNode>(); foreach (PeptideGroupDocNode nodePepGroup in docMulti.MoleculeGroups) { var listPeptides = new List <DocNode>(); foreach (PeptideDocNode nodePep in nodePepGroup.Children) { listPeptides.Add(nodePep.ChangeAutoManageChildren(false)); } listPepGroups.Add(nodePepGroup.ChangeChildren(listPeptides)); } var docNoAuto = (SrmDocument)docMulti.ChangeChildren(listPepGroups); startRev++; // Switch back to settings without isotope labels var docNoAutoLight = docNoAuto.ChangeSettings(docFasta.Settings); // The document should return to its initial state AssertEx.IsDocumentState(docNoAutoLight, ++startRev, initProt, initPep, initTran); // Switch back to Settings with isotope labels var docNoAutoLabeled = docNoAutoLight.ChangeSettings(docMulti.Settings); // The number of nodes should not change AssertEx.IsDocumentState(docNoAutoLabeled, ++startRev, initProt, initPep, initTran); // Remove all document nodes var docEmpty = (SrmDocument)docNoAutoLabeled.ChangeChildren(new PeptideGroupDocNode[0]); // Paste FASTA back in var docRePaste = docEmpty.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST_LIB), false, pathRoot, out _); // This should produce the same document as the original settings change Assert.AreEqual(docMulti, docRePaste); }
public void ImportFastaTest() { SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault0_6()); IdentityPath path = IdentityPath.ROOT; SrmDocument docFasta = document.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST), false, path, out path); AssertEx.IsDocumentState(docFasta, 1, 2, 98, 311); Assert.AreEqual("YAL001C", ((PeptideGroupDocNode)docFasta.Children[0]).Name); Assert.AreEqual("YAL002W", ((PeptideGroupDocNode)docFasta.Children[1]).Name); Assert.AreEqual(1, path.Length); Assert.IsInstanceOfType(path.GetIdentity(0), typeof(FastaSequence)); Assert.AreEqual("YAL001C", ((FastaSequence) path.GetIdentity(0)).Name); int maxMz = docFasta.Settings.TransitionSettings.Instrument.MaxMz - 120; foreach (PeptideGroupDocNode nodeGroup in docFasta.Children) { if (SrmDocument.IsSpecialNonProteomicTestDocNode(nodeGroup)) continue; Assert.IsInstanceOfType(nodeGroup.Id, typeof(FastaSequence)); int lastEnd = docFasta.Settings.PeptideSettings.Filter.ExcludeNTermAAs - 1; foreach (PeptideDocNode nodePeptide in nodeGroup.Children) { Peptide peptide = nodePeptide.Peptide; char prev = peptide.PrevAA; if (prev != 'K' && prev != 'R') Assert.Fail("Unexpected preceding cleavage at {0}", prev); string seq = peptide.Sequence; char last = seq[seq.Length - 1]; if (last != 'K' && last != 'R' && peptide.NextAA != '-') Assert.Fail("Unexpected cleavage at {0}", last); Assert.IsNotNull(peptide.Begin); Assert.IsNotNull(peptide.End); // Make sure peptides are ordered, and not overlapping if (peptide.Begin.Value < lastEnd) Assert.Fail("Begin {0} less than last end {1}.", peptide.Begin.Value, lastEnd); lastEnd = peptide.End.Value; IList<DocNode> nodesTrans = ((DocNodeParent) nodePeptide.Children[0]).Children; int trans = nodesTrans.Count; if (trans < 3) { // Might have been cut off by the instrument limit. if ((trans == 0 && ((TransitionGroupDocNode)nodePeptide.Children[0]).PrecursorMz < maxMz) || (trans > 0 && ((TransitionDocNode)nodesTrans[0]).Mz < maxMz)) Assert.Fail("Found {0} transitions, expecting 3.", trans); } // Might have extra proline transitions else if (trans > 3 && peptide.Sequence.IndexOf('P') == -1) Assert.Fail("Found {0} transitions, expecting 3.", trans); // Make sure transitions are ordered correctly IonType lastType = IonType.a; int lastOffset = -1; foreach (TransitionDocNode nodeTran in nodesTrans) { Transition transition = nodeTran.Transition; if (lastType == transition.IonType) Assert.IsTrue(transition.CleavageOffset > lastOffset); else Assert.IsTrue(((int)transition.IonType) > ((int) lastType)); lastType = transition.IonType; lastOffset = transition.CleavageOffset; } } } // Make sure old document is unmodified. Assert.AreEqual(0, document.RevisionIndex); Assert.AreEqual(0, document.PeptideTransitionCount); // Re-paste of fasta should have no impact. // path = IdentityPath.ROOT; use null as substitute for Root SrmDocument docFasta2 = docFasta.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST), false, null, out path); // Returns the original document to avoid adding undo record in running app Assert.AreSame(docFasta, docFasta2); Assert.IsNull(path); // Discard double-insert document, and add peptides list into previous document path = IdentityPath.ROOT; SrmDocument docPeptides = docFasta.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES1), true, path, out path); AssertEx.IsDocumentState(docPeptides, 2, 3, 111, 352); Assert.AreEqual(1, path.Length); Assert.IsNotInstanceOfType(path.GetIdentity(0), typeof(FastaSequence)); Assert.AreEqual("Peptides1", ((PeptideGroupDocNode)docPeptides.FindNode(path)).Name); PeptideGroupDocNode nodePepList = (PeptideGroupDocNode) docPeptides.Children[2]; Assert.IsNotInstanceOfType(nodePepList.Id, typeof(FastaSequence)); // Make sure other two nodes are unchanged Assert.AreSame(docFasta.Children[0], docPeptides.Children[0]); Assert.AreSame(docFasta.Children[1], docPeptides.Children[1]); foreach (PeptideDocNode nodePeptide in nodePepList.Children) { if (SrmDocument.IsSpecialNonProteomicTestDocNode(nodePeptide)) continue; char prev = nodePeptide.Peptide.PrevAA; char next = nodePeptide.Peptide.NextAA; if (prev != 'X' || next != 'X') Assert.Fail("Expected amino acids X, but found {0} or {1}", prev, next); string seq = nodePeptide.Peptide.Sequence; char last = seq[seq.Length - 1]; // Just because they are tryptic peptides in the list if (last != 'K' && last != 'R' && nodePeptide.Peptide.NextAA != '-') Assert.Fail("Unexpected cleavage at {0}", last); Assert.IsNull(nodePeptide.Peptide.Begin); Assert.IsNull(nodePeptide.Peptide.End); IList<DocNode> nodesTrans = ((DocNodeParent)nodePeptide.Children[0]).Children; int trans = nodesTrans.Count; if (trans < 3) { // Might have been cut off by the instrument limit. if ((trans == 0 && ((TransitionGroupDocNode)nodePeptide.Children[0]).PrecursorMz < maxMz) || (trans > 0 && ((TransitionDocNode)nodesTrans[0]).Mz < maxMz)) Assert.Fail("Found {0} transitions, expecting 3.", trans); } // Might have extra proline transitions else if (trans > 3 && nodePeptide.Peptide.Sequence.IndexOf('P') == -1) Assert.Fail("Found {0} transitions, expecting 3.", trans); } // Make sure old documents are unmodified. AssertEx.IsDocumentState(document, 0, 0, 0, 0); AssertEx.IsDocumentState(docFasta, 1, 2, 98, 311); AssertEx.IsDocumentState(docPeptides, 2, 3, 111, 352); // Add peptides in all possible locations. // 1. Root (already done) // 1. Before another group path = docPeptides.GetPathTo(0); SrmDocument docPeptides2 = docPeptides.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES1), true, path, out path); AssertEx.IsDocumentState(docPeptides2, 3, 4, 124, 393); Assert.IsNotInstanceOfType(docPeptides2.Children[0].Id, typeof(FastaSequence)); Assert.AreEqual(docPeptides2.Children[0].Id, path.GetIdentity(0)); Assert.IsInstanceOfType(docPeptides2.Children[1].Id, typeof(FastaSequence)); // Make sure previously existing groups are unchanged Assert.AreSame(docPeptides.Children[0], docPeptides2.Children[1]); Assert.AreSame(docPeptides.Children[1], docPeptides2.Children[2]); Assert.AreSame(docPeptides.Children[2], docPeptides2.Children[3]); // 2. Inside a FASTA group path = docPeptides2.GetPathTo((int) SrmDocument.Level.Transitions, 100); SrmDocument docPeptides3 = docPeptides2.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES1), true, path, out path); AssertEx.IsDocumentState(docPeptides3, 4, 5, 137, 434); Assert.AreEqual(2, docPeptides3.FindNodeIndex(path)); // Make sure previously existing groups are unchanged Assert.AreSame(docPeptides2.Children[1], docPeptides3.Children[1]); Assert.AreSame(docPeptides2.Children[2], docPeptides3.Children[3]); // 3. To a peptide list // a. Same peptides path = docPeptides2.GetPathTo(0); docPeptides3 = docPeptides2.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES1), true, path, out path); // No longer filter repeated peptides, because they are useful for explicit modifictations. Assert.AreNotSame(docPeptides2, docPeptides3); Assert.IsNotNull(path); // b. Different paptides path = docPeptides2.GetPathTo(0); IdentityPath pathFirstPep = docPeptides3.GetPathTo((int) SrmDocument.Level.Molecules, 0); docPeptides3 = docPeptides2.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES2), true, path, out path); AssertEx.IsDocumentState(docPeptides3, 4, 4, 140, 448); Assert.AreSame(docPeptides2.Children[0].Id, docPeptides3.Children[0].Id); Assert.AreNotSame(docPeptides2.Children[0], docPeptides3.Children[0]); Assert.AreEqual("LVTDLTK", ((PeptideDocNode) docPeptides3.FindNode(path)).Peptide.Sequence); int index = docPeptides3.FindNodeIndex(path); IdentityPath pathPreceding = docPeptides3.GetPathTo(path.Depth, index - 1); Assert.AreEqual("IVGYLDEEGVLDQNR", ((PeptideDocNode)docPeptides3.FindNode(pathPreceding)).Peptide.Sequence); Assert.AreEqual(0, docPeptides3.FindNodeIndex(pathFirstPep)); // 4. At a peptide in a peptide list path = docPeptides2.GetPathTo((int) SrmDocument.Level.Molecules, 0); docPeptides3 = docPeptides2.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES2), true, path, out path); AssertEx.IsDocumentState(docPeptides3, 4, 4, 140, 448); Assert.AreSame(docPeptides2.Children[0].Id, docPeptides3.Children[0].Id); Assert.AreNotSame(docPeptides2.Children[0], docPeptides3.Children[0]); Assert.AreEqual(0, docPeptides3.FindNodeIndex(path)); Assert.AreEqual(16, docPeptides3.FindNodeIndex(pathFirstPep)); // 5. Inside a peptide in a peptide list path = docPeptides2.GetPathTo((int)SrmDocument.Level.Transitions, 0); docPeptides3 = docPeptides2.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES2), true, path, out path); AssertEx.IsDocumentState(docPeptides3, 4, 4, 140, 448); Assert.AreSame(docPeptides2.Children[0].Id, docPeptides3.Children[0].Id); Assert.AreNotSame(docPeptides2.Children[0], docPeptides3.Children[0]); Assert.AreEqual(1, docPeptides3.FindNodeIndex(path)); Assert.AreEqual(0, docPeptides3.FindNodeIndex(pathFirstPep)); }
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()); }
public void TestPaste() { ClearDefaultModifications(); _yeastDoc = new SrmDocument(SrmSettingsList.GetDefault().ChangeTransitionInstrument(instrument => instrument.ChangeMaxMz(1600))); _yeastDoc = _yeastDoc.ChangeSettings(_yeastDoc.Settings.ChangeTransitionFilter(filter => filter.ChangeMeasuredIons(new MeasuredIon[0]))); IdentityPath path; _yeastDocReadOnly = _yeastDoc = _yeastDoc.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST_LIB), false, IdentityPath.ROOT, out path); _study7DocReadOnly = _study7Doc = CreateStudy7Doc(); IdentityPath pathRoot = IdentityPath.ROOT; // Test pasting into document with same implicit modifications does not create any extra explicit modifications. var study7EmptyDoc = (SrmDocument)_study7Doc.ChangeChildren(new DocNode[0]); var study7PasteDoc = CopyPaste(_study7Doc, null, study7EmptyDoc, pathRoot); var arrayPeptides = _study7Doc.Peptides.ToArray(); var arrayPastePeptides = study7PasteDoc.Peptides.ToArray(); Assert.AreEqual(arrayPeptides.Length, arrayPastePeptides.Length); AssertEx.DocsEqual(_study7Doc, study7PasteDoc); // DocsEqual gives a more verbose failure message using XML output // Test implicit mods in source document become explicit mods in target document. ResetDocuments(); _yeastDoc = (SrmDocument)_yeastDoc.ChangeChildren(new DocNode[0]); var settings = _yeastDoc.Settings; _yeastDoc = _yeastDoc.ChangeSettings(settings.ChangePeptideModifications(mods => mods.ChangeStaticModifications(new StaticMod[0]))); _yeastDoc = CopyPaste(_study7Doc, null, _yeastDoc, pathRoot); var pepMods = _yeastDoc.Settings.PeptideSettings.Modifications; Assert.IsTrue(pepMods.StaticModifications != null); Assert.IsTrue(pepMods.HasHeavyModifications); Assert.IsFalse(pepMods.StaticModifications.Contains(mod => !mod.IsExplicit)); Assert.IsFalse(pepMods.HeavyModifications.Contains(mod => !mod.IsExplicit)); // Test explicit mods are dropped if the target document has matching implicit modifications. study7PasteDoc = CopyPaste(_yeastDoc, null, study7EmptyDoc, pathRoot); Assert.AreEqual(_study7Doc, study7PasteDoc); // Add new label type to source document. ResetDocuments(); const string labelTypeName13C = "heavy 13C"; var labelType13C = new IsotopeLabelType(labelTypeName13C, IsotopeLabelType.light.SortOrder + 1); _yeastDoc = ChangePeptideModifications(_yeastDoc, new[] { new TypedModifications(labelType13C, HEAVY_MODS_13_C) }); Assert.IsTrue(_yeastDoc.PeptideTransitionGroups.Contains(nodeGroup => Equals(nodeGroup.TransitionGroup.LabelType, labelType13C))); // Test pasting into the same document with new label type. _yeastDoc = CopyPaste(_yeastDoc, null, _yeastDoc, pathRoot); // Check all transition have correct label type references. Assert.IsFalse(_yeastDoc.PeptideTransitionGroups.Contains(nodeGroup => { IsotopeLabelType labelType = nodeGroup.TransitionGroup.LabelType; return(!ReferenceEquals(labelType, _yeastDoc.Settings.PeptideSettings.Modifications.GetModificationsByName(labelType.Name).LabelType)); })); // Check new document still serializes correctly. AssertEx.Serializable(_yeastDoc, AssertEx.DocumentCloned); // Test pasting into new document drops label types from source document that are not found in the target document. _yeastDoc = CopyPaste(_yeastDoc, null, new SrmDocument(SrmSettingsList.GetDefault()), pathRoot); Assert.IsNull(_yeastDoc.Settings.PeptideSettings.Modifications.GetModificationsByName(labelTypeName13C)); // If only specific children are selected, test that only these children get copied. ResetDocuments(); var arrayTrans = _study7Doc.PeptideTransitions.ToArray(); IList <DocNode> selNodes = new List <DocNode>(); for (int i = 0; i < arrayTrans.Length; i += 2) { selNodes.Add(arrayTrans[i]); } _study7Doc = CopyPaste(_study7Doc, selNodes, _study7Doc, pathRoot); Assert.AreEqual(arrayTrans.Length + selNodes.Count, _study7Doc.PeptideTransitionCount); // Test after pasting to a peptide list, all children have been updated to point to the correct parent. ResetDocuments(); _study7Doc = CopyPaste(_yeastDoc, new[] { _yeastDoc.Peptides.ToArray()[0] }, _study7Doc, _study7Doc.GetPathTo((int)SrmDocument.Level.MoleculeGroups, 0)); Assert.AreEqual(_yeastDoc.Peptides.ToArray()[0].Peptide, _study7Doc.Peptides.ToArray()[0].Peptide); Assert.AreEqual(_study7Doc.Peptides.ToArray()[0].Peptide, _study7Doc.PeptideTransitionGroups.ToArray()[0].TransitionGroup.Peptide); Assert.AreEqual(_study7Doc.PeptideTransitionGroups.ToArray()[0].TransitionGroup, _study7Doc.PeptideTransitions.ToArray()[0].Transition.Group); // If only specific transition are selected for a peptide, but all transition groups are included, test AutoManageChildren is true. ResetDocuments(); selNodes = new List <DocNode>(); foreach (TransitionGroupDocNode transGroup in _study7Doc.PeptideTransitionGroups) { selNodes.Add(transGroup.Children[0]); } // TODO: Fix this and make it pass // var emptyDoc = (SrmDocument)_study7Doc.ChangeChildren(new List<DocNode>()); // _study7Doc = CopyPaste(_study7Doc, selNodes, emptyDoc, pathRoot); _study7Doc = (SrmDocument)_study7Doc.ChangeChildren(new List <DocNode>()); _study7Doc = CopyPaste(_study7Doc, selNodes, _study7Doc, pathRoot); foreach (PeptideDocNode peptide in _study7Doc.Peptides) { Assert.IsTrue(peptide.AutoManageChildren); } // Test pasting in modifications with the same name as but different definition from existing modifications not allowed. ResetDocuments(); _yeastDoc = ChangePeptideModifications(_yeastDoc, new[] { new TypedModifications(IsotopeLabelType.heavy, HEAVY_C_K_DIFDEF) }); SetDefaultModifications(_study7Doc); AssertEx.ThrowsException <Exception>(() => _yeastDoc.Settings.UpdateDefaultModifications(false)); // Test variable modifications kept if target document has matching variable modifications turned on. ResetDocuments(); settings = _yeastDoc.Settings; var modsDefault = settings.PeptideSettings.Modifications; var listVariableMods = new List <StaticMod>(modsDefault.StaticModifications) { VAR_MET_OXIDIZED }; _yeastDoc = _yeastDoc.ChangeSettings(settings.ChangePeptideModifications(mods => mods.ChangeStaticModifications(listVariableMods.ToArray()))); // Make sure there is an implicitly modified peptide in the yeast document Assert.IsTrue(_yeastDoc.Peptides.Contains(nodePep => nodePep.Peptide.Sequence.Contains("C"))); Assert.IsTrue(_yeastDoc.Peptides.Contains(nodePep => nodePep.HasVariableMods)); _yeastDoc = CopyPaste(_yeastDoc, null, _yeastDoc, pathRoot); Assert.IsFalse(_yeastDoc.Peptides.Contains(nodePep => nodePep.HasExplicitMods && !nodePep.HasVariableMods)); // Otherwise the variable modifications become only explicit modifications. var yeastDocVar = _yeastDoc; _yeastDoc = _yeastDoc.ChangeSettings(_yeastDoc.Settings.ChangePeptideModifications(mods => modsDefault)); _yeastDoc = CopyPaste(yeastDocVar, null, _yeastDoc, pathRoot); Assert.IsFalse(_yeastDoc.Settings.PeptideSettings.Modifications.HasVariableModifications); Assert.IsTrue(_yeastDoc.Peptides.Contains(nodePep => nodePep.HasExplicitMods)); Assert.IsFalse(_yeastDoc.Peptides.Contains(nodePep => nodePep.HasVariableMods)); }
public void SpecialFragmentTest() { var docOriginal = new SrmDocument(SrmSettingsList.GetDefault()); IdentityPath path; var 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)); // y8 // Switch to the legacy version of the proline fragment where min length is 1 var docLegacyProline = docPeptide.ChangeSettings(docPeptide.Settings.ChangeTransitionFilter(filter => filter.ChangeMeasuredIons(new[] { MeasuredIonList.NTERM_PROLINE_LEGACY }))); Assert.AreEqual(5, docLegacyProline.PeptideTransitionCount); // Allow b-ions var docLegacyProlineB = docLegacyProline.ChangeSettings(docLegacyProline.Settings.ChangeTransitionFilter(filter => filter.ChangeIonTypes(new[] { IonType.b, IonType.y }))); Assert.AreEqual(9, docLegacyProlineB.PeptideTransitionCount); // Add C-terminal Glu and Asp to the original peptide document var docGluAsp = docPeptide.ChangeSettings(docPeptide.Settings.ChangeTransitionFilter(filter => filter.ChangeMeasuredIons(new List<MeasuredIon>(filter.MeasuredIons) { MeasuredIonList.CTERM_GLU_ASP }))); Assert.AreEqual(5, docGluAsp.PeptideTransitionCount); Assert.IsTrue(docGluAsp.PeptideTransitions.Contains(nodeTran => nodeTran.Transition.Ordinal == 3)); // y3 // Use the legacy version instead var docGluAspLegacy = docPeptide.ChangeSettings(docPeptide.Settings.ChangeTransitionFilter(filter => filter.ChangeMeasuredIons(new List<MeasuredIon>(filter.MeasuredIons) { MeasuredIonList.CTERM_GLU_ASP_LEGACY }))); Assert.AreEqual(6, docGluAspLegacy.PeptideTransitionCount); Assert.IsTrue(docGluAspLegacy.PeptideTransitions.Contains(nodeTran => nodeTran.Transition.Ordinal == 2)); // y2 // Add Proline to the C-terminal modification var docGluAspPro = docPeptide.ChangeSettings(docPeptide.Settings.ChangeTransitionFilter(filter => filter.ChangeMeasuredIons(new[] { new MeasuredIon("C-term GAP", "EDP", null, SequenceTerminus.C, 1) }))); Assert.AreEqual(8, docGluAspPro.PeptideTransitionCount); Assert.IsTrue(docGluAspPro.PeptideTransitions.Contains(nodeTran => nodeTran.Transition.Ordinal == 2 || // y2 nodeTran.Transition.Ordinal == 8)); // y8 // Restrict var docGluAspProRestrict = docPeptide.ChangeSettings(docPeptide.Settings.ChangeTransitionFilter(filter => filter.ChangeMeasuredIons(new[] { new MeasuredIon("C-term GAP", "EDP", "P", SequenceTerminus.C, 1) }))); Assert.AreEqual(6, docGluAspProRestrict.PeptideTransitionCount); Assert.IsFalse(docGluAspProRestrict.PeptideTransitions.Contains(nodeTran => nodeTran.Transition.Ordinal == 2 || // not y2 nodeTran.Transition.Ordinal == 8)); // not y8 }
public void RemoveDuplicatePeptidesTest() { // First try removals with no impact SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault0_6()); IdentityPath path; SrmDocument docFasta = document.ImportFasta(new StringReader(string.Format(TEXT_FASTA_YEAST_FRAGMENT, 1)), false, IdentityPath.ROOT, out path); AssertEx.IsDocumentState(docFasta, 1, 1, 11, 36); var refinementSettings = new RefinementSettings {RemoveDuplicatePeptides = true}; SrmDocument docFasta2 = refinementSettings.Refine(docFasta); Assert.AreSame(docFasta, docFasta2); docFasta2 = docFasta.ImportFasta(new StringReader(string.Format(TEXT_FASTA_YEAST_FRAGMENT, 2)), false, IdentityPath.ROOT, out path); // Adding same sequence twice, even with different custom names is ignored Assert.AreSame(docFasta, docFasta2); // Try a successful removal of duplicates that leaves no peptides SrmDocument docPeptides = document.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES1), true, IdentityPath.ROOT, out path); SrmDocument docPeptides2 = docPeptides.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES1), true, IdentityPath.ROOT, out path); AssertEx.IsDocumentState(docPeptides2, 2, 2, 26, 82); SrmDocument docPeptides3 = refinementSettings.Refine(docPeptides2); Assert.AreNotSame(docPeptides2, docPeptides3); AssertEx.IsDocumentState(docPeptides3, 3, 2, 0, 0); // Try again leaving a single peptide docPeptides2 = docPeptides.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES1 + "\n" + TEXT_BOVINE_SINGLE_PEPTIDE), true, IdentityPath.ROOT, out path); docPeptides3 = refinementSettings.Refine(docPeptides2); Assert.AreNotSame(docPeptides2, docPeptides3); AssertEx.IsDocumentState(docPeptides3, 3, 2, 1, 3); }
public void ImportFastaTest() { SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault0_6()); IdentityPath path = IdentityPath.ROOT; SrmDocument docFasta = document.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST), false, path, out path); AssertEx.IsDocumentState(docFasta, 1, 2, 98, 311); Assert.AreEqual("YAL001C", ((PeptideGroupDocNode)docFasta.Children[0]).Name); Assert.AreEqual("YAL002W", ((PeptideGroupDocNode)docFasta.Children[1]).Name); Assert.AreEqual(1, path.Length); Assert.IsInstanceOfType(path.GetIdentity(0), typeof(FastaSequence)); Assert.AreEqual("YAL001C", ((FastaSequence)path.GetIdentity(0)).Name); int maxMz = docFasta.Settings.TransitionSettings.Instrument.MaxMz - 120; foreach (PeptideGroupDocNode nodeGroup in docFasta.Children) { Assert.IsInstanceOfType(nodeGroup.Id, typeof(FastaSequence)); int lastEnd = docFasta.Settings.PeptideSettings.Filter.ExcludeNTermAAs - 1; foreach (PeptideDocNode nodePeptide in nodeGroup.Children) { Peptide peptide = nodePeptide.Peptide; char prev = peptide.PrevAA; if (prev != 'K' && prev != 'R') { Assert.Fail("Unexpected preceding cleavage at {0}", prev); } string seq = peptide.Sequence; char last = seq[seq.Length - 1]; if (last != 'K' && last != 'R' && peptide.NextAA != '-') { Assert.Fail("Unexpected cleavage at {0}", last); } Assert.IsNotNull(peptide.Begin); Assert.IsNotNull(peptide.End); // Make sure peptides are ordered, and not overlapping if (peptide.Begin.Value < lastEnd) { Assert.Fail("Begin {0} less than last end {1}.", peptide.Begin.Value, lastEnd); } lastEnd = peptide.End.Value; IList <DocNode> nodesTrans = ((DocNodeParent)nodePeptide.Children[0]).Children; int trans = nodesTrans.Count; if (trans < 3) { // Might have been cut off by the instrument limit. if ((trans == 0 && ((TransitionGroupDocNode)nodePeptide.Children[0]).PrecursorMz < maxMz) || (trans > 0 && ((TransitionDocNode)nodesTrans[0]).Mz < maxMz)) { Assert.Fail("Found {0} transitions, expecting 3.", trans); } } // Might have extra proline transitions else if (trans > 3 && peptide.Sequence.IndexOf('P') == -1) { Assert.Fail("Found {0} transitions, expecting 3.", trans); } // Make sure transitions are ordered correctly IonType lastType = IonType.a; int lastOffset = -1; foreach (TransitionDocNode nodeTran in nodesTrans) { Transition transition = nodeTran.Transition; if (lastType == transition.IonType) { Assert.IsTrue(transition.CleavageOffset > lastOffset); } else { Assert.IsTrue(((int)transition.IonType) > ((int)lastType)); } lastType = transition.IonType; lastOffset = transition.CleavageOffset; } } } // Make sure old document is unmodified. Assert.AreEqual(0, document.RevisionIndex); Assert.AreEqual(0, document.PeptideTransitionCount); // Re-paste of fasta should have no impact. // path = IdentityPath.ROOT; use null as substitute for Root SrmDocument docFasta2 = docFasta.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST), false, null, out path); // Returns the original document to avoid adding undo record in running app Assert.AreSame(docFasta, docFasta2); Assert.IsNull(path); // Discard double-insert document, and add peptides list into previous document path = IdentityPath.ROOT; SrmDocument docPeptides = docFasta.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES1), true, path, out path); AssertEx.IsDocumentState(docPeptides, 2, 3, 111, 352); Assert.AreEqual(1, path.Length); Assert.IsNotInstanceOfType(path.GetIdentity(0), typeof(FastaSequence)); Assert.AreEqual("Peptides1", ((PeptideGroupDocNode)docPeptides.FindNode(path)).Name); PeptideGroupDocNode nodePepList = (PeptideGroupDocNode)docPeptides.Children[2]; Assert.IsNotInstanceOfType(nodePepList.Id, typeof(FastaSequence)); // Make sure other two nodes are unchanged Assert.AreSame(docFasta.Children[0], docPeptides.Children[0]); Assert.AreSame(docFasta.Children[1], docPeptides.Children[1]); foreach (PeptideDocNode nodePeptide in nodePepList.Children) { char prev = nodePeptide.Peptide.PrevAA; char next = nodePeptide.Peptide.NextAA; if (prev != 'X' || next != 'X') { Assert.Fail("Expected amino acids X, but found {0} or {1}", prev, next); } string seq = nodePeptide.Peptide.Sequence; char last = seq[seq.Length - 1]; // Just because they are tryptic peptides in the list if (last != 'K' && last != 'R' && nodePeptide.Peptide.NextAA != '-') { Assert.Fail("Unexpected cleavage at {0}", last); } Assert.IsNull(nodePeptide.Peptide.Begin); Assert.IsNull(nodePeptide.Peptide.End); IList <DocNode> nodesTrans = ((DocNodeParent)nodePeptide.Children[0]).Children; int trans = nodesTrans.Count; if (trans < 3) { // Might have been cut off by the instrument limit. if ((trans == 0 && ((TransitionGroupDocNode)nodePeptide.Children[0]).PrecursorMz < maxMz) || (trans > 0 && ((TransitionDocNode)nodesTrans[0]).Mz < maxMz)) { Assert.Fail("Found {0} transitions, expecting 3.", trans); } } // Might have extra proline transitions else if (trans > 3 && nodePeptide.Peptide.Sequence.IndexOf('P') == -1) { Assert.Fail("Found {0} transitions, expecting 3.", trans); } } // Make sure old documents are unmodified. AssertEx.IsDocumentState(document, 0, 0, 0, 0); AssertEx.IsDocumentState(docFasta, 1, 2, 98, 311); AssertEx.IsDocumentState(docPeptides, 2, 3, 111, 352); // Add peptides in all possible locations. // 1. Root (already done) // 1. Before another group path = docPeptides.GetPathTo(0); SrmDocument docPeptides2 = docPeptides.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES1), true, path, out path); AssertEx.IsDocumentState(docPeptides2, 3, 4, 124, 393); Assert.IsNotInstanceOfType(docPeptides2.Children[0].Id, typeof(FastaSequence)); Assert.AreEqual(docPeptides2.Children[0].Id, path.GetIdentity(0)); Assert.IsInstanceOfType(docPeptides2.Children[1].Id, typeof(FastaSequence)); // Make sure previously existing groups are unchanged Assert.AreSame(docPeptides.Children[0], docPeptides2.Children[1]); Assert.AreSame(docPeptides.Children[1], docPeptides2.Children[2]); Assert.AreSame(docPeptides.Children[2], docPeptides2.Children[3]); // 2. Inside a FASTA group path = docPeptides2.GetPathTo((int)SrmDocument.Level.Transitions, 100); SrmDocument docPeptides3 = docPeptides2.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES1), true, path, out path); AssertEx.IsDocumentState(docPeptides3, 4, 5, 137, 434); Assert.AreEqual(2, docPeptides3.FindNodeIndex(path)); // Make sure previously existing groups are unchanged Assert.AreSame(docPeptides2.Children[1], docPeptides3.Children[1]); Assert.AreSame(docPeptides2.Children[2], docPeptides3.Children[3]); // 3. To a peptide list // a. Same peptides path = docPeptides2.GetPathTo(0); docPeptides3 = docPeptides2.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES1), true, path, out path); // No longer filter repeated peptides, because they are useful for explicit modifictations. Assert.AreNotSame(docPeptides2, docPeptides3); Assert.IsNotNull(path); // b. Different paptides path = docPeptides2.GetPathTo(0); IdentityPath pathFirstPep = docPeptides3.GetPathTo((int)SrmDocument.Level.Molecules, 0); docPeptides3 = docPeptides2.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES2), true, path, out path); AssertEx.IsDocumentState(docPeptides3, 4, 4, 140, 448); Assert.AreSame(docPeptides2.Children[0].Id, docPeptides3.Children[0].Id); Assert.AreNotSame(docPeptides2.Children[0], docPeptides3.Children[0]); Assert.AreEqual("LVTDLTK", ((PeptideDocNode)docPeptides3.FindNode(path)).Peptide.Sequence); int index = docPeptides3.FindNodeIndex(path); IdentityPath pathPreceding = docPeptides3.GetPathTo(path.Depth, index - 1); Assert.AreEqual("IVGYLDEEGVLDQNR", ((PeptideDocNode)docPeptides3.FindNode(pathPreceding)).Peptide.Sequence); Assert.AreEqual(0, docPeptides3.FindNodeIndex(pathFirstPep)); // 4. At a peptide in a peptide list path = docPeptides2.GetPathTo((int)SrmDocument.Level.Molecules, 0); docPeptides3 = docPeptides2.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES2), true, path, out path); AssertEx.IsDocumentState(docPeptides3, 4, 4, 140, 448); Assert.AreSame(docPeptides2.Children[0].Id, docPeptides3.Children[0].Id); Assert.AreNotSame(docPeptides2.Children[0], docPeptides3.Children[0]); Assert.AreEqual(0, docPeptides3.FindNodeIndex(path)); Assert.AreEqual(16, docPeptides3.FindNodeIndex(pathFirstPep)); // 5. Inside a peptide in a peptide list path = docPeptides2.GetPathTo((int)SrmDocument.Level.Transitions, 0); docPeptides3 = docPeptides2.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES2), true, path, out path); AssertEx.IsDocumentState(docPeptides3, 4, 4, 140, 448); Assert.AreSame(docPeptides2.Children[0].Id, docPeptides3.Children[0].Id); Assert.AreNotSame(docPeptides2.Children[0], docPeptides3.Children[0]); Assert.AreEqual(1, docPeptides3.FindNodeIndex(path)); Assert.AreEqual(0, docPeptides3.FindNodeIndex(pathFirstPep)); }
public void DynamicMinMzTest() { var revisionIndex = 1; var settings = SrmSettingsList.GetDefault().ChangeTransitionFilter(filter => filter.ChangeIonTypes(new[] { IonType.y, IonType.b }) .ChangeFragmentRangeFirstName("ion 1") .ChangeFragmentRangeLastName("last ion")); var docOriginal = new SrmDocument(settings); IdentityPath path; var docPeptides = docOriginal.ImportFasta(new StringReader(">peptides\nESTIGNSAFELLLEVAK\nTVYHAGTK"), true, IdentityPath.ROOT, out path); AssertEx.IsDocumentState(docPeptides, revisionIndex++, 1, 2, 2, 40); // Both precursors should contain 1 and 2 ions foreach (var nodeGroup in docPeptides.PeptideTransitionGroups) { Assert.IsTrue(nodeGroup.Children.Contains(node => ((TransitionDocNode)node).Transition.Ordinal == 1)); Assert.IsTrue(nodeGroup.Children.Contains(node => ((TransitionDocNode)node).Transition.Ordinal == 2)); } // Switch to using dynamic minimum for product ions settings = settings.ChangeTransitionInstrument(instrument => instrument.ChangeIsDynamicMin(true)); var docDynamicMin = docPeptides.ChangeSettings(settings); AssertEx.IsDocumentState(docDynamicMin, revisionIndex++, 1, 2, 35); var arrayNodeGroups = docDynamicMin.PeptideTransitionGroups.ToArray(); // The larger precursor should no longer have 1 or 2 ions Assert.IsFalse(arrayNodeGroups[0].Children.Contains(node => ((TransitionDocNode)node).Transition.Ordinal == 1 || ((TransitionDocNode)node).Transition.Ordinal == 2)); // But the smaller precursor should retain at least one of both Assert.IsTrue(arrayNodeGroups[1].Children.Contains(node => ((TransitionDocNode)node).Transition.Ordinal == 1)); Assert.IsTrue(arrayNodeGroups[1].Children.Contains(node => ((TransitionDocNode)node).Transition.Ordinal == 2)); // Use a minimum that is high enough to exclude the smaller precursor settings = settings.ChangeTransitionInstrument(instrument => instrument.ChangeMinMz(500)); var docHighMinDynamicMz = docDynamicMin.ChangeSettings(settings); AssertEx.IsDocumentState(docHighMinDynamicMz, revisionIndex++, 1, 2, 1, 22); // Because of the dynamic minimum for product ions, the remaining precursor should not have changed var nodeGroupHigh = docHighMinDynamicMz.PeptideTransitionGroups.ToArray()[0]; Assert.AreSame(arrayNodeGroups[0], nodeGroupHigh); // Remove dynamic minimum, and verify that product ions are removed settings = settings.ChangeTransitionInstrument(instrument => instrument.ChangeIsDynamicMin(false)); var docHighMinMz = docHighMinDynamicMz.ChangeSettings(settings); AssertEx.IsDocumentState(docHighMinMz, revisionIndex, 1, 2, 1, 17); // No library test, because it is hard to test. Many of the library // spectra are likely gathered with LTQs which apply the same dynamic // minimum to the ms/ms peaks they measure. }
public void MultiLabelTypeListTest() { TestSmallMolecules = false; // we don't expect to roundtrip export/import of transition lists for non-proteomic molecules int startRev = 0; SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault().ChangeTransitionInstrument(inst => inst.ChangeMaxMz(1800))); // Add some FASTA IdentityPath path, pathRoot = IdentityPath.ROOT; SrmDocument docFasta = document.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST_LIB), false, pathRoot, out path); const int initProt = 2, initPep = 26, initTran = 89; AssertEx.IsDocumentState(docFasta, ++startRev, initProt, initPep, initTran); // Add multiple heavy types var settings = docFasta.Settings.ChangePeptideModifications(mods => new PeptideModifications(mods.StaticModifications, new[] { new TypedModifications(LABEL_TYPE13_C, HEAVY_MODS_13_C), new TypedModifications(LABEL_TYPE15_N, HEAVY_MODS_15_N) })); var docMulti = docFasta.ChangeSettings(settings); // CONSIDER: make explicit S-Lens, cone voltage, CE etc roundtrip? // docMulti.MoleculeTransitionGroups.FirstOrDefault().ChangeExplicitValues(ExplicitTransitionGroupValues.TEST) // Make sure transition lists export to various formats and roundtrip VerifyExportRoundTrip(new ThermoMassListExporter(docMulti), docFasta); VerifyExportRoundTrip(new AbiMassListExporter(docMulti), docFasta); VerifyExportRoundTrip(new AgilentMassListExporter(docMulti), docFasta); VerifyExportRoundTrip(new WatersMassListExporter(docMulti), docFasta); }
public void MultiLabelTypeTest() { int startRev = 0; SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault().ChangeTransitionInstrument(inst => inst.ChangeMaxMz(1800))); // Add some FASTA IdentityPath path, pathRoot = IdentityPath.ROOT; SrmDocument docFasta = document.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST_LIB), false, pathRoot, out path); const int initProt = 2, initPep = 26, initTran = 89; AssertEx.IsDocumentState(docFasta, ++startRev, initProt, initPep, initTran); // Add multiple heavy types var settings = docFasta.Settings.ChangePeptideModifications(mods => new PeptideModifications(mods.StaticModifications, new[] { new TypedModifications(LABEL_TYPE13_C, HEAVY_MODS_13_C), new TypedModifications(LABEL_TYPE15_N, HEAVY_MODS_15_N) })); var docMulti = docFasta.ChangeSettings(settings); // Make sure the contents of the resulting document are as expected. int countProteinTermTran, countProteinTerm; VerifyMultiLabelContent(docFasta, docMulti, out countProteinTerm, out countProteinTermTran); int multiGroupCount = initPep*3 - countProteinTerm; int multiTranCount = initTran*3 - countProteinTermTran; AssertEx.IsDocumentState(docMulti, ++startRev, initProt, initPep, multiGroupCount, multiTranCount); // Turn off auto-manage children on all peptides var listPepGroups = new List<DocNode>(); foreach (PeptideGroupDocNode nodePepGroup in docMulti.MoleculeGroups) { var listPeptides = new List<DocNode>(); foreach (PeptideDocNode nodePep in nodePepGroup.Children) listPeptides.Add(nodePep.ChangeAutoManageChildren(false)); listPepGroups.Add(nodePepGroup.ChangeChildren(listPeptides)); } var docNoAuto = (SrmDocument) docMulti.ChangeChildren(listPepGroups); startRev++; // Switch back to settings without isotope labels var docNoAutoLight = docNoAuto.ChangeSettings(docFasta.Settings); // The document should return to its initial state AssertEx.IsDocumentState(docNoAutoLight, ++startRev, initProt, initPep, initTran); // Switch back to Settings with isotope labels var docNoAutoLabeled = docNoAutoLight.ChangeSettings(docMulti.Settings); // The number of nodes should not change AssertEx.IsDocumentState(docNoAutoLabeled, ++startRev, initProt, initPep, initTran); // Remove all document nodes var docEmpty = (SrmDocument) docNoAutoLabeled.ChangeChildren(new PeptideGroupDocNode[0]); // Paste FASTA back in var docRePaste = docEmpty.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST_LIB), false, pathRoot, out path); // This should produce the same document as the original settings change Assert.AreEqual(docMulti, docRePaste); }
private static SrmDocument CreateMixedDoc() { SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault0_6()); IdentityPath path; // Add fasta sequences SrmDocument docFasta = document.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST), false, IdentityPath.ROOT, out path); AssertEx.IsDocumentState(docFasta, 1, 2, 98, 311); // Insert peptide list at beginnning SrmDocument docMixed = docFasta.ImportFasta(new StringReader(SrmDocEditTest.TEXT_BOVINE_PEPTIDES1), true, docFasta.GetPathTo(0), out path); AssertEx.IsDocumentState(docMixed, 2, 3, 111, 352); return docMixed; }
public void MoveNodeTest() { SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault()); IdentityPath path = IdentityPath.ROOT; SrmDocument docFasta = document.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST), false, path, out path); // 1. From peptide group to root SrmDocument docMoved = docFasta.MoveNode(docFasta.GetPathTo(0), IdentityPath.ROOT, out path); Assert.AreEqual(1, docMoved.FindNodeIndex(path)); Assert.AreSame(docFasta.Children[0], docMoved.Children[1]); Assert.AreSame(docFasta.Children[1], docMoved.Children[0]); // 2. From peptide group to before other peptide group docMoved = docFasta.MoveNode(docFasta.GetPathTo(1), docFasta.GetPathTo(0), out path); Assert.AreEqual(0, docMoved.FindNodeIndex(path)); Assert.AreSame(docFasta.Children[0], docMoved.Children[1]); Assert.AreSame(docFasta.Children[1], docMoved.Children[0]); // Some peptide lists IdentityPath pathPeptides; SrmDocument docPeptides = docFasta.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES2), true, docFasta.GetPathTo(1), out pathPeptides); docPeptides = docPeptides.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES1), true, IdentityPath.ROOT, out path); docPeptides = docPeptides.MoveNode(path, pathPeptides, out pathPeptides); Assert.AreEqual(1, docPeptides.FindNodeIndex(pathPeptides)); // 3. Peptide from one group to another IdentityPath fromParent = docPeptides.GetPathTo(2); IdentityPath from = new IdentityPath(fromParent, ((DocNodeParent)docPeptides.FindNode(fromParent)).Children[0].Id); SrmDocument docPeptides2 = docPeptides.MoveNode(from, pathPeptides, out path); Assert.AreEqual(pathPeptides, path.Parent); Assert.AreEqual(((DocNodeParent)docPeptides.Children[1]).Children.Count, ((DocNodeParent)docPeptides2.Children[1]).Children.Count - 1); Assert.AreEqual(((DocNodeParent)docPeptides.Children[2]).Children.Count, ((DocNodeParent)docPeptides2.Children[2]).Children.Count + 1); // Though moved to a different group, this should not have changed the overall // peptide order, since it was moved from the beginning of one group to the end // of the group before it. Assert.AreEqual(docPeptides.FindNodeIndex(from), docPeptides2.FindNodeIndex(path)); // 4. To before another peptide from = new IdentityPath(fromParent, ((DocNodeParent)docPeptides2.FindNode(fromParent)).Children[0].Id); IdentityPath path2; SrmDocument docPeptides3 = docPeptides2.MoveNode(from, path, out path2); Assert.AreEqual(pathPeptides, path.Parent); Assert.AreEqual(((DocNodeParent)docPeptides2.Children[1]).Children.Count, ((DocNodeParent)docPeptides3.Children[1]).Children.Count - 1); Assert.AreEqual(((DocNodeParent)docPeptides2.Children[2]).Children.Count, ((DocNodeParent)docPeptides3.Children[2]).Children.Count + 1); // Relative to all peptides, index should be 1 less than before Assert.AreEqual(docPeptides2.FindNodeIndex(from), docPeptides3.FindNodeIndex(path2) + 1); // 5. To within another peptide IdentityPath to = new IdentityPath(path, ((DocNodeParent)docPeptides3.FindNode(path)).Children[0].Id); SrmDocument docPeptides4 = docPeptides3.MoveNode(path2, to, out path); // Should not have changed to count in the group Assert.AreEqual(((DocNodeParent)docPeptides3.Children[1]).Children.Count, ((DocNodeParent)docPeptides4.Children[1]).Children.Count); // Relative to all peptides, should have been returned to original order Assert.AreEqual(docPeptides2.FindNodeIndex(from), docPeptides4.FindNodeIndex(path)); // Make sure expected exceptions are thrown Assert.IsNull(docPeptides4.FindNode(from)); AssertEx.ThrowsException<IdentityNotFoundException>(() => docPeptides4.MoveNode(from, to, out path)); AssertEx.ThrowsException<InvalidOperationException>(() => docPeptides2.MoveNode(from, docPeptides2.GetPathTo(0), out path)); AssertEx.ThrowsException<InvalidOperationException>(() => docPeptides3.MoveNode(docPeptides2.GetPathTo((int) SrmDocument.Level.Molecules, 0), to, out path)); AssertEx.ThrowsException<InvalidOperationException>(() => docPeptides3.MoveNode(docPeptides2.GetPathTo((int)SrmDocument.Level.Transitions, 0), to, out path)); }