コード例 #1
0
ファイル: LibrarySettingsTest.cs プロジェクト: rfellers/pwiz
        public void LibraryNoIonsTest()
        {
            var streamManager = new MemoryStreamManager();
            var loader        = new LibraryLoadTest.TestLibraryLoader {
                StreamManager = streamManager
            };

            // Create X! Hunter library with 20 lowest intensity peaks in NIST library
            LibraryLoadTest.CreateHunterFile(streamManager, loader, LibraryLoadTest.TEXT_LIB_YEAST_NIST, true);

            var hunterSpec = new XHunterLibSpec("Yeast (X!)", LibraryLoadTest.PATH_HUNTER_LIB);

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

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

            SrmSettings settings = SrmSettingsList.GetDefault();

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

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

            // Peptides should have been chosen, but no transitions, since the spectra are garbage
            AssertEx.IsDocumentState(docLoaded, startRev, 2, 4, 0);
        }
コード例 #2
0
        public void TestLibraryRankedSpectrumInfoSpeed()
        {
            var         testFilesDir = new TestFilesDir(TestContext, @"Test\LibraryRankedSpectrumInfoSpeedTest.zip");
            SrmDocument srmDocument;

            using (var stream = File.OpenRead(testFilesDir.GetTestPath("LibraryRankedSpectrumInfoSpeedTest.sky")))
            {
                srmDocument = (SrmDocument) new XmlSerializer(typeof(SrmDocument)).Deserialize(stream);
            }

            var unloadedLibrary = srmDocument.Settings.PeptideSettings.Libraries.Libraries.FirstOrDefault();

            Assert.IsNotNull(unloadedLibrary);
            var streamManager = new MemoryStreamManager();
            var loader        = new LibraryLoadTest.TestLibraryLoader {
                StreamManager = streamManager
            };
            var librarySpec = unloadedLibrary.CreateSpec(testFilesDir.GetTestPath("LibraryRankedSpectrumInfoSpeedTest.blib"));
            var library     = librarySpec.LoadLibrary(loader);

            Assert.IsTrue(library.IsLoaded);
            var peptideLibraries = srmDocument.Settings.PeptideSettings.Libraries.ChangeLibraries(new[] { library });

            var settingsWithLibraries =
                srmDocument.Settings.ChangePeptideSettings(
                    srmDocument.Settings.PeptideSettings.ChangeLibraries(peptideLibraries));

            // List of peptides to test with: <peptide sequence, description, expected # of matched ions, expected ranked ions>
            Tuple <string, string, int, double[]>[] testPeptides = new[]
            {
                // ReSharper disable StringLiteralTypo
                Tuple.Create("MEIVK", "Short Peptide",
                             20, new[] { 131.1, 147.1, 187.1 }),
                Tuple.Create("EIYYTPDPSELAAKEEPAKEEAPAPTPAASAPAPAAAAPAPVAAAAPAAAAAEIADEPVK", "Long Peptide",
                             55, new[] { 587.4, 771.4, 900.5 }),
                Tuple.Create("LVGFT[+80]FR", "Short Peptide with 1 Neutral Loss",
                             24, new[] { 305.1334, 322.0948, 325.2004 }),
                Tuple.Create("DLKEILSGFHNAGPVAGAGAASGAAAAGGDAAAEEEKEEEAAEES[+80]DDDMGFGLFD",
                             "Long peptide with 1 Neutral Loss",
                             43, new[] { 790.1161, 825.5901, 889.6103 }),
                Tuple.Create("MLPTS[+80]VS[+80]R", "Short peptide with 2 neutral losses",
                             36, new[] { 305.6439, 340.5001, 343.2071 }),
                Tuple.Create("RNPDFEDDDFLGGDFDEDEIDEESS[+80]EEEEEEKT[+80]QKK", "Long peptide with 2 neutral losses",
                             65, new[] { 483.2214, 552.9168, 626.2743 })
                // ReSharper restore StringLiteralTypo
            };

            Console.Out.WriteLine();
            foreach (var tuple in testPeptides)
            {
                var peptideDocNode = srmDocument.Molecules.FirstOrDefault(pep => pep.ModifiedSequenceDisplay == tuple.Item1);
                Assert.IsNotNull(peptideDocNode, "Could not find peptide {0}", tuple.Item1);
                var transitionGroup = peptideDocNode.TransitionGroups.FirstOrDefault();
                Assert.IsNotNull(transitionGroup);
                var spectrum = library
                               .GetSpectra(new LibKey(peptideDocNode.ModifiedTarget, transitionGroup.PrecursorAdduct),
                                           transitionGroup.LabelType, LibraryRedundancy.all).FirstOrDefault();
                Assert.IsNotNull(spectrum);

                var startTime = DateTime.UtcNow;
                LibraryRankedSpectrumInfo libraryRankedSpectrum = null;
                int repeatCount = 50;
                for (int i = 0; i < repeatCount; i++)
                {
                    libraryRankedSpectrum = LibraryRankedSpectrumInfo.NewLibraryRankedSpectrumInfo(spectrum.SpectrumPeaksInfo,
                                                                                                   transitionGroup.LabelType, transitionGroup, settingsWithLibraries, peptideDocNode.ExplicitMods,
                                                                                                   false, TransitionGroup.MAX_MATCHED_MSMS_PEAKS);
                    Assert.IsNotNull(libraryRankedSpectrum);
                }
                var endTime = DateTime.UtcNow;

                Console.Out.WriteLine("Time to get LibraryRankedSpectrumInfo for {0} {1} times: {2}", tuple.Item2, repeatCount, endTime.Subtract(startTime));
                Assert.IsNotNull(libraryRankedSpectrum);
                var rankedMzs = libraryRankedSpectrum.PeaksRanked.Select(peak => Math.Round(peak.ObservedMz, 4)).Take(3).ToArray();
                Console.Out.WriteLine("{0} matched peaks. First {1}/{2} ranked peaks: {{ {3} }}",
                                      libraryRankedSpectrum.PeaksMatched.Count(), rankedMzs.Length,
                                      libraryRankedSpectrum.PeaksRanked.Count(), string.Join(",", rankedMzs));
                if (!IsRecording)
                {
                    CollectionAssert.AreEqual(tuple.Item4, rankedMzs);
                    Assert.AreEqual(tuple.Item3, libraryRankedSpectrum.PeaksMatched.Count());
                }
            }
        }
コード例 #3
0
ファイル: LibrarySettingsTest.cs プロジェクト: rfellers/pwiz
        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));
        }