Esempio n. 1
0
        private SrmDocument RemoveTransitions(SrmDocument document, params int[] indexes)
        {
            foreach (var i in indexes)
            {
                var pathToTran = document.GetPathTo((int)SrmDocument.Level.Transitions, i - 1);  // Numbers are from the 1-based status bar
                document = (SrmDocument)document.RemoveChild(pathToTran.Parent, document.FindNode(pathToTran));
            }

            return(document);
        }
        private void PerformTestMeasuredDriftValues(bool asSmallMolecules)
        {
            if (asSmallMolecules)
            {
                if (!RunSmallMoleculeTestVersions)
                {
                    Console.Write(MSG_SKIPPING_SMALLMOLECULE_TEST_VERSION);
                    return;
                }
                TestSmallMolecules = false;                                                          // No need to add the magic small molecule test node
            }
            var testFilesDir = new TestFilesDir(TestContext, @"Test\Results\BlibDriftTimeTest.zip"); // Re-used from BlibDriftTimeTest
            // Open document with some peptides but no results
            var docPath = testFilesDir.GetTestPath("BlibDriftTimeTest.sky");
            // This was a malformed document, which caused problems after a fix to not recalculate
            // document library settings on open. To avoid rewriting this test for the document
            // which now contains 2 precursors, the first precursor is removed immediately.
            SrmDocument docOriginal      = ResultsUtil.DeserializeDocument(docPath);
            var         pathFirstPeptide = docOriginal.GetPathTo((int)SrmDocument.Level.Molecules, 0);
            var         nodeFirstPeptide = (DocNodeParent)docOriginal.FindNode(pathFirstPeptide);

            docOriginal = (SrmDocument)docOriginal.RemoveChild(pathFirstPeptide, nodeFirstPeptide.Children[0]);
            if (asSmallMolecules)
            {
                var refine = new RefinementSettings();
                docOriginal = refine.ConvertToSmallMolecules(docOriginal, testFilesDir.FullPath);
            }
            using (var docContainer = new ResultsTestDocumentContainer(docOriginal, docPath))
            {
                var doc = docContainer.Document;

                // Import an mz5 file that contains drift info
                const string replicateName = "ID12692_01_UCA168_3727_040714";
                var          chromSets     = new[]
                {
                    new ChromatogramSet(replicateName, new[]
                                        { new MsDataFilePath(testFilesDir.GetTestPath("ID12692_01_UCA168_3727_040714" + ExtensionTestContext.ExtMz5)), }),
                };
                var docResults = doc.ChangeMeasuredResults(new MeasuredResults(chromSets));
                Assert.IsTrue(docContainer.SetDocument(docResults, docOriginal, true));
                docContainer.AssertComplete();
                var document = docContainer.Document;
                document = document.ChangeSettings(document.Settings.ChangePeptidePrediction(prediction => new PeptidePrediction(null, IonMobilityPredictor.EMPTY)));

                // Verify ability to extract predictions from raw data
                var newPred = document.Settings.PeptideSettings.Prediction.IonMobilityPredictor.ChangeMeasuredIonMobilityValuesFromResults(
                    document, docContainer.DocumentFilePath);
                var result = newPred.MeasuredMobilityIons;
                Assert.AreEqual(TestSmallMolecules ? 2 : 1, result.Count);
                const double expectedDT     = 4.0019;
                var          expectedOffset = .4829;
                Assert.AreEqual(expectedDT, result.Values.First().IonMobility.Mobility.Value, .001);
                Assert.AreEqual(expectedOffset, result.Values.First().HighEnergyIonMobilityValueOffset, .001);

                // Check ability to update, and to preserve unchanged
                var revised = new Dictionary <LibKey, IonMobilityAndCCS>();
                var libKey  = result.Keys.First();
                revised.Add(libKey, IonMobilityAndCCS.GetIonMobilityAndCCS(IonMobilityValue.GetIonMobilityValue(4, eIonMobilityUnits.drift_time_msec), null, 0.234));  // N.B. CCS handling would require actual raw data in this test, it's covered in a perf test
                var libKey2 = new LibKey("DEADEELS", asSmallMolecules ? Adduct.NonProteomicProtonatedFromCharge(2) : Adduct.DOUBLY_PROTONATED);
                revised.Add(libKey2, IonMobilityAndCCS.GetIonMobilityAndCCS(IonMobilityValue.GetIonMobilityValue(5, eIonMobilityUnits.drift_time_msec), null, 0.123));
                document =
                    document.ChangeSettings(
                        document.Settings.ChangePeptidePrediction(prediction => new PeptidePrediction(null, new IonMobilityPredictor("test", revised, null, null, IonMobilityWindowWidthCalculator.IonMobilityPeakWidthType.resolving_power, 40, 0, 0))));
                newPred = document.Settings.PeptideSettings.Prediction.ChangeDriftTimePredictor(
                    document.Settings.PeptideSettings.Prediction.IonMobilityPredictor.ChangeMeasuredIonMobilityValuesFromResults(
                        document, docContainer.DocumentFilePath)).IonMobilityPredictor;
                result = newPred.MeasuredMobilityIons;
                Assert.AreEqual(TestSmallMolecules ? 3 : 2, result.Count);
                Assert.AreEqual(expectedDT, result[libKey].IonMobility.Mobility.Value, .001);
                Assert.AreEqual(expectedOffset, result[libKey].HighEnergyIonMobilityValueOffset, .001);
                Assert.AreEqual(5, result[libKey2].IonMobility.Mobility.Value, .001);
                Assert.AreEqual(0.123, result[libKey2].HighEnergyIonMobilityValueOffset, .001);
            }
        }
Esempio n. 3
0
        public void LibraryMultipleTest()
        {
            var streamManager = new MemoryStreamManager();
            var loader        = new LibraryLoadTest.TestLibraryLoader {
                StreamManager = streamManager
            };

            // Create library files
            const string hunterText = LibraryLoadTest.TEXT_LIB_YEAST_NIST1 + "\n" + LibraryLoadTest.TEXT_LIB_YEAST_NIST2;

            LibraryLoadTest.CreateHunterFile(streamManager, loader, hunterText);
            const string biblioText = LibraryLoadTest.TEXT_LIB_YEAST_NIST2 + "\n" + LibraryLoadTest.TEXT_LIB_YEAST_NIST3;

            LibraryLoadTest.CreateBiblioFile(streamManager, loader, biblioText);
            const string nistText = LibraryLoadTest.TEXT_LIB_YEAST_NIST3 + "\n" + LibraryLoadTest.TEXT_LIB_YEAST_NIST4;

            streamManager.TextFiles.Add(LibraryLoadTest.PATH_NIST_LIB, nistText);

            var hunterSpec = new XHunterLibSpec("Yeast (X!)", LibraryLoadTest.PATH_HUNTER_LIB);
            var bilbioSpec = new BiblioSpecLibSpec("Yeast (BS)", LibraryLoadTest.PATH_BIBLIOSPEC_LIB);
            var nistSpec   = new NistLibSpec("Yeast (NIST)", LibraryLoadTest.PATH_NIST_LIB);

            // For serialization, add the library spec to the settings
            TestLibraryList = new SpectralLibraryList {
                hunterSpec, bilbioSpec, nistSpec
            };

            var libraryManager = new LibraryManager {
                StreamManager = streamManager
            };
            var docContainer = new TestDocumentContainer();

            SrmSettings settings = SrmSettingsList.GetDefault();

            settings = settings.ChangePeptideLibraries(l => l.ChangeLibrarySpecs(new LibrarySpec[] { hunterSpec, bilbioSpec, nistSpec }));

            int         startRev;
            SrmDocument docLoaded = CreateLibraryDocument(settings, ExampleText.TEXT_FASTA_YEAST_LIB, false,
                                                          docContainer, libraryManager, out startRev);

            AssertEx.IsDocumentState(docLoaded, startRev, 2, 4, 12);
            Assert.IsTrue(HasLibraryInfo(docLoaded, typeof(XHunterSpectrumHeaderInfo)));
            Assert.IsTrue(HasLibraryInfo(docLoaded, typeof(BiblioSpecSpectrumHeaderInfo)));
            Assert.IsTrue(HasLibraryInfo(docLoaded, typeof(NistSpectrumHeaderInfo)));

            // Remove the rank 1 transition from each transition group
            TransitionDocNode[] transitionNodes = docLoaded.PeptideTransitions.ToArray();
            for (int i = 0; i < transitionNodes.Length; i++)
            {
                var nodeTran = transitionNodes[i];
                if (nodeTran.LibInfo.Rank != 1)
                {
                    continue;
                }
                var path = docLoaded.GetPathTo((int)SrmDocument.Level.TransitionGroups, i / 3);
                docLoaded = (SrmDocument)docLoaded.RemoveChild(path, nodeTran);
                ++startRev;
            }
            AssertEx.IsDocumentState(docLoaded, startRev, 2, 4, 8);
            // Make sure this can be serialized and deserialized without causing
            // a recalculation of the nodes in the tree.
            AssertEx.Serializable(docLoaded, (doc1, doc2) => ValidateLibraryDocs(doc1, doc2, libraryManager));
        }
Esempio n. 4
0
        private void PerformTestMeasuredDriftValues(bool asSmallMolecules)
        {
            if (asSmallMolecules)
            {
                if (!RunSmallMoleculeTestVersions)
                {
                    Console.Write(MSG_SKIPPING_SMALLMOLECULE_TEST_VERSION);
                    return;
                }
            }
            var testFilesDir = new TestFilesDir(TestContext, @"TestData\Results\BlibDriftTimeTest.zip"); // Re-used from BlibDriftTimeTest
            // Open document with some peptides but no results
            var docPath = testFilesDir.GetTestPath("BlibDriftTimeTest.sky");
            // This was a malformed document, which caused problems after a fix to not recalculate
            // document library settings on open. To avoid rewriting this test for the document
            // which now contains 2 precursors, the first precursor is removed immediately.
            SrmDocument docOriginal      = ResultsUtil.DeserializeDocument(docPath);
            var         pathFirstPeptide = docOriginal.GetPathTo((int)SrmDocument.Level.Molecules, 0);
            var         nodeFirstPeptide = (DocNodeParent)docOriginal.FindNode(pathFirstPeptide);

            docOriginal = (SrmDocument)docOriginal.RemoveChild(pathFirstPeptide, nodeFirstPeptide.Children[0]);
            if (asSmallMolecules)
            {
                var refine = new RefinementSettings();
                docOriginal = refine.ConvertToSmallMolecules(docOriginal, testFilesDir.FullPath);
            }
            using (var docContainer = new ResultsTestDocumentContainer(docOriginal, docPath))
            {
                var doc = docContainer.Document;

                // Import an mz5 file that contains drift info
                const string replicateName = "ID12692_01_UCA168_3727_040714";
                var          chromSets     = new[]
                {
                    new ChromatogramSet(replicateName, new[]
                                        { new MsDataFilePath(testFilesDir.GetTestPath("ID12692_01_UCA168_3727_040714" + ExtensionTestContext.ExtMz5)), }),
                };
                var docResults = doc.ChangeMeasuredResults(new MeasuredResults(chromSets));
                Assert.IsTrue(docContainer.SetDocument(docResults, docOriginal, true));
                docContainer.AssertComplete();
                var document = docContainer.Document;

                // Clear out any current settings
                document = document.ChangeSettings(document.Settings.ChangeTransitionIonMobilityFiltering(s => TransitionIonMobilityFiltering.EMPTY));

                // Verify ability to extract predictions from raw data
                var libraryName0   = "test0";
                var dbPath0        = testFilesDir.GetTestPath(libraryName0 + IonMobilityDb.EXT);
                var newIMFiltering = document.Settings.TransitionSettings.IonMobilityFiltering.ChangeLibrary(
                    IonMobilityLibrary.CreateFromResults(
                        document, docContainer.DocumentFilePath, true,
                        libraryName0, dbPath0));
                var result = newIMFiltering.IonMobilityLibrary.GetIonMobilityLibKeyMap().AsDictionary();
                Assert.AreEqual(1, result.Count);
                var expectedDT     = 4.0019;
                var expectedOffset = .4829;
                Assert.AreEqual(expectedDT, result.Values.First().First().IonMobility.Mobility.Value, .001);
                Assert.AreEqual(expectedOffset, result.Values.First().First().HighEnergyIonMobilityValueOffset ?? 0, .001);

                // Check ability to update, and to preserve unchanged
                var revised = new List <PrecursorIonMobilities>();
                var libKey  = result.Keys.First();
                revised.Add(new PrecursorIonMobilities(libKey, IonMobilityAndCCS.GetIonMobilityAndCCS(IonMobilityValue.GetIonMobilityValue(expectedDT = 4, eIonMobilityUnits.drift_time_msec), null, expectedOffset = 0.234)));  // N.B. CCS handling would require actual raw data in this test, it's covered in a perf test
                var pepSequence = "DEADEELS";
                var libKey2     = asSmallMolecules ?
                                  new LibKey(SmallMoleculeLibraryAttributes.Create(pepSequence, "C12H5", null, null, null, null), Adduct.M_PLUS_2H) :
                                  new LibKey(pepSequence, Adduct.DOUBLY_PROTONATED);
                revised.Add(new PrecursorIonMobilities(libKey2, IonMobilityAndCCS.GetIonMobilityAndCCS(IonMobilityValue.GetIonMobilityValue(5, eIonMobilityUnits.drift_time_msec), null, 0.123)));
                var libraryName = "test";
                var dbPath      = testFilesDir.GetTestPath(libraryName + IonMobilityDb.EXT);
                var imsdb       = IonMobilityDb.CreateIonMobilityDb(dbPath, libraryName, false, revised);
                var newLibIM    = new IonMobilityLibrary(libraryName, dbPath, imsdb);
                var ionMobilityWindowWidthCalculator = new IonMobilityWindowWidthCalculator(
                    IonMobilityWindowWidthCalculator.IonMobilityWindowWidthType.resolving_power, 40, 0, 0, 0);
                var calculator = ionMobilityWindowWidthCalculator;
                document = document.ChangeSettings(
                    document.Settings.ChangeTransitionIonMobilityFiltering(
                        imf => imf.ChangeFilterWindowWidthCalculator(calculator).
                        ChangeLibrary(newLibIM)));
                result = document.Settings.TransitionSettings.IonMobilityFiltering.IonMobilityLibrary.GetIonMobilityLibKeyMap().AsDictionary();
                Assert.AreEqual(2, result.Count);
                Assert.AreEqual(expectedDT, result[libKey].First().IonMobility.Mobility.Value, .001);
                Assert.AreEqual(expectedOffset, result[libKey].First().HighEnergyIonMobilityValueOffset ?? 0, .001);
                Assert.AreEqual(5, result[libKey2].First().IonMobility.Mobility.Value, .001);
                Assert.AreEqual(0.123, result[libKey2].First().HighEnergyIonMobilityValueOffset ?? 0, .001);

                ionMobilityWindowWidthCalculator = new IonMobilityWindowWidthCalculator(
                    IonMobilityWindowWidthCalculator.IonMobilityWindowWidthType.fixed_width, 40, 0, 0, 100);
                document = document.ChangeSettings(
                    document.Settings.ChangeTransitionIonMobilityFiltering(
                        imf => imf.ChangeFilterWindowWidthCalculator(ionMobilityWindowWidthCalculator).
                        ChangeLibrary(newLibIM)));
                result = document.Settings.TransitionSettings.IonMobilityFiltering.IonMobilityLibrary.GetIonMobilityLibKeyMap().AsDictionary();
                Assert.AreEqual(2, result.Count);
                Assert.AreEqual(expectedDT, result[libKey].First().IonMobility.Mobility.Value, .001);
                Assert.AreEqual(expectedOffset, result[libKey].First().HighEnergyIonMobilityValueOffset ?? 0, .001);
                Assert.AreEqual(5, result[libKey2].First().IonMobility.Mobility.Value, .001);
                Assert.AreEqual(0.123, result[libKey2].First().HighEnergyIonMobilityValueOffset ?? 0, .001);
            }
        }
Esempio n. 5
0
        public void RunTestFindNode(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules)
        {
            if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none)
            {
                TestDirectoryName = asSmallMolecules.ToString();
            }
            TestSmallMolecules = false;  // Don't need the magic test node, we have an explicit test

            SrmDocument doc = CreateStudy7Doc();

            doc = (new RefinementSettings()).ConvertToSmallMolecules(doc, asSmallMolecules);
            var displaySettings = new DisplaySettings(null, false, 0, 0); //, ProteinDisplayMode.ByName);
            // Find every other transition, searching down.
            List <TransitionDocNode> listTransitions = doc.MoleculeTransitions.ToList();
            var pathFound = doc.GetPathTo(0, 0);
            int i;

            for (i = 0; i < doc.MoleculeTransitionCount; i += 2)
            {
                pathFound = doc.SearchDocumentForString(pathFound, String.Format("{0:F04}", listTransitions[i].Mz), displaySettings, false, false);
                Assert.AreEqual(doc.GetPathTo((int)SrmDocument.Level.Transitions, i), pathFound);
            }

            // Test wrapping in search down.
            pathFound = doc.SearchDocumentForString(pathFound, String.Format("{0:F04}", listTransitions[0].Mz), displaySettings, false, false);
            Assert.AreEqual(doc.GetPathTo((int)SrmDocument.Level.Transitions, 0), pathFound);

            // Find every other peptide searching up while for each finding one of its children searching down.
            pathFound = doc.LastNodePath;
            List <PeptideDocNode> listPeptides = new List <PeptideDocNode>();

            listPeptides.AddRange(doc.Molecules);
            List <TransitionGroupDocNode> listTransitionGroups = new List <TransitionGroupDocNode>();

            listTransitionGroups.AddRange(doc.MoleculeTransitionGroups);
            for (int x = doc.MoleculeCount; x > 0; x -= 2)
            {
                // Test case insensitivity.
                pathFound = doc.SearchDocumentForString(pathFound, listPeptides[x - 1].ToString().ToLower(), displaySettings, true, false);
                Assert.AreEqual(doc.GetPathTo((int)SrmDocument.Level.Molecules, x - 1), pathFound);
                // Test parents can find children.
                pathFound = doc.SearchDocumentForString(pathFound, String.Format("{0:F04}", listTransitionGroups[x * 2 - 1].PrecursorMz.Value), displaySettings,
                                                        false, true);
                Assert.AreEqual(doc.GetPathTo((int)SrmDocument.Level.TransitionGroups, x * 2 - 1), pathFound);
                // Test Children can find parents.
                pathFound = doc.SearchDocumentForString(pathFound, listPeptides[x - 1].ToString().ToLower(), displaySettings, true, false);
                Assert.AreEqual(doc.GetPathTo((int)SrmDocument.Level.Molecules, x - 1), pathFound);
            }

            // Test wrapping in search up.
            pathFound = doc.SearchDocumentForString(pathFound, String.Format("{0:F04}", listTransitionGroups[listTransitionGroups.Count - 1].PrecursorMz.Value),
                                                    displaySettings, false, true);
            Assert.AreEqual(doc.GetPathTo((int)SrmDocument.Level.TransitionGroups, listTransitionGroups.Count - 1), pathFound);

            // Test children can find other parents.
            pathFound = doc.SearchDocumentForString(pathFound, listPeptides[0].ToString().ToLowerInvariant(), displaySettings, true, false);
            Assert.AreEqual(doc.GetPathTo((int)SrmDocument.Level.Molecules, 0), pathFound);

            // Test forward and backward searching in succession
            const string heavyText         = "heavy";
            int          countHeavyForward = CountOccurrances(doc, heavyText, displaySettings, false, true);

            Assert.IsTrue(countHeavyForward > 0);
            Assert.AreEqual(countHeavyForward, CountOccurrances(doc, heavyText, displaySettings, true, true));
            // More tests of case insensitive searching
            Assert.AreEqual(0, CountOccurrances(doc, heavyText.ToUpperInvariant(), displaySettings, false, true));
            Assert.AreEqual(countHeavyForward, CountOccurrances(doc, heavyText.ToUpperInvariant(), displaySettings, false, false));
            if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.masses_only)
            {
                Assert.AreEqual(1, CountOccurrances(doc, "hgflpr", displaySettings, true, false));
            }

            // Test mismatched transitions finder
            var missmatchFinder = new FindOptions().ChangeCustomFinders(new[] { new MismatchedIsotopeTransitionsFinder() });

            Assert.AreEqual(4, CountOccurrances(doc, missmatchFinder, displaySettings));
            var docRemoved = (SrmDocument)doc.RemoveChild(doc.Children[1]).RemoveChild(doc.Children[2]);

            Assert.AreEqual(0, CountOccurrances(docRemoved, missmatchFinder, displaySettings));
            var refineRemoveHeavy = new RefinementSettings {
                RefineLabelType = IsotopeLabelType.heavy
            };
            var docLight = refineRemoveHeavy.Refine(doc);

            Assert.AreEqual(0, CountOccurrances(docLight, missmatchFinder, displaySettings));
            var refineRemoveLight = new RefinementSettings {
                RefineLabelType = IsotopeLabelType.light
            };
            var docHeavy = refineRemoveLight.Refine(doc);

            Assert.AreEqual(0, CountOccurrances(docHeavy, missmatchFinder, displaySettings));
            var docMulti = ResultsUtil.DeserializeDocument("MultiLabel.sky", typeof(MultiLabelRatioTest));

            docMulti = (new RefinementSettings()).ConvertToSmallMolecules(docMulti, asSmallMolecules);
            Assert.AreEqual(0, CountOccurrances(docMulti, missmatchFinder, displaySettings));
            var pathTranMultiRemove = docMulti.GetPathTo((int)SrmDocument.Level.Transitions, 7);
            var tranMultiRemove     = docMulti.FindNode(pathTranMultiRemove);
            var docMultiRemoved     = (SrmDocument)docMulti.RemoveChild(pathTranMultiRemove.Parent, tranMultiRemove);

            Assert.AreEqual(2, CountOccurrances(docMultiRemoved, missmatchFinder, displaySettings));
            var tranGroupMultiRemove = docMulti.FindNode(pathTranMultiRemove.Parent);
            var docMultiGroupRemoved = (SrmDocument)
                                       docMulti.RemoveChild(pathTranMultiRemove.Parent.Parent, tranGroupMultiRemove);

            Assert.AreEqual(0, CountOccurrances(docMultiGroupRemoved, missmatchFinder, displaySettings));
        }