示例#1
0
        private void DoTestImportSim(bool asSmallMolecules)
        {
            if (asSmallMolecules && !RunSmallMoleculeTestVersions)
            {
                System.Console.Write(MSG_SKIPPING_SMALLMOLECULE_TEST_VERSION);
                return;
            }

            var    testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);
            string docPath      = testFilesDir.GetTestPath(DOCUMENT_NAME);
            string cachePath    = ChromatogramCache.FinalPathForName(docPath, null);

            FileEx.SafeDelete(cachePath);
            SrmDocument doc = ResultsUtil.DeserializeDocument(docPath);

            var pepdoc = doc;

            if (asSmallMolecules)
            {
                var refine = new RefinementSettings();
                doc = refine.ConvertToSmallMolecules(pepdoc, TestContext.ResultsDirectory);
            }

            using (var docContainer = new ResultsTestDocumentContainer(doc, docPath))
            {
                // Import the mzML file and verify Mz range
                Import(docContainer, testFilesDir.GetTestPath(RESULTS_NAME), 510, 512);
                Import(docContainer, testFilesDir.GetTestPath(RESULTS_NAME2), 555, 557);
            }
        }
示例#2
0
        private SrmDocument ExportTestLib(string docName, string libName, bool convertFromPeptides, out IList <DbRefSpectra> refSpectra)
        {
            RunUI(() => SkylineWindow.OpenFile(TestFilesDir.GetTestPath(docName)));
            var docOrig = WaitForDocumentLoaded();
            var doc     = docOrig;

            _convertedFromPeptides = convertFromPeptides;
            if (_convertedFromPeptides)
            {
                var refine = new RefinementSettings();
                doc = refine.ConvertToSmallMolecules(docOrig, TestFilesDirs[0].FullPath, addAnnotations: false);
                SkylineWindow.SetDocument(doc, docOrig);
            }
            var exported        = TestFilesDir.GetTestPath(libName);
            var libraryExporter = new SpectralLibraryExporter(SkylineWindow.Document, SkylineWindow.DocumentFilePath);

            libraryExporter.ExportSpectralLibrary(exported, null);
            Assert.IsTrue(File.Exists(exported));
            refSpectra = null;
            using (var connection = new SQLiteConnection(string.Format("Data Source='{0}';Version=3", exported)))
            {
                connection.Open();
                refSpectra = GetRefSpectra(connection);
            }

            return(doc);
        }
示例#3
0
        public PeptidesPerProteinDlg(SrmDocument doc, List <PeptideGroupDocNode> addedPeptideGroups, string decoyGenerationMethod, double decoysPerTarget)
        {
            InitializeComponent();
            _document              = doc;
            _addedPeptideGroups    = addedPeptideGroups;
            _decoyGenerationMethod = decoyGenerationMethod;
            _decoysPerTarget       = decoysPerTarget;
            _remaniningText        = lblRemaining.Text;
            _emptyProteinsText     = lblEmptyProteins.Text;
            int proteinCount, peptideCount, precursorCount, transitionCount;

            NewTargetsAll(out proteinCount, out peptideCount, out precursorCount, out transitionCount);
            lblNew.Text = FormatCounts(lblNew.Text, proteinCount, peptideCount, precursorCount, transitionCount);

            var docRefined = new RefinementSettings {
                RemoveDuplicatePeptides = true
            }.Refine(_document);

            if (_document.PeptideCount == docRefined.PeptideCount)
            {
                Height -= panelRemaining.Top - panelDuplicates.Top;
                panelDuplicates.Hide();
                panelRemaining.Top = panelDuplicates.Top;
            }

            numMinPeptides.TextChanged += UpdateRemaining;
        }
示例#4
0
        public void OkDialog()
        {
            var helper = new MessageBoxHelper(this);

            int numDecoys;

            if (!helper.ValidateNumberTextBox(textNumberOfDecoys, 0, null, out numDecoys))
            {
                return;
            }

            int numComparableGroups = RefinementSettings.SuggestDecoyCount(_document);

            if (numComparableGroups == 0)
            {
                helper.ShowTextBoxError(textNumberOfDecoys, Resources.GenerateDecoysError_No_peptide_precursor_models_for_decoys_were_found_);
                return;
            }
            if (!Equals(DecoysMethod, DecoyGeneration.SHUFFLE_SEQUENCE) && numComparableGroups < numDecoys)
            {
                helper.ShowTextBoxError(textNumberOfDecoys,
                                        Resources.GenerateDecoysDlg_OkDialog_The_number_of_peptides__0__must_be_less_than_the_number_of_peptide_precursor_models_for_decoys__1___or_use_the___2___decoy_generation_method_,
                                        null, numComparableGroups, DecoyGeneration.SHUFFLE_SEQUENCE);
                return;
            }

            _numDecoys   = numDecoys;
            DialogResult = DialogResult.OK;
        }
示例#5
0
        public bool ShowGenerateDecoysDlg(IWin32Window owner = null)
        {
            using (var decoysDlg = new GenerateDecoysDlg(DocumentUI))
            {
                if (decoysDlg.ShowDialog(owner ?? SkylineWindow) == DialogResult.OK)
                {
                    var refinementSettings = new RefinementSettings {
                        NumberOfDecoys = decoysDlg.NumDecoys, DecoysMethod = decoysDlg.DecoysMethod
                    };
                    ModifyDocument(Resources.SkylineWindow_ShowGenerateDecoysDlg_Generate_Decoys, refinementSettings.GenerateDecoys,
                                   docPair =>
                    {
                        var plural = refinementSettings.NumberOfDecoys > 1;
                        return(AuditLogEntry.CreateSingleMessageEntry(new MessageInfo(
                                                                          plural ? MessageType.added_peptide_decoys : MessageType.added_peptide_decoy,
                                                                          DocumentUI.DocumentType,
                                                                          refinementSettings.NumberOfDecoys, refinementSettings.DecoysMethod)));
                    });

                    var nodePepGroup = DocumentUI.PeptideGroups.First(nodePeptideGroup => nodePeptideGroup.IsDecoy);
                    SelectedPath = DocumentUI.GetPathTo((int)SrmDocument.Level.MoleculeGroups, DocumentUI.FindNodeIndex(nodePepGroup.Id));
                    return(true);
                }
            }
            return(false);
        }
示例#6
0
        public void ConvertDocumentToSmallMolecules(RefinementSettings.ConvertToSmallMoleculesMode mode = RefinementSettings.ConvertToSmallMoleculesMode.formulas,
                                                    RefinementSettings.ConvertToSmallMoleculesChargesMode invertCharges = RefinementSettings.ConvertToSmallMoleculesChargesMode.none,
                                                    bool ignoreDecoys = false)
        {
            var doc = WaitForDocumentLoaded();

            RunUI(() => SkylineWindow.ModifyDocument("Convert to small molecules", document =>
            {
                var refine      = new RefinementSettings();
                var path        = Path.GetDirectoryName(SkylineWindow.DocumentFilePath);
                var smallMolDoc = refine.ConvertToSmallMolecules(document, path, mode, invertCharges, ignoreDecoys);
                CheckConsistentLibraryInfo(smallMolDoc);
                return(smallMolDoc);
            }));
            WaitForDocumentChange(doc);

            var newDocFileName =
                SkylineWindow.DocumentFilePath.Contains(BiblioSpecLiteSpec.DotConvertedToSmallMolecules) ?
                SkylineWindow.DocumentFilePath :
                SkylineWindow.DocumentFilePath.Replace(".sky", BiblioSpecLiteSpec.DotConvertedToSmallMolecules + ".sky");

            RunUI(() => SkylineWindow.SaveDocument(newDocFileName));
            WaitForCondition(() => File.Exists(newDocFileName));
            RunUI(() => SkylineWindow.OpenFile(newDocFileName));
            WaitForDocumentLoaded();
            CheckConsistentLibraryInfo();

            Thread.Sleep(1000);
        }
示例#7
0
        public static SrmDocument ChangeAutoManageChildren(SrmDocument document, PickLevel which, bool autoPick)
        {
            var refine = new RefinementSettings {
                AutoPickChildrenAll = which, AutoPickChildrenOff = !autoPick
            };

            return(refine.Refine(document));
        }
示例#8
0
        public void GenerateDecoysTest()
        {
            TestFilesDir testFilesDir = new TestFilesDir(TestContext, @"TestA\SimpleDecoys.zip");

            string      docPath         = testFilesDir.GetTestPath("SimpleDecoys.sky");
            SrmDocument simpleDecoysDoc = ResultsUtil.DeserializeDocument(docPath);

            AssertEx.IsDocumentState(simpleDecoysDoc, 0, 1, 18, 18, 56);

            // First check right number of decoy peptide groups and transtions are generated
            var refineSettings = new RefinementSettings();
            int numDecoys      = simpleDecoysDoc.PeptideCount;
            var decoysDoc      = refineSettings.GenerateDecoys(simpleDecoysDoc, numDecoys, DecoyGeneration.ADD_RANDOM);

            ValidateDecoys(simpleDecoysDoc, decoysDoc, false);

            // Second call to generate decoys to make sure that it removes the original Decoys group and generates a completely new one.
            var newDecoysDoc = refineSettings.GenerateDecoys(decoysDoc, numDecoys, DecoyGeneration.ADD_RANDOM);

            Assert.AreNotEqual(decoysDoc.PeptideGroups.First(nodePeptideGroup => nodePeptideGroup.IsDecoy),
                               newDecoysDoc.PeptideGroups.First(nodePeptideGroup => nodePeptideGroup.IsDecoy));

            // MS1 document with precursors and variable modifications, shuffled
            docPath = testFilesDir.GetTestPath("Ms1FilterTutorial.sky");
            SrmDocument variableDecoysDoc = ResultsUtil.DeserializeDocument(docPath);

            AssertEx.IsDocumentState(variableDecoysDoc, 0, 11, 50, 51, 153);
            numDecoys = variableDecoysDoc.PeptideCount;
            var decoysVariableShuffle = refineSettings.GenerateDecoys(variableDecoysDoc, numDecoys, DecoyGeneration.SHUFFLE_SEQUENCE);

            ValidateDecoys(variableDecoysDoc, decoysVariableShuffle, true);

            // Document with explicit modifications, reversed
            SrmDocument docStudy7 = ResultsUtil.DeserializeDocument("Study7.sky", GetType());

            AssertEx.IsDocumentState(docStudy7, 0, 7, 11, 22, 66);
            numDecoys = docStudy7.PeptideCount;
            var decoysExplicitReverse = refineSettings.GenerateDecoys(docStudy7, numDecoys, DecoyGeneration.REVERSE_SEQUENCE);

            ValidateDecoys(docStudy7, decoysExplicitReverse, true);

            // Random mass shifts with precursors (used to throw an exception due to bad range check that assumed product ions only)
            while (true)
            {
                // As this is random we may need to make a few attempts before we get the values we need
                SrmDocument doc = ResultsUtil.DeserializeDocument(testFilesDir.GetTestPath("precursor_decoy_test.sky"));
                AssertEx.IsDocumentState(doc, null, 1, 1, 2, 6);
                numDecoys = 2;
                var decoysRandom = refineSettings.GenerateDecoys(doc, numDecoys, DecoyGeneration.ADD_RANDOM);
                // Verify that we successfully set a precursor transition decoy mass outside the allowed range of product transitions
                if (decoysRandom.PeptideTransitions.Any(x => x.IsDecoy &&
                                                        (x.Transition.DecoyMassShift > Transition.MAX_PRODUCT_DECOY_MASS_SHIFT ||
                                                         x.Transition.DecoyMassShift < Transition.MIN_PRODUCT_DECOY_MASS_SHIFT)))
                {
                    break;
                }
            }
        }
示例#9
0
        public void DoAgilentMseChromatogramTest(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules)
        {
            if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none && !RunSmallMoleculeTestVersions)
            {
                System.Console.Write(MSG_SKIPPING_SMALLMOLECULE_TEST_VERSION);
                return;
            }

            var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);

            TestSmallMolecules = false; // We have an explicit test for that here

            string      docPath;
            SrmDocument document = InitAgilentMseDocument(testFilesDir, out docPath);

            if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none)
            {
                var refine = new RefinementSettings();
                document = refine.ConvertToSmallMolecules(document, asSmallMolecules);
            }
            using (var docContainer = new ResultsTestDocumentContainer(document, docPath))
            {
                var doc = docContainer.Document;
                var listChromatograms = new List <ChromatogramSet>();
                var path = MsDataFileUri.Parse(@"AgilentMse\BSA-AI-0-10-25-41_first_100_scans.mzML");
                listChromatograms.Add(AssertResult.FindChromatogramSet(doc, path) ??
                                      new ChromatogramSet(path.GetFileName().Replace('.', '_'), new[] { path }));
                var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms));
                Assert.IsTrue(docContainer.SetDocument(docResults, doc, true));
                docContainer.AssertComplete();
                document = docContainer.Document;

                float tolerance = (float)document.Settings.TransitionSettings.Instrument.MzMatchTolerance;
                var   results   = document.Settings.MeasuredResults;
                foreach (var pair in document.MoleculePrecursorPairs)
                {
                    ChromatogramGroupInfo[] chromGroupInfo;
                    Assert.IsTrue(results.TryLoadChromatogram(0, pair.NodePep, pair.NodeGroup,
                                                              tolerance, true, out chromGroupInfo));
                    Assert.AreEqual(1, chromGroupInfo.Length);
                }

                // now drill down for specific values
                int nPeptides = 0;
                foreach (var nodePep in document.Molecules.Where(nodePep => nodePep.Results[0] != null))
                {
                    // expecting just one peptide result in this small data set
                    if (nodePep.Results[0].Sum(chromInfo => chromInfo.PeakCountRatio > 0 ? 1 : 0) > 0)
                    {
                        Assert.AreEqual(0.2462, (double)nodePep.GetMeasuredRetentionTime(0), .0001, "averaged retention time differs in node " + nodePep.RawTextId);
                        Assert.AreEqual(0.3333, (double)nodePep.GetPeakCountRatio(0), 0.0001);
                        nPeptides++;
                    }
                }
                Assert.AreEqual(1, nPeptides);
            }
            testFilesDir.Dispose();
        }
示例#10
0
        private void removeRepeatedPeptidesMenuItem_Click(object sender, EventArgs e)
        {
            var refinementSettings = new RefinementSettings {
                RemoveRepeatedPeptides = true
            };

            ModifyDocument(Resources.SkylineWindow_removeRepeatedPeptidesMenuItem_Click_Remove_repeated_peptides,
                           refinementSettings.Refine, docPair => CreateRemoveNodesEntry(docPair, MessageType.removed_repeated_peptide, MessageType.removed_repeated_peptides));
        }
示例#11
0
        private void removeEmptyPeptidesMenuItem_Click(object sender, EventArgs e)
        {
            var refinementSettings = new RefinementSettings {
                MinPrecursorsPerPeptide = 1
            };

            ModifyDocument(Resources.SkylineWindow_removeEmptyPeptidesMenuItem_Click_Remove_empty_peptides,
                           refinementSettings.Refine, docPair => CreateRemoveNodesEntry(docPair, MessageType.removed_empty_peptide, MessageType.removed_empty_peptides));
        }
示例#12
0
        public void RemoveMissingResults()
        {
            var refinementSettings = new RefinementSettings {
                RemoveMissingResults = true
            };

            ModifyDocument(Resources.SkylineWindow_RemoveMissingResults_Remove_missing_results, refinementSettings.Refine,
                           docPair => AuditLogEntry.CreateSimpleEntry(MessageType.removed_missing_results, docPair.NewDocumentType));
        }
示例#13
0
        public void RefineDocumentTest()
        {
            TestFilesDir testFilesDir = new TestFilesDir(TestContext, @"TestA\Refine.zip");

            var document = InitRefineDocument(testFilesDir);

            AssertEx.Serializable(document);  // This checks a longstanding schema error

            // First check a few refinements which should not change the document
            var refineSettings = new RefinementSettings();

            Assert.AreSame(document, refineSettings.Refine(document));
            refineSettings.MinPeptidesPerProtein = (TestSmallMolecules ? 1 : 3); // That magic small molecule node has just one child
            Assert.AreSame(document, refineSettings.Refine(document));
            refineSettings.MinTransitionsPepPrecursor = (TestSmallMolecules ? 1 : 2);
            Assert.AreSame(document, refineSettings.Refine(document));

            // Remove the protein with only 3 peptides
            refineSettings.MinPeptidesPerProtein = 4;
            Assert.AreEqual(document.PeptideGroupCount - 1, refineSettings.Refine(document).PeptideGroupCount);
            refineSettings.MinPeptidesPerProtein = 1;
            // Remove the precursor with only 2 transitions
            refineSettings.MinTransitionsPepPrecursor = 3;
            Assert.AreEqual(document.PeptideTransitionGroupCount - 1, refineSettings.Refine(document).PeptideTransitionGroupCount);
            refineSettings.MinTransitionsPepPrecursor = null;
            // Remove the heavy precursor
            refineSettings.RefineLabelType = IsotopeLabelType.heavy;
            Assert.AreEqual(document.PeptideTransitionGroupCount - 1, refineSettings.Refine(document).PeptideTransitionGroupCount);
            // Remove everything but the heavy precursor
            refineSettings.RefineLabelType = IsotopeLabelType.light;
            var docRefined = refineSettings.Refine(document);

            AssertEx.IsDocumentState(docRefined, 1, 1, 1, 1, 4);
            // Perform the operation again without protein removal
            refineSettings.MinPeptidesPerProtein = null;
            docRefined = refineSettings.Refine(document);
            AssertEx.IsDocumentState(docRefined, 1, 4, 1, 1, 4);
            refineSettings.RefineLabelType = null;
            // Remove repeated peptides
            refineSettings.RemoveRepeatedPeptides = true;
            Assert.AreEqual(document.PeptideCount - 2, refineSettings.Refine(document).PeptideCount);
            // Remove duplicate peptides
            refineSettings.RemoveDuplicatePeptides = true;
            Assert.AreEqual(document.PeptideCount - 3, refineSettings.Refine(document).PeptideCount);

            // Try settings that remove everything from the document
            refineSettings = new RefinementSettings {
                MinPeptidesPerProtein = 20
            };
            Assert.AreEqual(0, refineSettings.Refine(document).PeptideGroupCount);
            refineSettings.MinPeptidesPerProtein      = 1;
            refineSettings.MinTransitionsPepPrecursor = 20;
            Assert.AreEqual(0, refineSettings.Refine(document).PeptideGroupCount);

            testFilesDir.Dispose();
        }
示例#14
0
        public void RefineConvertToSmallMoleculeMassesAndNamesTest()
        {
            TestFilesDir testFilesDir = new TestFilesDir(TestContext, @"TestA\Refine.zip");

            var document       = InitRefineDocument(testFilesDir);
            var refineSettings = new RefinementSettings();
            var converted      = refineSettings.ConvertToSmallMolecules(document, RefinementSettings.ConvertToSmallMoleculesMode.masses_and_names);

            AssertEx.ConvertedSmallMoleculeDocumentIsSimilar(document, converted);
        }
示例#15
0
        private void CheckRoundTrip()
        {
            // Verify that document roundtrips properly as small molecule
            var refine = new RefinementSettings();
            var doc    = refine.ConvertToSmallMolecules(SkylineWindow.Document, ignoreDecoys: true);

            AssertEx.RoundTrip(doc);
            // Verify that document roundtrips properly
            AssertEx.RoundTrip(SkylineWindow.Document);
        }
 public void ConvertDocumentToSmallMolecules(RefinementSettings.ConvertToSmallMoleculesMode mode = RefinementSettings.ConvertToSmallMoleculesMode.formulas,
                                             bool invertCharges = false, bool ignoreDecoys = false)
 {
     WaitForDocumentLoaded();
     RunUI(() => SkylineWindow.ModifyDocument("Convert to small molecules", document =>
     {
         var refine = new RefinementSettings();
         return(refine.ConvertToSmallMolecules(document, mode, invertCharges, ignoreDecoys));
     }));
 }
示例#17
0
        private void RunMultiplePeptidesSameMz(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

            var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);

            string      docPath;
            SrmDocument document = InitMultiplePeptidesSameMzDocument(testFilesDir, out docPath);

            document = new RefinementSettings().ConvertToSmallMolecules(document, testFilesDir.FullPath, asSmallMolecules);
            using (var docContainer = new ResultsTestDocumentContainer(document, docPath))
            {
                var doc = docContainer.Document;
                var listChromatograms = new List <ChromatogramSet>();
                var path = MsDataFileUri.Parse(@"AMultiplePeptidesSameMz\ljz_20131201k_Newvariant_standards_braf.mzML");
                listChromatograms.Add(AssertResult.FindChromatogramSet(doc, path) ??
                                      new ChromatogramSet(path.GetFileName().Replace('.', '_'), new[] { path }));
                var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms));
                Assert.IsTrue(docContainer.SetDocument(docResults, doc, true));
                docContainer.AssertComplete();
                document = docContainer.Document;

                float tolerance = (float)document.Settings.TransitionSettings.Instrument.MzMatchTolerance;
                var   results   = document.Settings.MeasuredResults;
                foreach (var pair in document.MoleculePrecursorPairs)
                {
                    ChromatogramGroupInfo[] chromGroupInfo;
                    Assert.IsTrue(results.TryLoadChromatogram(0, pair.NodePep, pair.NodeGroup,
                                                              tolerance, true, out chromGroupInfo));
                    Assert.AreEqual(1, chromGroupInfo.Length);  // without the fix, only the first pair will have a chromatogram
                }
                // now drill down for specific values
                int nPeptides = 0;
                foreach (var nodePep in document.Molecules.Where(nodePep => !nodePep.Results[0].IsEmpty))
                {
                    // expecting three peptide result in this small data set
                    if (nodePep.Results[0].Sum(chromInfo => chromInfo.PeakCountRatio > 0 ? 1 : 0) > 0)
                    {
                        Assert.AreEqual(34.2441024780273, (double)nodePep.GetMeasuredRetentionTime(0), .0001);
                        nPeptides++;
                    }
                }
                Assert.AreEqual(3, nPeptides); // without the fix this will give just one result
            }
            testFilesDir.Dispose();
        }
示例#18
0
        public void RefineDocumentTest()
        {
            var document = InitRefineDocument(RefinementSettings.ConvertToSmallMoleculesMode.none);

            // First check a few refinements which should not change the document
            var refineSettings = new RefinementSettings();

            Assert.AreSame(document, refineSettings.Refine(document));
            refineSettings.MinPeptidesPerProtein = 3;
            Assert.AreSame(document, refineSettings.Refine(document));
            refineSettings.MinTransitionsPepPrecursor = 2;
            Assert.AreSame(document, refineSettings.Refine(document));

            // Remove the protein with only 3 peptides
            refineSettings.MinPeptidesPerProtein = 4;
            Assert.AreEqual(document.PeptideGroupCount - 1, refineSettings.Refine(document).PeptideGroupCount);
            refineSettings.MinPeptidesPerProtein = 1;
            // Remove the precursor with only 2 transitions
            refineSettings.MinTransitionsPepPrecursor = 3;
            Assert.AreEqual(document.PeptideTransitionGroupCount - 1, refineSettings.Refine(document).PeptideTransitionGroupCount);
            refineSettings.MinTransitionsPepPrecursor = null;
            // Remove the heavy precursor
            refineSettings.RefineLabelType = IsotopeLabelType.heavy;
            Assert.AreEqual(document.PeptideTransitionGroupCount - 1, refineSettings.Refine(document).PeptideTransitionGroupCount);
            // Remove everything but the heavy precursor
            refineSettings.RefineLabelType = IsotopeLabelType.light;
            var docRefined = refineSettings.Refine(document);

            AssertEx.IsDocumentState(docRefined, null, 1, 1, 1, 4);
            // Perform the operation again without protein removal
            refineSettings.MinPeptidesPerProtein = null;
            docRefined = refineSettings.Refine(document);
            AssertEx.IsDocumentState(docRefined, null, 4, 1, 1, 4);
            refineSettings.RefineLabelType = null;
            // Remove repeated peptides
            refineSettings.RemoveRepeatedPeptides = true;
            Assert.AreEqual(document.PeptideCount - 2, refineSettings.Refine(document).PeptideCount);
            // Remove duplicate peptides
            refineSettings.RemoveDuplicatePeptides = true;
            Assert.AreEqual(document.PeptideCount - 3, refineSettings.Refine(document).PeptideCount);

            // Try settings that remove everything from the document
            refineSettings = new RefinementSettings {
                MinPeptidesPerProtein = 20
            };
            Assert.AreEqual(0, refineSettings.Refine(document).PeptideGroupCount);
            refineSettings.MinPeptidesPerProtein      = 1;
            refineSettings.MinTransitionsPepPrecursor = 20;
            Assert.AreEqual(0, refineSettings.Refine(document).PeptideGroupCount);
        }
示例#19
0
        private void CheckRoundTrip(int pass)
        {
            // Verify that document roundtrips properly
            AssertEx.RoundTrip(SkylineWindow.Document);

            // Verify that document roundtrips properly as small molecule
            var    refine = new RefinementSettings();
            string pathForSmallMoleculeLibs =
                Path.Combine(TestFilesDirs[0].FullPath,
                             string.Format("AsSmallMolecules{0}", pass));
            var doc = refine.ConvertToSmallMolecules(SkylineWindow.Document, pathForSmallMoleculeLibs, ignoreDecoys: true);

            AssertEx.RoundTrip(doc);
        }
示例#20
0
        private static SrmDocument InitWatersImsMseDocument(TestFilesDir testFilesDir, string skyFile,
                                                            RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules,
                                                            out string docPath)
        {
            docPath = testFilesDir.GetTestPath(skyFile);
            var cmdline = new CommandLine();

            Assert.IsTrue(cmdline.OpenSkyFile(docPath)); // Handles any path shifts in database files, like our .imdb file
            SrmDocument doc    = cmdline.Document;
            var         refine = new RefinementSettings();

            doc = refine.ConvertToSmallMolecules(doc, asSmallMolecules);
            return(doc);
        }
示例#21
0
 public void AcceptProteins()
 {
     using (var dlg = new RefineProteinListDlg(DocumentUI))
     {
         if (dlg.ShowDialog(SkylineWindow) == DialogResult.OK)
         {
             var refinementSettings = new RefinementSettings
             {
                 AcceptedProteins  = dlg.AcceptedProteins,
                 AcceptProteinType = dlg.ProteinSpecType
             };
             ModifyDocument(Resources.SkylineWindow_acceptPeptidesMenuItem_Click_Accept_peptides, refinementSettings.Refine, dlg.FormSettings.EntryCreator.Create);
         }
     }
 }
示例#22
0
        public GenerateDecoysDlg(SrmDocument document)
        {
            _document = document;

            InitializeComponent();

            Icon = Resources.Skyline;

            // Set initial decoys number
            textNumberOfDecoys.Text = RefinementSettings.SuggestDecoyCount(document).ToString(LocalizationHelper.CurrentCulture);

            // Fill method type combo box
            comboDecoysGenerationMethod.Items.AddRange(DecoyGeneration.Methods.Cast <object>().ToArray());
            comboDecoysGenerationMethod.SelectedIndex = 0;
        }
示例#23
0
        public void RefineConvertToSmallMoleculesTest()
        {
            // Exercise the code that helps match heavy labeled ion formulas with unlabled
            Assert.AreEqual("C5H12NO2S", BioMassCalc.MONOISOTOPIC.StripLabelsFromFormula("C5H9H'3NO2S"));
            Assert.IsNull(BioMassCalc.MONOISOTOPIC.StripLabelsFromFormula(""));
            Assert.IsNull(BioMassCalc.MONOISOTOPIC.StripLabelsFromFormula(null));

            TestFilesDir testFilesDir = new TestFilesDir(TestContext, @"TestA\Refine.zip");

            var document       = InitRefineDocument(testFilesDir);
            var refineSettings = new RefinementSettings();
            var converted      = refineSettings.ConvertToSmallMolecules(document);

            AssertEx.ConvertedSmallMoleculeDocumentIsSimilar(document, converted);
        }
示例#24
0
        public void DoAsymmetricIsolationTest(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules)
        {
            if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none && !RunSmallMoleculeTestVersions)
            {
                Console.Write(MSG_SKIPPING_SMALLMOLECULE_TEST_VERSION);
                return;
            }

            TestSmallMolecules = false;      // We test small molecules explicitly in this test

            LocalizationHelper.InitThread(); // TODO: All unit tests should be correctly initialized

            var    testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);
            string docPath      = testFilesDir.GetTestPath("TROUBLED_File.sky");
            string cachePath    = ChromatogramCache.FinalPathForName(docPath, null);

            FileEx.SafeDelete(cachePath);
            SrmDocument doc    = ResultsUtil.DeserializeDocument(docPath);
            var         refine = new RefinementSettings();

            doc = refine.ConvertToSmallMolecules(doc, testFilesDir.FullPath, asSmallMolecules);
            const int expectedMoleculeCount = 1;   // At first small molecules did not support multiple label types

            AssertEx.IsDocumentState(doc, null, 1, expectedMoleculeCount, 2, 6);

            using (var docContainer = new ResultsTestDocumentContainer(doc, docPath))
            {
                // Import the first RAW file (or mzML for international)
                string rawPath         = testFilesDir.GetTestPath("Rush_p3_96_21May16_Smeagol.mzML");
                var    measuredResults = new MeasuredResults(new[] { new ChromatogramSet("Single", new[] { rawPath }) });

                {
                    // Import with symmetric isolation window
                    var docResults =
                        docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 3, 3);
                    var    nodeGroup = docResults.MoleculeTransitionGroups.First();
                    double ratio     = nodeGroup.Results[0][0].Ratio ?? 0;
                    // The expected ratio is 1.0, but the symmetric isolation window should produce poor results
                    if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.masses_only) // Can't use labels without a formula
                    {
                        Assert.AreEqual(0.008, ratio, 0.001);
                    }
                }
            }

            testFilesDir.Dispose();
        }
示例#25
0
        private static SrmDocument InitFullScanDocument(string docPath, int prot, ref int pep, ref int prec, ref int tran, RefinementSettings.ConvertToSmallMoleculesMode smallMoleculeTestMode)
        {
            SrmDocument doc = ResultsUtil.DeserializeDocument(docPath);
            int?        expectedRevisionNumber = 0;

            if (smallMoleculeTestMode != RefinementSettings.ConvertToSmallMoleculesMode.none)
            {
                var refine = new RefinementSettings();
                var oldDoc = doc;
                AssertEx.Serializable(oldDoc);
                doc = refine.ConvertToSmallMolecules(doc, smallMoleculeTestMode);
                AssertEx.ConvertedSmallMoleculeDocumentIsSimilar(oldDoc, doc);
                AssertEx.Serializable(doc);
                expectedRevisionNumber = null;
            }
            AssertEx.IsDocumentState(doc, expectedRevisionNumber, prot, pep, prec, tran);
            return(doc);
        }
示例#26
0
        public void AcceptPeptides()
        {
            using (var dlg = new RefineListDlg(DocumentUI))
            {
                if (dlg.ShowDialog(SkylineWindow) == DialogResult.OK)
                {
                    var refinementSettings = new RefinementSettings
                    {
                        AcceptedPeptides = dlg.AcceptedPeptides,
                        AcceptModified   = dlg.MatchModified
                    };
                    if (dlg.RemoveEmptyProteins)
                    {
                        refinementSettings.MinPeptidesPerProtein = 1;
                    }

                    ModifyDocument(Resources.SkylineWindow_acceptPeptidesMenuItem_Click_Accept_peptides, refinementSettings.Refine, dlg.FormSettings.EntryCreator.Create);
                }
            }
        }
示例#27
0
        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);
        }
示例#28
0
        public void DoTestDemux(bool asSmallMolecules)
        {
            var    testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);
            string docPathMsx   = testFilesDir.GetTestPath("MsxTest.sky");
            string dataPathMsx  = testFilesDir.GetTestPath("MsxTest.mzML");
            string cachePathMsx = ChromatogramCache.FinalPathForName(docPathMsx, null);

            FileEx.SafeDelete(cachePathMsx);
            SrmDocument docMsx = ResultsUtil.DeserializeDocument(docPathMsx);

            if (asSmallMolecules)
            {
                var refine = new RefinementSettings();
                docMsx = refine.ConvertToSmallMolecules(docMsx);
            }
            var fullScanInitialMsx = docMsx.Settings.TransitionSettings.FullScan;

            Assert.IsTrue(fullScanInitialMsx.IsEnabledMsMs);

            TestMsx(docMsx, dataPathMsx);

            string docPathOverlap   = testFilesDir.GetTestPath("OverlapTest.sky");
            string dataPathOverlap  = testFilesDir.GetTestPath("OverlapTest.mzML");
            string cachePathOverlap = ChromatogramCache.FinalPathForName(docPathOverlap, null);

            FileEx.SafeDelete(cachePathOverlap);
            SrmDocument docOverlap = ResultsUtil.DeserializeDocument(docPathOverlap);

            if (asSmallMolecules)
            {
                var refine = new RefinementSettings();
                docOverlap = refine.ConvertToSmallMolecules(docOverlap);
            }
            var fullScanInitialOverlap = docMsx.Settings.TransitionSettings.FullScan;

            Assert.IsTrue(fullScanInitialOverlap.IsEnabledMsMs);
            TestOverlap(docOverlap, dataPathOverlap);
        }
示例#29
0
        // Helper function for PrecursorIonFormula and PrecursorNeutralFormula
        private void GetPrecursorFormulaAndAdduct(out Adduct adduct, out string formula)
        {
            if (IsSmallMolecule())
            {
                formula = (DocNode.CustomMolecule.Formula ?? string.Empty);
                adduct  = DocNode.PrecursorAdduct;
            }
            else
            {
                PeptideDocNode parent = DataSchema.Document.FindNode(IdentityPath.Parent) as PeptideDocNode;
                if (parent == null)
                {
                    adduct  = Util.Adduct.EMPTY;
                    formula = String.Empty;
                    return;
                }

                var molecule = RefinementSettings.ConvertToSmallMolecule(
                    RefinementSettings.ConvertToSmallMoleculesMode.formulas, SrmDocument, parent, out adduct,
                    DocNode.TransitionGroup.PrecursorAdduct.AdductCharge, DocNode.TransitionGroup.LabelType);
                formula = molecule.Formula ?? string.Empty;
            }
        }
示例#30
0
        private void DoTestImportSim(bool asSmallMolecules)
        {
            TestSmallMolecules = false; // Don't need that magic extra node
            var    testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);
            string docPath      = testFilesDir.GetTestPath(DOCUMENT_NAME);
            string cachePath    = ChromatogramCache.FinalPathForName(docPath, null);

            FileEx.SafeDelete(cachePath);
            SrmDocument doc = ResultsUtil.DeserializeDocument(docPath);

            var pepdoc = doc;

            if (asSmallMolecules)
            {
                var refine = new RefinementSettings();
                doc = refine.ConvertToSmallMolecules(pepdoc);
            }

            var docContainer = new ResultsTestDocumentContainer(doc, docPath);

            // Import the mzML file and verify Mz range
            Import(docContainer, testFilesDir.GetTestPath(RESULTS_NAME), 510, 512);
            Import(docContainer, testFilesDir.GetTestPath(RESULTS_NAME2), 555, 557);
        }