Пример #1
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);
        }
        public void DoTestTargetedMSMSTutorial(RefinementSettings.ConvertToSmallMoleculesMode smallMoleculesTestMode)
        {
            // Set true to look at tutorial screenshots.
            //IsPauseForScreenShots = true;

            TestSmallMolecules = false; // Don't need that magic extra node, we have an explict test

            ForceMzml = true;   // 2-3x faster than raw files for this test.

            AsSmallMoleculesTestMode = smallMoleculesTestMode;

            if (smallMoleculesTestMode !=  RefinementSettings.ConvertToSmallMoleculesMode.none)
                TestDirectoryName = "AsSmMol_" + smallMoleculesTestMode;

            LinkPdf = "https://skyline.gs.washington.edu/labkey/_webdav/home/software/Skyline/%40files/tutorials/TargetedMSMS-2_5.pdf";

            TestFilesZipPaths = new[]
                {
                    UseRawFiles
                        ? @"http://skyline.gs.washington.edu/tutorials/TargetedMSMS_2.zip"
                        : @"http://skyline.gs.washington.edu/tutorials/TargetedMSMSMzml_2.zip",
                    @"TestTutorial\TargetedMSMSViews.zip"
                };
            RunFunctionalTest();
        }
Пример #3
0
        public void RefineConvertToSmallMoleculeMassesTest()
        {
            TestFilesDir testFilesDir = new TestFilesDir(TestContext, @"TestA\Refine.zip");

            var document = InitRefineDocument(testFilesDir);
            var refineSettings = new RefinementSettings();
            var converted = refineSettings.ConvertToSmallMolecules(document, RefinementSettings.ConvertToSmallMoleculesMode.masses_only);
            AssertEx.ConvertedSmallMoleculeDocumentIsSimilar(document, converted);
        }
Пример #4
0
        public void DoAgilentMseChromatogramTest(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules)
        {
            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);
            }
            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);
            // Release file handles
            docContainer.Release();
            testFilesDir.Dispose();
        }
Пример #5
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);
        }
        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, asSmallMolecules);
            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] != null))
            {
                // 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
            // Release file handles
            docContainer.Release();
            testFilesDir.Dispose();
        }
Пример #7
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;
            }
        }
        public void DoTestExportIsolationList(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules, 
            bool asExplicitRetentionTimes = false, bool negativeCharges = false, bool withSLens = false)
        {
            SmallMoleculeTestMode = asSmallMolecules;
            AsSmallMoleculesNegative = (SmallMoleculeTestMode != RefinementSettings.ConvertToSmallMoleculesMode.none) && negativeCharges;
            AsExplicitRetentionTimes = asExplicitRetentionTimes;
            WithSLens = withSLens;

            TestFilesZip = @"TestFunctional\ExportIsolationListTest.zip";
            // Avoid trying to reuse the .skyd file while another test is still extant
            if (AsExplicitRetentionTimes)
                TestDirectoryName = "AsExplicitRetentionTimes";
            else if (AsSmallMoleculesNegative)
                TestDirectoryName = "AsSmallMoleculesNegative_" + SmallMoleculeTestMode;
            else if (SmallMoleculeTestMode != RefinementSettings.ConvertToSmallMoleculesMode.none)
                TestDirectoryName = "AsSmallMolecules_" + SmallMoleculeTestMode;
            if (WithSLens)
                TestDirectoryName += "WithSLens";
            RunFunctionalTest();
        }
Пример #9
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);
        }
Пример #10
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();
        }
Пример #11
0
        public void DoThermoRatioTest(RefinementSettings.ConvertToSmallMoleculesMode smallMoleculesTestMode)
        {
            TestSmallMolecules = false;  // We do this explicitly

            var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);
            string docPath;
            SrmDocument doc = InitThermoDocument(testFilesDir, out docPath);
            SrmSettings settings = doc.Settings.ChangePeptideModifications(mods =>
                mods.ChangeInternalStandardTypes(new[]{IsotopeLabelType.light}));
            doc = doc.ChangeSettings(settings);
            if (smallMoleculesTestMode != RefinementSettings.ConvertToSmallMoleculesMode.none)
            {
                var docOrig = doc;
                var refine = new RefinementSettings();
                doc = refine.ConvertToSmallMolecules(doc, smallMoleculesTestMode);
                // This is our first example of a converted label doc - check roundtripping
                AssertEx.ConvertedSmallMoleculeDocumentIsSimilar(docOrig, doc);
                AssertEx.Serializable(doc);
            }
            var docContainer = new ResultsTestDocumentContainer(doc, docPath);
            string extRaw = ExtensionTestContext.ExtThermoRaw;
            var listChromatograms = new List<ChromatogramSet>
                                        {
                                            new ChromatogramSet("rep03", new[]
                                                                             {
                                                                                 MsDataFileUri.Parse(testFilesDir.GetTestPath(
                                                                                     "Site20_STUDY9P_PHASEII_QC_03" + extRaw))
                                                                             }),
                                            new ChromatogramSet("rep05", new[]
                                                                             {
                                                                                 MsDataFileUri.Parse(testFilesDir.GetTestPath(
                                                                                     "Site20_STUDY9P_PHASEII_QC_05" + extRaw))
                                                                             })
                                        };
            var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms));
            Assert.IsTrue(docContainer.SetDocument(docResults, doc, true));
            docContainer.AssertComplete();
            docResults = docContainer.Document;
            // Make sure all groups have at least 5 transitions (of 6) with ratios
            int ratioGroupMissingCount = 0;
            foreach (var nodeGroup in docResults.MoleculeTransitionGroups)
            {
                if (nodeGroup.TransitionGroup.LabelType.IsLight)
                {
                    foreach (var result in nodeGroup.Results)
                        Assert.IsFalse(result[0].Ratio.HasValue, "Light group found with a ratio");
                    foreach (TransitionDocNode nodeTran in nodeGroup.Children)
                    {
                        foreach (var resultTran in nodeTran.Results)
                            Assert.IsFalse(resultTran[0].Ratio.HasValue, "Light transition found with a ratio");
                    }
                }
                else
                {
                    bool missingRatio = false;
                    foreach (ChromInfoList<TransitionGroupChromInfo> chromInfoList in nodeGroup.Results)
                    {
                        var ratioHeavy = chromInfoList[0].Ratio;
                        if (!ratioHeavy.HasValue)
                            missingRatio = true;
                    }
                    int ratioCount1 = 0;
                    int ratioCount2 = 0;
                    foreach (TransitionDocNode nodeTranHeavy in nodeGroup.Children)
                    {
                        float? ratioHeavy = nodeTranHeavy.Results[0][0].Ratio;
                        if (ratioHeavy.HasValue)
                        {
                            Assert.IsFalse(float.IsNaN(ratioHeavy.Value) || float.IsInfinity(ratioHeavy.Value));
                            ratioCount1++;
                        }
                        ratioHeavy = nodeTranHeavy.Results[1][0].Ratio;
                        if (ratioHeavy.HasValue)
                        {
                            Assert.IsFalse(float.IsNaN(ratioHeavy.Value) || float.IsInfinity(ratioHeavy.Value));
                            ratioCount2++;
                        }
                    }
                    Assert.AreEqual(3, ratioCount1);
                    if (ratioCount2 < 2)
                        ratioGroupMissingCount++;
                    else
                        Assert.IsFalse(missingRatio, "Precursor missing ratio when transitions have ratios");
                }
            }
            // 3 groups with less than 2 transition ratios
            Assert.AreEqual(3, ratioGroupMissingCount);

            // Remove the first light transition, checking that this removes the ratio
            // from the corresponding heavy transition, but not the entire group, until
            // after all light transitions have been removed.
            IdentityPath pathFirstPep = docResults.GetPathTo((int) SrmDocument.Level.Molecules, 0);
            var nodePep = (PeptideDocNode) docResults.FindNode(pathFirstPep);
            Assert.AreEqual(2, nodePep.Children.Count);
            var nodeGroupLight = (TransitionGroupDocNode) nodePep.Children[0];
            IdentityPath pathGroupLight = new IdentityPath(pathFirstPep, nodeGroupLight.TransitionGroup);
            Assert.IsNull(nodeGroupLight.Results[0][0].Ratio, "Light group has ratio");
            var nodeGroupHeavy = (TransitionGroupDocNode) nodePep.Children[1];
            IdentityPath pathGroupHeavy = new IdentityPath(pathFirstPep, nodeGroupHeavy.TransitionGroup);
            float? ratioStart = nodeGroupHeavy.Results[0][0].Ratio;
            Assert.IsTrue(ratioStart.HasValue, "No starting heavy group ratio");
            var expectedValues = new[] { 1.403414, 1.38697791, 1.34598482 };
            for (int i = 0; i < 3; i++)
            {
                var pathLight = docResults.GetPathTo((int) SrmDocument.Level.Transitions, 0);
                var pathHeavy = docResults.GetPathTo((int) SrmDocument.Level.Transitions, 3);
                TransitionDocNode nodeTran = (TransitionDocNode) docResults.FindNode(pathHeavy);
                float? ratioTran = nodeTran.Results[0][0].Ratio;
                Assert.IsTrue(ratioTran.HasValue, "Expected transition ratio not found");
                Assert.AreEqual(ratioTran.Value, expectedValues[i], 1.0e-5);
                docResults = (SrmDocument) docResults.RemoveChild(pathLight.Parent, docResults.FindNode(pathLight));
                nodeTran = (TransitionDocNode) docResults.FindNode(pathHeavy);
                Assert.IsFalse(nodeTran.Results[0][0].Ratio.HasValue, "Unexpected transiton ratio found");
                Assert.AreEqual(pathGroupHeavy, pathHeavy.Parent, "Transition found outside expected group");
            //                nodePep = (PeptideDocNode) docResults.FindNode(pathFirstPep);
                nodeGroupHeavy = (TransitionGroupDocNode) docResults.FindNode(pathGroupHeavy);
            //                Assert.AreEqual(nodePep.Results[0][0].RatioToStandard, nodeGroupHeavy.Results[0][0].Ratio,
            //                                "Peptide and group ratios not equal");
                if (i < 2)
                {
                    float? ratioGroup = nodeGroupHeavy.Results[0][0].Ratio;
                    Assert.IsTrue(ratioGroup.HasValue, "Group ratio removed with transition ratios");
                    Assert.AreEqual(ratioStart.Value, ratioGroup.Value, 0.1,
                                    "Unexpected group ratio change by more than 0.1");
                }
                else
                {
                    Assert.IsFalse(nodeGroupHeavy.Results[0][0].Ratio.HasValue,
                                   "Group ratio still present with no transition ratios");
                }
            }
            bool asSmallMolecules = (smallMoleculesTestMode != RefinementSettings.ConvertToSmallMoleculesMode.none);
            if (!asSmallMolecules) // GetTransitions() doesn't work the same way for small molecules - it only lists existing ones
            {
                bool firstAdd = true;
                var nodeGroupLightOrig = (TransitionGroupDocNode) doc.FindNode(pathGroupLight);
                DocNode[] lightChildrenOrig = nodeGroupLightOrig.Children.ToArray();
                foreach (var nodeTran in nodeGroupLightOrig.GetTransitions(docResults.Settings,
                    null, nodeGroupLightOrig.PrecursorMz, null, null, null, false))
                {
                    var transition = nodeTran.Transition;
                    if (!firstAdd && lightChildrenOrig.IndexOf(node => Equals(node.Id, transition)) == -1)
                        continue;
                    // Add the first transition, and then the original transitions
                    docResults = (SrmDocument) docResults.Add(pathGroupLight, nodeTran);
                    nodeGroupHeavy = (TransitionGroupDocNode) docResults.FindNode(pathGroupHeavy);
                    if (firstAdd)
                        Assert.IsNull(nodeGroupHeavy.Results[0][0].Ratio, "Unexpected heavy ratio found");
                    else
                        Assert.IsNotNull(nodeGroupHeavy.Results[0][0].Ratio,
                            "Heavy ratio null after adding light children");
                    firstAdd = false;
                }
                Assert.AreEqual(ratioStart, nodeGroupHeavy.Results[0][0].Ratio);
            }
            // Release file handles
            docContainer.Release();
            testFilesDir.Dispose();
        }
Пример #12
0
        public void OkDialog()
        {
            var helper = new MessageBoxHelper(this);

            int? minPeptidesPerProtein = null;
            if (!string.IsNullOrEmpty(textMinPeptides.Text))
            {
                int minVal;
                if (!helper.ValidateNumberTextBox(tabControl1, 0, textMinPeptides, 0, 10, out minVal))
                    return;
                minPeptidesPerProtein = minVal;
            }
            int? minTransitionsPerPrecursor = null;
            if (!string.IsNullOrEmpty(textMinTransitions.Text))
            {
                int minVal;
                if (!helper.ValidateNumberTextBox(tabControl1, 0, textMinTransitions, 0, 100, out minVal))
                    return;
                minTransitionsPerPrecursor = minVal;
            }
            bool removeDuplicatePeptides = cbRemoveDuplicatePeptides.Checked;
            bool removeRepeatedPeptides = cbRemoveRepeatedPeptides.Checked;

            IsotopeLabelType refineLabelType = RefineLabelType;

            bool addLabelType = cbAdd.Checked;
            // If adding, make sure there is something to add
            if (addLabelType && refineLabelType != null && !CanAddLabelType(refineLabelType))
            {
                MessageDlg.Show(this, string.Format(Resources.RefineDlg_OkDialog_The_label_type__0__cannot_be_added_There_are_no_modifications_for_this_type,
                                                    refineLabelType.Name));
                tabControl1.SelectedIndex = 0;
                comboRefineLabelType.Focus();
                return;
            }

            double? minPeakFoundRatio = null, maxPeakFoundRatio = null;
            if (!string.IsNullOrEmpty(textMinPeakFoundRatio.Text))
            {
                double minVal;
                if (!helper.ValidateDecimalTextBox(tabControl1, 1, textMinPeakFoundRatio, 0, 1, out minVal))
                    return;
                minPeakFoundRatio = minVal;
            }
            if (!string.IsNullOrEmpty(textMaxPeakFoundRatio.Text))
            {
                double maxVal;
                if (!helper.ValidateDecimalTextBox(tabControl1, 1, textMaxPeakFoundRatio, 0, 1, out maxVal))
                    return;
                maxPeakFoundRatio = maxVal;
            }
            if (minPeakFoundRatio.HasValue && maxPeakFoundRatio.HasValue &&
                    minPeakFoundRatio.Value > maxPeakFoundRatio.Value)
            {
                helper.ShowTextBoxError(textMaxPeakFoundRatio,
                                        Resources.RefineDlg_OkDialog__0__must_be_less_than_min_peak_found_ratio);
                return;
            }

            int? maxPepPeakRank = null;
            if (!string.IsNullOrEmpty(textMaxPepPeakRank.Text))
            {
                int maxVal;
                if (!helper.ValidateNumberTextBox(tabControl1, 1, textMaxPepPeakRank, 1, 10, out maxVal))
                    return;
                maxPepPeakRank = maxVal;
            }
            int? maxPeakRank = null;
            if (!string.IsNullOrEmpty(textMaxPeakRank.Text))
            {
                int maxVal;
                if (!helper.ValidateNumberTextBox(tabControl1, 1, textMaxPeakRank, 1, 10, out maxVal))
                    return;
                maxPeakRank = maxVal;
            }

            bool removeMissingResults = radioRemoveMissing.Checked;

            double? rtRegressionThreshold = null;
            if (!string.IsNullOrEmpty(textRTRegressionThreshold.Text))
            {
                double minVal;
                if (!helper.ValidateDecimalTextBox(tabControl1, 1, textRTRegressionThreshold, 0, 1, out minVal))
                    return;
                rtRegressionThreshold = minVal;
            }

            double? dotProductThreshold = null;
            if (!string.IsNullOrEmpty(textMinDotProduct.Text))
            {
                double minVal;
                if (!helper.ValidateDecimalTextBox(tabControl1, 1, textMinDotProduct, 0, 1, out minVal))
                    return;
                dotProductThreshold = minVal;
            }

            double? idotProductThreshold = null;
            if (!string.IsNullOrEmpty(textMinIdotProduct.Text))
            {
                double minVal;
                if (!helper.ValidateDecimalTextBox(tabControl1, 1, textMinIdotProduct, 0, 1, out minVal))
                    return;
                idotProductThreshold = minVal;
            }

            bool useBestResult = comboReplicateUse.SelectedIndex > 0;

            RefinementSettings = new RefinementSettings
                                     {
                                         MinPeptidesPerProtein = minPeptidesPerProtein,
                                         RemoveDuplicatePeptides = removeDuplicatePeptides,
                                         RemoveRepeatedPeptides = removeRepeatedPeptides,
                                         MinTransitionsPepPrecursor = minTransitionsPerPrecursor,
                                         RefineLabelType = refineLabelType,
                                         AddLabelType = addLabelType,
                                         MinPeakFoundRatio = minPeakFoundRatio,
                                         MaxPeakFoundRatio = maxPeakFoundRatio,
                                         MaxPepPeakRank = maxPepPeakRank,
                                         MaxPeakRank = maxPeakRank,
                                         PreferLargeIons = cbPreferLarger.Checked,
                                         RemoveMissingResults = removeMissingResults,
                                         RTRegressionThreshold = rtRegressionThreshold,
                                         DotProductThreshold = dotProductThreshold,
                                         IdotProductThreshold = idotProductThreshold,
                                         UseBestResult = useBestResult,
                                         AutoPickChildrenAll = (cbAutoPeptides.Checked ? PickLevel.peptides : 0) |
                                                               (cbAutoPrecursors.Checked ? PickLevel.precursors : 0) |
                                                               (cbAutoTransitions.Checked ? PickLevel.transitions : 0)
                                     };

            DialogResult = DialogResult.OK;
            Close();
        }
Пример #13
0
        public void RefineResultsTest()
        {
            TestFilesDir testFilesDir = new TestFilesDir(TestContext, @"TestA\Refine.zip");
            Settings.Default.RTCalculatorName = Settings.Default.RTScoreCalculatorList.GetDefaults().First().Name;

            var document = InitRefineDocument(testFilesDir);

            // First check a few refinements which should not change the document
            var refineSettings = new RefinementSettings {RTRegressionThreshold = 0.3};
            Assert.AreSame(document, refineSettings.Refine(document));
            refineSettings.RTRegressionThreshold = null;
            refineSettings.DotProductThreshold = Statistics.AngleToNormalizedContrastAngle(0.1);    // Convert form original cos(angle) dot-product
            Assert.AreSame(document, refineSettings.Refine(document));
            refineSettings.DotProductThreshold = null;
            refineSettings.MinPeakFoundRatio = 0;
            refineSettings.MaxPeakFoundRatio = 1.0;
            Assert.AreSame(document, refineSettings.Refine(document));
            refineSettings.MinPeakFoundRatio = refineSettings.MaxPeakFoundRatio = null;
            // refineSettings.MaxPeakRank = 15;  This will remove unmeasured transitions
            Assert.AreSame(document, refineSettings.Refine(document));

            // Remove nodes without results
            refineSettings.MinPeptidesPerProtein = 1;
            refineSettings.RemoveMissingResults = true;
            var docRefined = refineSettings.Refine(document);
            Assert.AreEqual(document.PeptideGroupCount, docRefined.PeptideGroupCount);
            // First three children should be unchanged
            for (int i = 0; i < 3; i++)
                Assert.AreSame(document.Children[i], docRefined.Children[i]);
            var nodePepGroupRefined = (PeptideGroupDocNode) docRefined.Children[3];
            Assert.AreEqual(1, nodePepGroupRefined.MoleculeCount);
            Assert.AreEqual(1, nodePepGroupRefined.TransitionGroupCount);
            Assert.AreEqual(5, nodePepGroupRefined.TransitionCount);

            // Filter for dot product, ignoring nodes without results
            refineSettings.RemoveMissingResults = false;
            double dotProductThreshold = Statistics.AngleToNormalizedContrastAngle(0.9);    // Convert form original cos(angle) dot-product
            refineSettings.DotProductThreshold = dotProductThreshold;
            docRefined = refineSettings.Refine(document);
            int missingResults = 0;
            foreach (var nodeGroup in docRefined.PeptideTransitionGroups)
            {
                if (!nodeGroup.HasResults || nodeGroup.Results[0] == null)
                    missingResults++;
                else
                    Assert.IsTrue(nodeGroup.Results[0][0].LibraryDotProduct >= dotProductThreshold);
            }
            Assert.AreNotEqual(0, missingResults);
            Assert.IsTrue(missingResults < docRefined.PeptideTransitionGroupCount);

            // Further refine with retention time refinement
            refineSettings.RTRegressionThreshold = 0.95;
            refineSettings.RTRegressionPrecision = 2;   // Backward compatibility
            var docRefinedRT = refineSettings.Refine(document);
            Assert.AreNotEqual(docRefined.PeptideCount, docRefinedRT.PeptideCount);
            // And peak count ratio
            refineSettings.MinPeakFoundRatio = 1.0;
            var docRefinedRatio = refineSettings.Refine(document);
            Assert.AreNotEqual(docRefinedRT.PeptideCount, docRefinedRatio.PeptideCount);
            Assert.IsTrue(ArrayUtil.EqualsDeep(docRefinedRatio.Children,
                refineSettings.Refine(docRefinedRT).Children));
            foreach (var nodeGroup in docRefinedRatio.PeptideTransitionGroups)
            {
                Assert.IsTrue(nodeGroup.HasResults);
                Assert.IsTrue(nodeGroup.HasLibInfo);
                Assert.AreEqual(1.0, nodeGroup.Results[0][0].PeakCountRatio);
            }
            Assert.AreEqual(2, docRefinedRatio.PeptideGroupCount);
            Assert.AreEqual(7, docRefinedRatio.PeptideTransitionGroupCount);

            // Pick only most intense transtions
            refineSettings.MaxPeakRank = 4;
            var docRefineMaxPeaks = refineSettings.Refine(document);
            Assert.AreEqual(28, docRefineMaxPeaks.PeptideTransitionCount);
            // Make sure the remaining peaks really started as the right rank,
            // and did not change.
            var dictIdTran = new Dictionary<int, TransitionDocNode>();
            foreach (var nodeTran in document.PeptideTransitions)
                dictIdTran.Add(nodeTran.Id.GlobalIndex, nodeTran);
            foreach (var nodeGroup in docRefineMaxPeaks.PeptideTransitionGroups)
            {
                Assert.AreEqual(refineSettings.MaxPeakRank, nodeGroup.TransitionCount);
                foreach (TransitionDocNode nodeTran in nodeGroup.Children)
                {
                    int rank = nodeTran.Results[0][0].Rank;
                    Assert.IsTrue(rank <= refineSettings.MaxPeakRank);

                    var nodeTranOld = dictIdTran[nodeTran.Id.GlobalIndex];
                    Assert.AreEqual(nodeTranOld.Results[0][0].Rank, nodeTran.Results[0][0].Rank);
                }
            }

            // Pick only most intenst peptides
            refineSettings = new RefinementSettings { MaxPepPeakRank = 5 };
            var docRefinePepMaxPeaks = refineSettings.Refine(document);
            // 4 groups, one unmeasured and one with only 3 peptides
            Assert.AreEqual(13, docRefinePepMaxPeaks.PeptideCount);
            Assert.AreEqual(docRefinePepMaxPeaks.PeptideCount, docRefinePepMaxPeaks.PeptideTransitionGroupCount);

            // Add heavy labeled precursors for everything
            var settingsNew = docRefineMaxPeaks.Settings.ChangeTransitionFilter(f => f.ChangeAutoSelect(false));
            settingsNew = settingsNew.ChangePeptideModifications(m => m.ChangeHeavyModifications(new[]
                {
                    new StaticMod("13C K", "K", ModTerminus.C, null, LabelAtoms.C13, null, null),
                    new StaticMod("13C R", "R", ModTerminus.C, null, LabelAtoms.C13, null, null),
                }));
            var docPrepareAdd = docRefineMaxPeaks.ChangeSettings(settingsNew);
            refineSettings = new RefinementSettings {RefineLabelType = IsotopeLabelType.heavy, AddLabelType = true};
            var docHeavy = refineSettings.Refine(docPrepareAdd);
            Assert.AreEqual(docRefineMaxPeaks.PeptideTransitionCount*2, docHeavy.PeptideTransitionCount);
            // Verify that the precursors were added with the right transitions
            foreach (var nodePep in docHeavy.Peptides)
            {
                Assert.AreEqual(2, nodePep.Children.Count);
                var lightGroup = (TransitionGroupDocNode) nodePep.Children[0];
                Assert.AreEqual(IsotopeLabelType.light, lightGroup.TransitionGroup.LabelType);
                var heavyGroup = (TransitionGroupDocNode)nodePep.Children[1];
                Assert.AreEqual(IsotopeLabelType.heavy, heavyGroup.TransitionGroup.LabelType);
                Assert.AreEqual(lightGroup.TransitionGroup.PrecursorCharge,
                    heavyGroup.TransitionGroup.PrecursorCharge);
                Assert.AreEqual(lightGroup.Children.Count, heavyGroup.Children.Count);
                for (int i = 0; i < lightGroup.Children.Count; i++)
                {
                    var lightTran = (TransitionDocNode) lightGroup.Children[i];
                    var heavyTran = (TransitionDocNode) heavyGroup.Children[i];
                    Assert.AreEqual(lightTran.Transition.FragmentIonName, heavyTran.Transition.FragmentIonName);
                }
            }
            testFilesDir.Dispose();
        }
Пример #14
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), 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),
                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));
        }
Пример #15
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;
        }
Пример #16
0
        public void DoAsymmetricIsolationTest(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules)
        {
            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("Asym_DIA.sky");
            string cachePath = ChromatogramCache.FinalPathForName(docPath, null);
            FileEx.SafeDelete(cachePath);
            SrmDocument doc = ResultsUtil.DeserializeDocument(docPath);
            var refine = new RefinementSettings();
            doc = refine.ConvertToSmallMolecules(doc, asSmallMolecules);
            const int expectedMoleculeCount = 1;   // At first small molecules did not support multiple charge states, and this was 2 for that test mode
            AssertEx.IsDocumentState(doc, null, 1, expectedMoleculeCount, 2, 4);
            var fullScanInitial = doc.Settings.TransitionSettings.FullScan;
            Assert.IsTrue(fullScanInitial.IsEnabledMsMs);
            Assert.AreEqual(FullScanAcquisitionMethod.DIA, fullScanInitial.AcquisitionMethod);
            Assert.AreEqual(25, fullScanInitial.PrecursorFilter);
            AssertEx.Serializable(doc);
            var docContainer = new ResultsTestDocumentContainer(doc, docPath);

            // Import the first RAW file (or mzML for international)
            string rawPath = testFilesDir.GetTestPath("Asym_DIA_data.mzML");
            var measuredResults = new MeasuredResults(new[] { new ChromatogramSet("Single", new[] { rawPath }) });
            TransitionGroupDocNode nodeGroup;
            double ratio;

            {
                // Import with symmetric isolation window
                SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 2, 2);
                nodeGroup = docResults.MoleculeTransitionGroups.First();
                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.25, ratio, 0.05);

                // Revert to original document, and get rid of results cache
                Assert.IsTrue(docContainer.SetDocument(doc, docResults, false));
                FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd"));
            }

            {
                // Import with asymmetric isolation window
                SrmDocument docAsym = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fullScan =>
                    fullScan.ChangeAcquisitionMethod(fullScan.AcquisitionMethod, new IsolationScheme("Test asym", 5, 20))));
                AssertEx.Serializable(docAsym);
                Assert.IsTrue(docContainer.SetDocument(docAsym, doc, false));

                SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 2, 2);
                nodeGroup = docResults.MoleculeTransitionGroups.First();
                ratio = nodeGroup.Results[0][0].Ratio ?? 0;
                // Asymmetric should be a lot closer to 1.0
                if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.masses_only)  // Can't use labels without a formula
                    Assert.AreEqual(1.05, ratio, 0.05);

                // Revert to original document, and get rid of results cache
                Assert.IsTrue(docContainer.SetDocument(doc, docResults, false));
                FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd"));
            }

            {
                // Import with prespecified isolation windows
                var windowList = new List<IsolationWindow>
                {
                    new IsolationWindow(999.2702214, 1024.270221),
                    new IsolationWindow(1024.27267, 1049.27267)
                };
                SrmDocument docPrespecified = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fullScan =>
                    fullScan.ChangeAcquisitionMethod(fullScan.AcquisitionMethod, new IsolationScheme("Test prespecified", windowList))));
                AssertEx.Serializable(docPrespecified);
                Assert.IsTrue(docContainer.SetDocument(docPrespecified, doc, false));

                SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 2, 2);
                nodeGroup = docResults.MoleculeTransitionGroups.First();
                ratio = nodeGroup.Results[0][0].Ratio ?? 0;
                // Asymmetric should be a lot closer to 1.0
                if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.masses_only)  // Can't use labels without a formula
                    Assert.AreEqual(1.05, ratio, 0.05);

                // Revert to original document, and get rid of results cache
                Assert.IsTrue(docContainer.SetDocument(doc, docResults, false));
                FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd"));
            }

            {
                // Import with prespecified targets
                var windowList = new List<IsolationWindow>
                {
                    new IsolationWindow(999.2702214, 1024.270221, 1004.27),
                    new IsolationWindow(1024.27267, 1049.27267, 1029.27)
                };
                SrmDocument docPrespecified = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fullScan =>
                    fullScan.ChangeAcquisitionMethod(fullScan.AcquisitionMethod, new IsolationScheme("Test target", windowList))));
                AssertEx.Serializable(docPrespecified);
                Assert.IsTrue(docContainer.SetDocument(docPrespecified, doc, false));

                SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 2, 2);
                nodeGroup = docResults.MoleculeTransitionGroups.First();
                ratio = nodeGroup.Results[0][0].Ratio ?? 0;
                // Asymmetric should be a lot closer to 1.0
                if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.masses_only)  // Can't use labels without a formula
                    Assert.AreEqual(1.05, ratio, 0.05);

                // Revert to original document, and get rid of results cache
                Assert.IsTrue(docContainer.SetDocument(doc, docResults, false));
                FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd"));
            }

            {
                // Import with ambiguous prespecified targets
                var windowList = new List<IsolationWindow>
                {
                    new IsolationWindow(999.2702214, 1024.270221, 1004.27),
                    new IsolationWindow(1000.0, 1049.27267, 1004.28)
                };
                SrmDocument docAmbiguous = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fullScan =>
                    fullScan.ChangeAcquisitionMethod(fullScan.AcquisitionMethod, new IsolationScheme("Test ambiguous", windowList))));
                AssertEx.Serializable(docAmbiguous);
                Assert.IsTrue(docContainer.SetDocument(docAmbiguous, doc, false));

                try
                {
                    docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 2, 2);
                    Assert.Fail("Expected ambiguous isolation targets.");
                }
                catch (Exception x)
                {
                    AssertEx.AreComparableStrings(Resources.SpectrumFilter_FindFilterPairs_Two_isolation_windows_contain_targets_which_match_the_isolation_target__0__, x.Message, 1);
                }

                // Revert to original document, and get rid of results cache
                Assert.IsTrue(docContainer.SetDocument(doc, docContainer.Document, false));
                FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd"));
            }

            {
                // Import with one isolation window, so one result is discarded.
                var windowList = new List<IsolationWindow>
                {
                    new IsolationWindow(999.2702214, 1024.270221),
                };
                SrmDocument docOneWindow = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fullScan =>
                    fullScan.ChangeAcquisitionMethod(fullScan.AcquisitionMethod, new IsolationScheme("Test one window", windowList))));
                AssertEx.Serializable(docOneWindow);
                Assert.IsTrue(docContainer.SetDocument(docOneWindow, doc, false));

                SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, 1, 1, 0, 2, 0);
                nodeGroup = docResults.MoleculeTransitionGroups.First();
                Assert.IsNull(nodeGroup.Results[0][0].Ratio);

                // Revert to original document, and get rid of results cache
                Assert.IsTrue(docContainer.SetDocument(doc, docResults, false));
                FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd"));
            }

            testFilesDir.Dispose();
        }
Пример #17
0
 private static SrmDocument InitWatersImsMseDocument(TestFilesDir testFilesDir, string skyFile, 
     RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules,
     out string docPath)
 {
     docPath = testFilesDir.GetTestPath(skyFile);
     var consoleBuffer = new StringBuilder();
     var consoleOutput = new CommandStatusWriter(new StringWriter(consoleBuffer));
     var cmdline = new CommandLine(consoleOutput);
     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;
 }
Пример #18
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);
 }
Пример #19
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);
        }
Пример #20
0
        protected override void DoTest()
        {
            // Creating a MS/MS Spectral Library, p. 1
            PeptideSettingsUI peptideSettingsUI = ShowDialog<PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI);
            RunDlg<BuildLibraryDlg>(peptideSettingsUI.ShowBuildLibraryDlg, buildLibraryDlg =>
            {
                buildLibraryDlg.LibraryPath = TestFilesDirs[0].GetTestPath(@"MethodEdit\Library\"); // Not L10N
                buildLibraryDlg.LibraryName = YEAST_ATLAS;
                buildLibraryDlg.LibraryCutoff = 0.95;
                buildLibraryDlg.LibraryAuthority = "peptideatlas.org"; // Not L10N
                buildLibraryDlg.OkWizardPage();
                IList<string> inputPaths = new List<string>
                 {
                     TestFilesDirs[0].GetTestPath(@"MethodEdit\Yeast_atlas\interact-prob.pep.xml") // Not L10N
                 };
                buildLibraryDlg.AddInputFiles(inputPaths);
                buildLibraryDlg.OkWizardPage();
            });

            PeptideSettingsUI peptideSettingsUI1 = peptideSettingsUI;
            RunUI(() =>
                {
                    peptideSettingsUI1.SelectedTab = PeptideSettingsUI.TABS.Library;
                    peptideSettingsUI1.PickedLibraries = new[] { YEAST_ATLAS };
                });
            WaitForOpenForm<PeptideSettingsUI>();   // To show Library tab for Forms testing
            PauseForScreenShot<PeptideSettingsUI.LibraryTab>("Peptide Settings - Library tab", 4); // Not L10N

            RunUI(() => peptideSettingsUI1.SelectedTab = PeptideSettingsUI.TABS.Digest);
            WaitForOpenForm<PeptideSettingsUI>();   // To show Digestion tab for Forms testing

            // Creating a Background Proteome File, p. 3
            FileEx.SafeDelete(TestFilesDirs[0].GetTestPath(@"MethodEdit\FASTA\Yeast" + ProteomeDb.EXT_PROTDB)); // Not L10N
            var buildBackgroundProteomeDlg =
                ShowDialog<BuildBackgroundProteomeDlg>(peptideSettingsUI.ShowBuildBackgroundProteomeDlg);
            RunUI(() =>
            {
                buildBackgroundProteomeDlg.BackgroundProteomePath =
                    TestFilesDirs[0].GetTestPath(@"MethodEdit\FASTA\Yeast"); // Not L10N
                buildBackgroundProteomeDlg.BackgroundProteomeName = "Yeast"; // Not L10N
                buildBackgroundProteomeDlg.AddFastaFile(
                    TestFilesDirs[0].GetTestPath(@"MethodEdit\FASTA\sgd_yeast.fasta")); // Not L10N
            });
            PauseForScreenShot<BuildBackgroundProteomeDlg>("Edit Background Proteome form", 5); // Not L10N

            OkDialog(buildBackgroundProteomeDlg, buildBackgroundProteomeDlg.OkDialog);

            PauseForScreenShot<PeptideSettingsUI.DigestionTab>("Peptide Settings - Digestion tab", 6); // Not L10N

            OkDialog(peptideSettingsUI, peptideSettingsUI.OkDialog);

            if (!TryWaitForCondition(() =>
                SkylineWindow.Document.Settings.PeptideSettings.Libraries.IsLoaded &&
                SkylineWindow.Document.Settings.PeptideSettings.Libraries.Libraries.Count > 0))
            {
                Assert.Fail("Timed out loading libraries: libCount={0}, NotLoadedExplained={1}",
                    SkylineWindow.Document.Settings.PeptideSettings.Libraries.Libraries.Count,
                    SkylineWindow.Document.Settings.PeptideSettings.Libraries.IsNotLoadedExplained ?? "<null>");
            }

            WaitForCondition(() =>
            {
                var peptideSettings = SkylineWindow.Document.Settings.PeptideSettings;
                var backgroundProteome = peptideSettings.BackgroundProteome;
                return (backgroundProteome.HasDigestion(peptideSettings));
            }, "backgroundProteome.HasDigestion");

            // Wait a bit in case web access is turned on and backgroundProteome is actually resolving protein metadata
            int millis = (AllowInternetAccess ? 300 : 60) * 1000;
            WaitForCondition(millis, () => !SkylineWindow.Document.Settings.PeptideSettings.BackgroundProteome.NeedsProteinMetadataSearch, "backgroundProteome.NeedsProteinMetadataSearch");

            // Pasting FASTA Sequences, p. 5
            RunUI(() => SetClipboardFileText(@"MethodEdit\FASTA\fasta.txt")); // Not L10N

            // New in v0.7 : Skyline asks about removing empty proteins.
            using (new CheckDocumentState(35, 25, 25, 75))
            {
                var emptyProteinsDlg = ShowDialog<EmptyProteinsDlg>(SkylineWindow.Paste);
                RunUI(() => emptyProteinsDlg.IsKeepEmptyProteins = true);
                OkDialog(emptyProteinsDlg, emptyProteinsDlg.OkDialog);
                WaitForCondition(millis, () => SkylineWindow.SequenceTree.Nodes.Count > 4);
            }

            RunUI(() =>
            {
                SkylineWindow.SequenceTree.SelectedNode = SkylineWindow.SequenceTree.Nodes[3].Nodes[0];
            });
            RestoreViewOnScreen(07);
            PauseForScreenShot("Main window", 7); // Not L10N

            RunUI(() =>
            {
                Settings.Default.ShowBIons = true;
                SkylineWindow.SequenceTree.SelectedNode.Expand();
                SkylineWindow.SequenceTree.SelectedNode =
                    SkylineWindow.SequenceTree.SelectedNode.Nodes[0].Nodes[1];
            });
            PauseForScreenShot("Main window showing effect of selection on Library Match graph", 8); // Not L10N

            CheckTransitionCount("VDIIANDQGNR", 3); // Not L10N

            using (new CheckDocumentState(35, 28, 31, 155))
            {
                var transitionSettingsUI = ShowDialog<TransitionSettingsUI>(SkylineWindow.ShowTransitionSettingsUI);
                RunUI(() =>
                    {
                        transitionSettingsUI.SelectedTab = TransitionSettingsUI.TABS.Filter;
                        transitionSettingsUI.PrecursorCharges = "2, 3"; // Not L10N
                        transitionSettingsUI.ProductCharges = "1"; // Not L10N
                        transitionSettingsUI.FragmentTypes = "y, b"; // Not L10N
                    });
                WaitForOpenForm<TransitionSettingsUI>();   // To show Filter tab for Forms testing
                PauseForScreenShot<TransitionSettingsUI.FilterTab>("Transition Settings - Filter tab", 9); // Not L10N
                RunUI(() =>
                    {
                        transitionSettingsUI.SelectedTab = TransitionSettingsUI.TABS.Library;
                        transitionSettingsUI.IonCount = 5;
                    });
                PauseForScreenShot<TransitionSettingsUI.LibraryTab>("Transition Settings - Library tab", 10); // Not L10N
                OkDialog(transitionSettingsUI, transitionSettingsUI.OkDialog);
            }
            PauseForScreenShot("Targets tree clipped from main window", 11); // Not L10N

            CheckTransitionCount("VDIIANDQGNR", 5); // Not L10N

            // Using a Public Spectral Library, p. 9
            peptideSettingsUI = ShowDialog<PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI);
            var editListUI =
                ShowDialog<EditListDlg<SettingsListBase<LibrarySpec>, LibrarySpec>>(peptideSettingsUI.EditLibraryList);
            var addLibUI = ShowDialog<EditLibraryDlg>(editListUI.AddItem);
            RunUI(() => addLibUI.LibrarySpec =
                new BiblioSpecLibSpec(YEAST_GPM, TestFilesDirs[0].GetTestPath(@"MethodEdit\Library\yeast_cmp_20.hlf"))); // Not L10N
            OkDialog(addLibUI, addLibUI.OkDialog);
            WaitForClosedForm(addLibUI);
            OkDialog(editListUI, editListUI.OkDialog);

            // Limiting Peptides per Protein, p. 11
            using (new CheckDocumentState(35, 182, 219, 1058))
            {
                RunUI(() =>
                    {
                        peptideSettingsUI.SelectedTab = PeptideSettingsUI.TABS.Library;
                        peptideSettingsUI.PickedLibraries = new[] {YEAST_ATLAS, YEAST_GPM};
                    });
                PauseForScreenShot<PeptideSettingsUI.LibraryTab>("Peptide Settings - Library tab", 12); // Not L10N
                OkDialog(peptideSettingsUI, peptideSettingsUI.OkDialog);
                Assert.IsTrue(WaitForCondition(
                    () =>
                        SkylineWindow.Document.Settings.PeptideSettings.Libraries.IsLoaded &&
                            SkylineWindow.Document.Settings.PeptideSettings.Libraries.Libraries.Count > 0));
            }

            using (new CheckDocumentState(35, 47, 47, 223, 2, true))    // Wait for change loaded, and expect 2 document revisions.
            {
                RunDlg<PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI, peptideSettingsUI2 =>
                    {
                        peptideSettingsUI2.PickedLibraries = new[] {YEAST_GPM};
                        peptideSettingsUI2.LimitPeptides = true;
                        peptideSettingsUI2.RankID = XHunterLibSpec.PEP_RANK_EXPECT;
                        peptideSettingsUI2.PeptidesPerProtein = 3;
                        peptideSettingsUI2.OkDialog();
                    });
            }

            using (new CheckDocumentState(19, 47, 47, 223))
            {
                RunUI(() =>
                    {
                        var refinementSettings = new RefinementSettings {MinPeptidesPerProtein = 1};
                        SkylineWindow.ModifyDocument("Remove empty proteins", refinementSettings.Refine); // Not L10N
                    });
            }

            // Inserting a Protein List, p. 11
            using (new CheckDocumentState(36, 58, 58, 278))
            {
                PasteDlg pasteProteinsDlg = ShowDialog<PasteDlg>(SkylineWindow.ShowPasteProteinsDlg);
                RunUI(() =>
                    {
                        var node = SkylineWindow.SequenceTree.Nodes[SkylineWindow.SequenceTree.Nodes.Count - 1];
                        SkylineWindow.SequenceTree.SelectedNode = node;
                        SetClipboardFileText(@"MethodEdit\FASTA\Protein list.txt"); // Not L10N
                        pasteProteinsDlg.SelectedPath = SkylineWindow.SequenceTree.SelectedPath;
                        pasteProteinsDlg.PasteProteins();
                    });
                PauseForScreenShot<PasteDlg.ProteinListTab>("Insert Protein List - For Screenshot, select last (empty) item in list", 14); // Not L10N
                OkDialog(pasteProteinsDlg, pasteProteinsDlg.OkDialog);
            }

            using (new CheckDocumentState(24, 58, 58, 278))
            {
                RunUI(() =>
                    {
                        var refinementSettings = new RefinementSettings {MinPeptidesPerProtein = 1};
                        SkylineWindow.ModifyDocument("Remove empty proteins", refinementSettings.Refine); // Not L10N
                    });
            }

            // Inserting a Peptide List, p. 13
            using (new CheckDocumentState(25, 70, 70, 338))
            {
                RunUI(() =>
                    {
                        SetClipboardFileText(@"MethodEdit\FASTA\Peptide list.txt"); // Not L10N
                        SkylineWindow.SequenceTree.SelectedNode = SkylineWindow.SequenceTree.Nodes[0];
                        SkylineWindow.Paste();
            // ReSharper disable LocalizableElement
                        SkylineWindow.SequenceTree.Nodes[0].Text = "Primary Peptides"; // Not L10N
            // ReSharper restore LocalizableElement
                    });
                FindNode("TLTAQSMQNSTQSAPNK"); // Not L10N
                PauseForScreenShot("Main window", 16); // Not L10N
            }

            using (new CheckDocumentState(35, 70, 70, 338))
            {
                RunUI(() => SkylineWindow.Undo());
                PasteDlg pastePeptidesDlg = ShowDialog<PasteDlg>(SkylineWindow.ShowPastePeptidesDlg);
                RunUI(pastePeptidesDlg.PastePeptides);
                PauseForScreenShot<PasteDlg.PeptideListTab>("Insert Peptide List -  For screenshot, select last (empty) line in list", 17); // Not L10N
                OkDialog(pastePeptidesDlg, pastePeptidesDlg.OkDialog);
            }

            // Simple Refinement, p. 16
            var findPeptideDlg = ShowDialog<FindNodeDlg>(SkylineWindow.ShowFindNodeDlg);
            RunUI(() => findPeptideDlg.SearchString = "IPEE"); // Not L10N
            OkDialog(findPeptideDlg, () =>
                                         {
                                             findPeptideDlg.FindNext();
                                             findPeptideDlg.Close();
                                         });
            PauseForScreenShot<GraphSpectrum>("Library Match graph metafile", 18); // Not L10N

            using (new CheckDocumentState(35, 64, 64, 320))
            {
                RefineDlg refineDlg = ShowDialog<RefineDlg>(SkylineWindow.ShowRefineDlg);
                RunUI(() => refineDlg.MinTransitions = 5);
                OkDialog(refineDlg, refineDlg.OkDialog);
                PauseForScreenShot("29/35 prot 50/64 pep 50/64 prec 246/320 tran", 18); // Not L10N
            }

            // Checking Peptide Uniqueness, p. 18
            RunUI(() =>
            {
                var node = SkylineWindow.SequenceTree.Nodes[SkylineWindow.SequenceTree.Nodes.Count - (TestSmallMolecules ? 3 : 2)];
                SkylineWindow.SequenceTree.SelectedNode = node;
            });

            using (new CheckDocumentState(34, 63, 63, 315))
            {
                var uniquePeptidesDlg = ShowDialog<UniquePeptidesDlg>(SkylineWindow.ShowUniquePeptidesDlg);
                WaitForConditionUI(() => uniquePeptidesDlg.GetDataGridView().RowCount == 1);
                RunUI(() =>
                    {
                        Assert.AreEqual(1, uniquePeptidesDlg.GetDataGridView().RowCount);
                        Assert.AreEqual(7, uniquePeptidesDlg.GetDataGridView().ColumnCount);
                    });
                PauseForScreenShot<UniquePeptidesDlg>("Unique Peptides form", 19); // Not L10N
                OkDialog(uniquePeptidesDlg, uniquePeptidesDlg.OkDialog);
                RunUI(() => SkylineWindow.EditDelete());
            }

            // Protein Name Auto-Completion
            PauseForScreenShot("(fig. 1): For screenshot, click at bottom of document tree, type 'ybl087' and see the autocomplete text.  Make sure to undo this new entry before proceeding.", 20); // Not L10N
            TestAutoComplete("ybl087", 0); // Not L10N
            var peptideGroups = new List<PeptideGroupDocNode>(Program.ActiveDocument.PeptideGroups);
            Assert.AreEqual("YBL087C", peptideGroups[peptideGroups.Count - 1].Name); // Not L10N

            // Protein Description Auto-Completion
            PauseForScreenShot("(fig. 2): For screenshot, click at bottom of document tree, type 'eft2' and see the autocomplete text, then down-arrow twice. Make sure to undo this new entry before proceeding.", 20); // Not L10N
            TestAutoComplete("eft2", 0); // Sorting logic puts this at the 0th entry in the list - Not L10N
            peptideGroups = new List<PeptideGroupDocNode>(Program.ActiveDocument.PeptideGroups);
            Assert.AreEqual("YDR385W", peptideGroups[peptideGroups.Count - 1].Name); // Not L10N

            // Peptide Sequence Auto-Completion, p. 21
            TestAutoComplete("IQGP", 0); // Not L10N
            var peptides = new List<PeptideDocNode>(Program.ActiveDocument.Peptides);
            Assert.AreEqual("K.AYLPVNESFGFTGELR.Q [769, 784]", peptides[peptides.Count - 1].Peptide.ToString()); // Not L10N
            PauseForScreenShot("(fig. 1) - For screenshot, click at the bottom of the document tree", 21); // Not L10N

            // Pop-up Pick-Lists, p. 21
            using (new CheckDocumentState(36, 71, 71, 355))
            {
                RunUI(() =>
                    {
                        var node = SkylineWindow.SequenceTree.Nodes[SkylineWindow.SequenceTree.Nodes.Count - (TestSmallMolecules ? 4 : 3)];
                        SkylineWindow.SequenceTree.SelectedNode = node;
                    });
                var pickList = ShowDialog<PopupPickList>(SkylineWindow.ShowPickChildrenInTest);
                RunUI(() =>
                    {
                        pickList.ApplyFilter(false);
                        pickList.SetItemChecked(8, true);
                        pickList.AutoManageChildren = false; // TODO: Because calling SetItemChecked does not do this
                    });
                PauseForScreenShot<PopupPickList>("(fig. 2) - YBL087C Peptides picklist", 21); // Not L10N
                RunUI(pickList.OnOk);
            }

            using (new CheckDocumentState(36, 71, 71, 355))
            {
                RunUI(() =>
                    {
                        SkylineWindow.SequenceTree.Nodes[34].ExpandAll();
                        var node =
                            SkylineWindow.SequenceTree.Nodes[34].Nodes[0].Nodes[0];
                        SkylineWindow.SequenceTree.SelectedNode = node;
                    });
                var pickList1 = ShowDialog<PopupPickList>(SkylineWindow.ShowPickChildrenInTest);
                RunUI(() =>
                    {
                        pickList1.SearchString = "y"; // Not L10N
                        pickList1.SetItemChecked(0, false);
                        pickList1.SetItemChecked(1, false);
                        pickList1.ApplyFilter(false);
                        pickList1.ToggleFind();
                        pickList1.SearchString = "b ++"; // Not L10N
                        pickList1.SetItemChecked(4, true);
                        pickList1.SetItemChecked(6, true);
                    });
                PauseForScreenShot<PopupPickList>("b ++ filtered picklist", 22); // Not L10N
                RunUI(pickList1.OnOk);
            }

            // Bigger Picture, p. 22. Drag and Drop, p. 23
            RunUI(() =>
            {
                ITipProvider nodeTip = SkylineWindow.SequenceTree.SelectedNode as ITipProvider;
                Assert.IsTrue(nodeTip != null && nodeTip.HasTip);
                var nodeName = SkylineWindow.SequenceTree.Nodes[1].Name;
                IdentityPath selectPath;
                SkylineWindow.ModifyDocument("Drag and drop", // Not L10N
                    doc => doc.MoveNode(SkylineWindow.Document.GetPathTo(0, 1), SkylineWindow.Document.GetPathTo(0, 0), out selectPath));
                Assert.IsTrue(SkylineWindow.SequenceTree.Nodes[0].Name == nodeName);
            });

            FindNode(string.Format("L [b5] - {0:F04}+", 484.3130)); // Not L10N - may be localized " (rank 3)"
            PauseForScreenShot("For Screenshots, First hover over YBL087C, then over 672.671+++", 23); // Not L10N

            // Preparing to Measure, p. 25
            RunDlg<TransitionSettingsUI>(() => SkylineWindow.ShowTransitionSettingsUI(TransitionSettingsUI.TABS.Prediction), transitionSettingsUI =>
            {
                transitionSettingsUI.RegressionCE = Settings.Default.GetCollisionEnergyByName("ABI 4000 QTrap"); // Not L10N
                transitionSettingsUI.RegressionDP = Settings.Default.GetDeclusterPotentialByName("ABI"); // Not L10N
                transitionSettingsUI.InstrumentMaxMz = 1800;
                transitionSettingsUI.OkDialog();
            });
            RunUI(() => SkylineWindow.SaveDocument(TestFilesDirs[0].GetTestPath("MethodEdit Tutorial.sky"))); // Not L10N
            var exportDialog = ShowDialog<ExportMethodDlg>(() =>
                SkylineWindow.ShowExportMethodDialog(ExportFileType.List));
            RunUI(() =>
            {
                exportDialog.ExportStrategy = ExportStrategy.Buckets;
                exportDialog.MethodType = ExportMethodType.Standard;
                exportDialog.OptimizeType = ExportOptimize.NONE;
                exportDialog.IgnoreProteins = true;
                exportDialog.MaxTransitions = 75;
            });
            PauseForScreenShot<ExportMethodDlg.TransitionListView>("Export Transition List form", 25); // Not L10N

            const string basename = "Yeast_list"; //  Not L10N
            OkDialog(exportDialog, () => exportDialog.OkDialog(TestFilesDirs[0].GetTestPath(basename)));  // write Yeast_list_000n.csv

            // check the output files
            for (int n = 0; n++ < 5;)
            {
                var csvname = String.Format("{0}_{1}.csv", basename, n.ToString("D4")); // Not L10N

                // AssertEx.FieldsEqual is hard-coded with CultureInfo.InvariantCulture, but so is transition list CSV export, so OK
                using (TextReader actual = new StreamReader(TestFilesDirs[0].GetTestPath(csvname)))
                using (TextReader target = new StreamReader(TestFilesDirs[1].GetTestPath(csvname)))
                {
                    AssertEx.FieldsEqual(target, actual, 6, null, true, TestSmallMolecules ? 3 : 0);
                }
            }
        }
Пример #21
0
        public void DoFullScanSettingsTest(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules, 
            out List<SrmDocument> docCheckPoints)
        {
            TestSmallMolecules = false; // Don't need that magic extra node, we have an explicit test

            docCheckPoints = new List<SrmDocument>();
            var doc = ResultsUtil.DeserializeDocument("MultiLabel.sky", GetType());
            var refine = new RefinementSettings();
            doc = refine.ConvertToSmallMolecules(doc, asSmallMolecules);
            Assert.IsFalse(doc.MoleculeTransitionGroups.Any(nodeGroup => nodeGroup.IsotopeDist != null));
            AssertEx.Serializable(doc, AssertEx.Cloned);

            double c13Delta = BioMassCalc.MONOISOTOPIC.GetMass(BioMassCalc.C13) -
                              BioMassCalc.MONOISOTOPIC.GetMass(BioMassCalc.C);
            double n15Delta = BioMassCalc.MONOISOTOPIC.GetMass(BioMassCalc.N15) -
                              BioMassCalc.MONOISOTOPIC.GetMass(BioMassCalc.N);

            // Verify isotope distributions calculated when MS1 filtering enabled
            var enrichments = IsotopeEnrichments.DEFAULT;
            var docIsotopes = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fs =>
                fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Count, 3, enrichments)));
            docCheckPoints.Add(docIsotopes);
            Assert.AreEqual(FullScanMassAnalyzerType.tof,
                docIsotopes.Settings.TransitionSettings.FullScan.PrecursorMassAnalyzer);
            Assert.IsFalse(docIsotopes.MoleculeTransitionGroups.Any(nodeGroup => nodeGroup.IsotopeDist == null));
            foreach (var nodeGroup in docIsotopes.MoleculeTransitionGroups)
            {
                Assert.AreEqual(3, nodeGroup.Children.Count);
                var isotopePeaks = nodeGroup.IsotopeDist;
                Assert.IsNotNull(isotopePeaks);
                Assert.IsTrue(nodeGroup.HasIsotopeDist);
                // The peaks should always includ at least M-1
                Assert.IsTrue(isotopePeaks.MassIndexToPeakIndex(0) > 0);
                // Within 2.5% of 100% of the entire isotope distribution
                Assert.AreEqual(1.0, isotopePeaks.ExpectedProportions.Sum(), 0.025);

                // Precursor mass and m/z values are expected to match exactly (well, within XML roundtrip accuracy anyway)
                Assert.AreEqual(nodeGroup.PrecursorMz, nodeGroup.IsotopeDist.GetMZI(0), SequenceMassCalc.MassTolerance);
                Assert.AreEqual(nodeGroup.PrecursorMz, nodeGroup.TransitionGroup.IsCustomIon ?
                                BioMassCalc.CalculateIonMz(nodeGroup.IsotopeDist.GetMassI(0),
                                                       nodeGroup.TransitionGroup.PrecursorCharge) :
                                SequenceMassCalc.GetMZ(nodeGroup.IsotopeDist.GetMassI(0),
                                                       nodeGroup.TransitionGroup.PrecursorCharge), SequenceMassCalc.MassTolerance);

                // Check isotope distribution masses
                for (int i = 1; i < isotopePeaks.CountPeaks; i++)
                {
                    int massIndex = isotopePeaks.PeakIndexToMassIndex(i);
                    Assert.IsTrue(isotopePeaks.GetMZI(massIndex - 1) < isotopePeaks.GetMZI(massIndex));
                    double massDelta = GetMassDelta(isotopePeaks, massIndex);
                    if (nodeGroup.TransitionGroup.LabelType.IsLight)
                    {
                        // All positive should be close to 13C - C, and 0 should be the same as the next delta
                        double expectedDelta = (massIndex > 0 ? c13Delta : GetMassDelta(isotopePeaks, massIndex + 1));
                        Assert.AreEqual(expectedDelta, massDelta, 0.001);
                    }
                    else if (nodeGroup.TransitionGroup.LabelType.Name.Contains("15N"))
                    {
                        // All positive should be close to 13C, and all negative 15N
                        double expectedDelta = (massIndex > 0 ? c13Delta : n15Delta);
                        Assert.AreEqual(expectedDelta, massDelta, 0.0015);
                    }
                    else if (massIndex == 0)
                    {
                        double expectedDelta = (isotopePeaks.GetProportionI(massIndex - 1) == 0
                                                    ? GetMassDelta(isotopePeaks, massIndex + 1)
                                                    : 1.0017);
                        Assert.AreEqual(expectedDelta, massDelta, 0.001);
                    }
                    else
                    {
                        Assert.AreEqual(c13Delta, massDelta, 0.001);
                    }
                }
            }
            AssertEx.Serializable(docIsotopes, AssertEx.Cloned);

            // Narrow the resolution, and verify that predicted proportion of the isotope
            // distribution captured is reduced for all precursors
            var docIsotopesFt = docIsotopes.ChangeSettings(docIsotopes.Settings.ChangeTransitionFullScan(fs =>
                fs.ChangePrecursorResolution(FullScanMassAnalyzerType.ft_icr, 500 * 1000, 400)));
            docCheckPoints.Add(docIsotopesFt);
            var tranGroupsOld = docIsotopes.MoleculeTransitionGroups.ToArray();
            var tranGroupsNew = docIsotopesFt.MoleculeTransitionGroups.ToArray();
            Assert.AreEqual(tranGroupsOld.Length, tranGroupsNew.Length);
            for (int i = 0; i < tranGroupsOld.Length; i++)
            {
                Assert.AreNotSame(tranGroupsOld[i], tranGroupsNew[i]);
                Assert.AreNotSame(tranGroupsOld[i].IsotopeDist, tranGroupsNew[i].IsotopeDist);
                Assert.IsTrue(tranGroupsOld[i].IsotopeDist.ExpectedProportions.Sum() >
                    tranGroupsNew[i].IsotopeDist.ExpectedProportions.Sum());
            }

            // Use Min % of base peak and verify variation in transitions used
            const float minPercent1 = 10;
            var docIsotopesP1 = docIsotopes.ChangeSettings(docIsotopes.Settings.ChangeTransitionFullScan(fs =>
                fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Percent, minPercent1, enrichments)));
            docCheckPoints.Add(docIsotopesP1);
            tranGroupsNew = docIsotopesP1.MoleculeTransitionGroups.ToArray();
            int maxTran = 0;
            for (int i = 0; i < tranGroupsOld.Length; i++)
            {
                // Isotope distributions should not have changed
                var isotopePeaks = tranGroupsNew[i].IsotopeDist;
                Assert.AreSame(tranGroupsOld[i].IsotopeDist, isotopePeaks);
                // Expected transitions should be present
                maxTran = Math.Max(maxTran, tranGroupsNew[i].Children.Count);
                foreach (TransitionDocNode nodeTran in tranGroupsNew[i].Children)
                {
                    int massIndex = nodeTran.Transition.MassIndex;
                    Assert.IsTrue(minPercent1 <= isotopePeaks.GetProportionI(massIndex)*100.0/isotopePeaks.BaseMassPercent);
                }
            }
            Assert.AreEqual(5, maxTran);
            AssertEx.Serializable(docIsotopesP1, AssertEx.Cloned);  // Express any failure in terms of XML diffs

            // Use 10%, and check that 15N modifications all have M-1
            const float minPercent2 = 5;
            var docIsotopesP2 = docIsotopesP1.ChangeSettings(docIsotopesP1.Settings.ChangeTransitionFullScan(fs =>
                fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Percent, minPercent2, enrichments)));
            docCheckPoints.Add(docIsotopesP2);

            foreach (var nodeGroup in docIsotopesP2.MoleculeTransitionGroups)
            {
                var firstChild = (TransitionDocNode) nodeGroup.Children[0];
                if (nodeGroup.TransitionGroup.LabelType.Name.EndsWith("15N"))
                    Assert.AreEqual(-1, firstChild.Transition.MassIndex);
                else
                    Assert.AreNotEqual(-1, firstChild.Transition.MassIndex);
            }
            AssertEx.Serializable(docIsotopesP2, AssertEx.Cloned);

            // Use lower enrichment of 13C, and verify that this add M-1 for 13C labeled precursors
            var enrichmentsLow13C = enrichments.ChangeEnrichment(new IsotopeEnrichmentItem(BioMassCalc.C13, 0.9));
            var docIsotopesLow13C = docIsotopesP1.ChangeSettings(docIsotopesP1.Settings.ChangeTransitionFullScan(fs =>
                fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Percent, minPercent2, enrichmentsLow13C)));
            tranGroupsNew = docIsotopesLow13C.MoleculeTransitionGroups.ToArray();
            for (int i = 0; i < tranGroupsOld.Length; i++)
            {
                var nodeGroup = tranGroupsNew[i];
                if (!Equals(nodeGroup.TransitionGroup.LabelType.Name, "heavy"))
                    Assert.AreSame(tranGroupsOld[i].IsotopeDist, nodeGroup.IsotopeDist);
                else
                {
                    var firstChild = (TransitionDocNode)nodeGroup.Children[0];
                    Assert.IsTrue(firstChild.Transition.MassIndex < 0);
                }
            }
            AssertEx.Serializable(docIsotopesLow13C, AssertEx.Cloned); // Express any failure as XML diffs

            // Use 0%, and check that everything has M-1 and lower
            var enrichmentsLow = enrichmentsLow13C.ChangeEnrichment(new IsotopeEnrichmentItem(BioMassCalc.N15, 0.97));
            var docIsotopesLowP0 = docIsotopesP1.ChangeSettings(docIsotopesP1.Settings.ChangeTransitionFullScan(fs =>
                fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Percent, 0, enrichmentsLow)));
            docCheckPoints.Add(docIsotopesLowP0);
            foreach (var nodeGroup in docIsotopesLowP0.MoleculeTransitionGroups)
            {
                Assert.AreEqual(nodeGroup.IsotopeDist.CountPeaks, nodeGroup.Children.Count);
                var firstChild = (TransitionDocNode)nodeGroup.Children[0];
                if (nodeGroup.TransitionGroup.LabelType.IsLight)
                    Assert.AreEqual(-1, firstChild.Transition.MassIndex);
                else
                    Assert.IsTrue(-1 > firstChild.Transition.MassIndex);
            }
            AssertEx.Serializable(docIsotopesLowP0, AssertEx.Cloned);

            // Test a document with variable and heavy modifications, which caused problems for
            // the original implementation
            var docVariable = ResultsUtil.DeserializeDocument("HeavyVariable.sky", GetType());
            Assert.IsFalse(docVariable.MoleculeTransitionGroups.Any(nodeGroup => nodeGroup.IsotopeDist == null));

            foreach (var nodeGroup in docVariable.MoleculeTransitionGroups)
            {
                var isotopePeaks = nodeGroup.IsotopeDist;
                Assert.IsNotNull(isotopePeaks);
                // The peaks should always includ at least M-1
                Assert.IsTrue(isotopePeaks.MassIndexToPeakIndex(0) > 0);
                // Precursor mass and m/z values are expected to match exactly (well, within XML roundtrip tolerance anyway)
                Assert.AreEqual(nodeGroup.PrecursorMz, nodeGroup.IsotopeDist.GetMZI(0), SequenceMassCalc.MassTolerance);

                // Check isotope distribution masses
                for (int i = 1; i < isotopePeaks.CountPeaks; i++)
                {
                    int massIndex = isotopePeaks.PeakIndexToMassIndex(i);
                    Assert.IsTrue(isotopePeaks.GetMZI(massIndex - 1) < isotopePeaks.GetMZI(massIndex));
                    double massDelta = GetMassDelta(isotopePeaks, massIndex);
                    bool containsSulfur = nodeGroup.TransitionGroup.Peptide.IsCustomIon
                        ? (nodeGroup.CustomIon.Formula.IndexOfAny("S".ToCharArray()) != -1)
                        : (nodeGroup.TransitionGroup.Peptide.Sequence.IndexOfAny("CM".ToCharArray()) != -1);
                    if (massIndex == 0)
                    {
                        double expectedDelta = (isotopePeaks.GetProportionI(massIndex - 1) == 0
                                                    ? GetMassDelta(isotopePeaks, massIndex + 1)
                                                    : 1.0017);
                        Assert.AreEqual(expectedDelta, massDelta, 0.001);
                    }
                    else if (!containsSulfur || massIndex == 1)
                    {
                        Assert.AreEqual(c13Delta, massDelta, 0.001);
                    }
                    else
                    {
                        Assert.AreEqual(1.00075, massDelta, 0.001);
                    }
                }
            }
            docCheckPoints.Add(docVariable);
        }
Пример #22
0
        private void DoFullScanFilterTest(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules,
            out List<SrmDocument> docCheckpoints, bool centroided = false)
        {
            docCheckpoints = new List<SrmDocument>();
            TestSmallMolecules = false;  // We test small molecules explicitly

            var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);
            string docPath = testFilesDir.GetTestPath("BSA_Protea_label_free_20100323_meth3_multi.sky");
            var expectedPepCount = 7;
            var expectedTransGroupCount = 7;
            var expectedTransCount = 49;
            var doc = InitFullScanDocument(docPath, 2, ref expectedPepCount, ref expectedTransGroupCount, ref expectedTransCount, asSmallMolecules);
            if (centroided && ExtensionTestContext.CanImportThermoRaw)
            {
                const double ppm20 = 20.0;
                doc = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fs =>
                    fs.ChangePrecursorResolution(FullScanMassAnalyzerType.centroided, ppm20, 0)));
            }
            var docContainer = new ResultsTestDocumentContainer(doc, docPath);

            // Import the first RAW file (or mzML for international)
            string rawPath = testFilesDir.GetTestPath("ah_20101011y_BSA_MS-MS_only_5-2" +
                ExtensionTestContext.ExtThermoRaw);
            var measuredResults = new MeasuredResults(new[]
                {new ChromatogramSet("Single", new[] {new MsDataFilePath(rawPath)})});

            SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, 3, 3, 21);

            docCheckpoints.Add(docResults);

            // Refilter allowing multiple precursors per spectrum
            SrmDocument docMulti = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(
                fs => fs.ChangeAcquisitionMethod(FullScanAcquisitionMethod.DIA, new IsolationScheme("Test", 2))));
            AssertEx.Serializable(docMulti, AssertEx.DocumentCloned);
            // Release data cache file
            Assert.IsTrue(docContainer.SetDocument(docMulti, docResults));
            // And remove it
            FileEx.SafeDelete(Path.ChangeExtension(docPath, ChromatogramCache.EXT));

            docCheckpoints.Add(docContainer.ChangeMeasuredResults(measuredResults, 6, 6, 38));

            // Import full scan Orbi-Velos data
            docPath = testFilesDir.GetTestPath("BSA_Protea_label_free_20100323_meth3_long_acc_template.sky");
            expectedPepCount = 3;
            expectedTransGroupCount = 3;
            expectedTransCount = 21;
            doc = InitFullScanDocument(docPath, 1, ref expectedPepCount, ref expectedTransGroupCount, ref expectedTransCount, asSmallMolecules);
            docCheckpoints.Add(doc);
            Assert.AreEqual(FullScanMassAnalyzerType.orbitrap, doc.Settings.TransitionSettings.FullScan.ProductMassAnalyzer);
            // Make sure saving this type of document works
            AssertEx.Serializable(doc, AssertEx.DocumentCloned);
            Assert.IsTrue(docContainer.SetDocument(doc, docContainer.Document));
            rawPath = testFilesDir.GetTestPath("ah_20101029r_BSA_CID_FT_centroid_3uscan_3" +
                ExtensionTestContext.ExtThermoRaw);
            measuredResults = new MeasuredResults(new[] { new ChromatogramSet("Accurate", new[] { rawPath }) });

            docCheckpoints.Add(docContainer.ChangeMeasuredResults(measuredResults, 3, 3, 21));

            // Import LTQ data with MS1 and MS/MS
            docPath = testFilesDir.GetTestPath("BSA_Protea_label_free_20100323_meth3_test4.sky");
            expectedPepCount = 3;
            expectedTransGroupCount = 4;
            expectedTransCount = 32;
            doc = InitFullScanDocument(docPath, 3, ref expectedPepCount, ref expectedTransGroupCount, ref expectedTransCount, asSmallMolecules);
            Assert.AreEqual(FullScanMassAnalyzerType.none, doc.Settings.TransitionSettings.FullScan.ProductMassAnalyzer);
            Assert.AreEqual(FullScanMassAnalyzerType.none, doc.Settings.TransitionSettings.FullScan.PrecursorMassAnalyzer);
            docCheckpoints.Add(doc);
            var docBoth = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fs =>
                fs.ChangeAcquisitionMethod(FullScanAcquisitionMethod.Targeted, null)
                  .ChangePrecursorResolution(FullScanMassAnalyzerType.qit, TransitionFullScan.DEFAULT_RES_QIT, null)));
            docCheckpoints.Add(docBoth);
            AssertEx.Serializable(docBoth, AssertEx.DocumentCloned);
            Assert.IsTrue(docContainer.SetDocument(docBoth, docContainer.Document));

            string dataPath = testFilesDir.GetTestPath("klc_20100329v_Protea_Peptide_Curve_200fmol_uL_tech1.mzML");
            var listResults = new List<ChromatogramSet>
                                  {
                                      new ChromatogramSet("MS1 and MS/MS", new[] { dataPath }),
                                  };
            measuredResults = new MeasuredResults(listResults.ToArray());

            docCheckpoints.Add(docContainer.ChangeMeasuredResults(measuredResults, expectedPepCount, expectedTransGroupCount, expectedTransCount-6));
            // The mzML was filtered for the m/z range 410 to 910.
            foreach (var nodeTran in docContainer.Document.PeptideTransitions)
            {
                Assert.IsTrue(nodeTran.HasResults);
                Assert.IsNotNull(nodeTran.Results[0]);
                if (410 > nodeTran.Mz || nodeTran.Mz > 910)
                    Assert.IsTrue(nodeTran.Results[0][0].IsEmpty);
                else
                    Assert.IsFalse(nodeTran.Results[0][0].IsEmpty);
            }

            // Import LTQ data with MS1 and MS/MS using multiple files for a single replicate
            listResults.Add(new ChromatogramSet("Multi-file", new[]
                                                                  {
                                                                      testFilesDir.GetTestPath("both_DRV.mzML"),
                                                                      testFilesDir.GetTestPath("both_KVP.mzML"),
                                                                  }));
            measuredResults = new MeasuredResults(listResults.ToArray());
            docCheckpoints.Add(docContainer.ChangeMeasuredResults(measuredResults, expectedPepCount - 1, expectedTransGroupCount-1, expectedTransCount-6));
            int indexResults = listResults.Count - 1;
            foreach (var nodeTran in docContainer.Document.PeptideTransitions)
            {
                Assert.IsTrue(nodeTran.HasResults);
                Assert.AreEqual(listResults.Count, nodeTran.Results.Count);
                var peptide = nodeTran.Transition.Group.Peptide;
                // DRV without FASTA sequence should not have data for non-precursor transitions
                if (!peptide.Sequence.StartsWith("DRV") || !peptide.Begin.HasValue)
                {
                    Assert.IsNotNull(nodeTran.Results[indexResults]);
                    Assert.IsFalse(nodeTran.Results[indexResults][0].IsEmpty);
                }
                else if (nodeTran.Transition.IonType != IonType.precursor)
                    Assert.IsNull(nodeTran.Results[indexResults]);
                else
                {
                    // Random, bogus peaks chosen in both files
                    Assert.IsNotNull(nodeTran.Results[indexResults]);
                    Assert.AreEqual(2, nodeTran.Results[indexResults].Count);
                    Assert.IsFalse(nodeTran.Results[indexResults][0].IsEmpty);
                    Assert.IsFalse(nodeTran.Results[indexResults][1].IsEmpty);
                }
            }

            if (asSmallMolecules == RefinementSettings.ConvertToSmallMoleculesMode.masses_only)
                return; // Can't work with isotope distributions when we don't have ion formulas

            // Verify handling of bad request for vendor centroided data - out-of-range PPM
            docPath = testFilesDir.GetTestPath("Yeast_HI3 Peptides_test.sky");
            expectedPepCount = 2;
            expectedTransGroupCount = 2;
            expectedTransCount = 2;
            doc = InitFullScanDocument(docPath, 2, ref expectedPepCount, ref expectedTransGroupCount, ref expectedTransCount, asSmallMolecules);
            Assert.AreEqual(FullScanMassAnalyzerType.none, doc.Settings.TransitionSettings.FullScan.ProductMassAnalyzer);
            Assert.AreEqual(FullScanMassAnalyzerType.none, doc.Settings.TransitionSettings.FullScan.PrecursorMassAnalyzer);
            var docBad = doc;
            AssertEx.ThrowsException<InvalidDataException>(() =>
              docBad.ChangeSettings(docBad.Settings.ChangeTransitionFullScan(fs =>
                fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Count, 1, IsotopeEnrichments.DEFAULT)
                  .ChangePrecursorResolution(FullScanMassAnalyzerType.centroided, 50 * 1000, 400))),
                  string.Format(Resources.TransitionFullScan_ValidateRes_Mass_accuracy_must_be_between__0__and__1__for_centroided_data_,
                     TransitionFullScan.MIN_CENTROID_PPM,TransitionFullScan.MAX_CENTROID_PPM));

            // Verify relationship between PPM and resolving power
            const double ppm = 20.0;  // Should yield same filter width as resolving power 50,000 in TOF
            var docNoCentroid = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fs =>
                fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Count, 1, IsotopeEnrichments.DEFAULT)
                  .ChangePrecursorResolution(FullScanMassAnalyzerType.centroided, ppm, 0)));
            AssertEx.Serializable(docNoCentroid, AssertEx.DocumentCloned);
            Assert.IsTrue(docContainer.SetDocument(docNoCentroid, docContainer.Document));
            const double mzTest = 400.0;
            var filterWidth = docNoCentroid.Settings.TransitionSettings.FullScan.GetPrecursorFilterWindow(mzTest);
            Assert.AreEqual(mzTest * 2.0 * ppm * 1E-6, filterWidth);

            // Verify handling of bad request for vendor centroided data - ask for centroiding in mzML
            const string fileName = "S_2_LVN.mzML";
            var filePath = testFilesDir.GetTestPath(fileName);
            AssertEx.ThrowsException<AssertFailedException>(() =>
                {
                listResults = new List<ChromatogramSet> { new ChromatogramSet("rep1", new[] {new MsDataFilePath(filePath, null, true)}), };
                docContainer.ChangeMeasuredResults(new MeasuredResults(listResults.ToArray()), 1, 1, 1);
                },
                string.Format(Resources.NoCentroidedDataException_NoCentroidedDataException_No_centroided_data_available_for_file___0_____Adjust_your_Full_Scan_settings_, fileName));

            // Import FT data with only MS1
            docPath = testFilesDir.GetTestPath("Yeast_HI3 Peptides_test.sky");
            expectedPepCount = 2;
            expectedTransGroupCount = 2;
            expectedTransCount = 2;
            doc = InitFullScanDocument(docPath, 2, ref expectedPepCount, ref expectedTransGroupCount, ref expectedTransCount, asSmallMolecules);
            Assert.AreEqual(FullScanMassAnalyzerType.none, doc.Settings.TransitionSettings.FullScan.ProductMassAnalyzer);
            Assert.AreEqual(FullScanMassAnalyzerType.none, doc.Settings.TransitionSettings.FullScan.PrecursorMassAnalyzer);
            var docMs1 = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fs =>
                fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Count, 1, IsotopeEnrichments.DEFAULT)
                  .ChangePrecursorResolution(FullScanMassAnalyzerType.tof, 50 * 1000, null)));
            Assert.AreEqual(filterWidth, docMs1.Settings.TransitionSettings.FullScan.GetPrecursorFilterWindow(mzTest));
            docMs1 = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fs =>
                fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Count, 1, IsotopeEnrichments.DEFAULT)
                  .ChangePrecursorResolution(FullScanMassAnalyzerType.ft_icr, 50 * 1000, mzTest)));
            AssertEx.Serializable(docMs1, AssertEx.DocumentCloned);
            Assert.IsTrue(docContainer.SetDocument(docMs1, docContainer.Document));
            const string rep1 = "rep1";
            listResults = new List<ChromatogramSet>
                                  {
                                      new ChromatogramSet(rep1, new[] {filePath}),
                                  };
            measuredResults = new MeasuredResults(listResults.ToArray());
            docCheckpoints.Add(docContainer.ChangeMeasuredResults(measuredResults, 1, 1, 1));
            // Because of the way the mzML files were filtered, all of the LVN peaks should be present
            // in the first replicate, and all of the NVN peaks should be present in the other.
            foreach (var nodeTranGroup in docContainer.Document.MoleculeTransitionGroups)
            {
                foreach (var docNode in nodeTranGroup.Children)
                {
                    var nodeTran = (TransitionDocNode) docNode;
                    Assert.IsTrue(nodeTran.HasResults);
                    Assert.AreEqual(1, nodeTran.Results.Count);
                    if ((nodeTran.Transition.Group.Peptide.IsCustomIon
                        ? nodeTranGroup.CustomIon.Name
                        : nodeTran.Transition.Group.Peptide.Sequence).StartsWith("LVN"))
                        Assert.IsFalse(nodeTran.Results[0][0].IsEmpty);
                    else
                        Assert.IsTrue(nodeTran.Results[0][0].IsEmpty);
                }
            }
            const string rep2 = "rep2";
            listResults.Add(new ChromatogramSet(rep2, new[] {testFilesDir.GetTestPath("S_2_NVN.mzML")}));
            measuredResults = new MeasuredResults(listResults.ToArray());
            docCheckpoints.Add(docContainer.ChangeMeasuredResults(measuredResults, 1, 1, 1));
            // Because of the way the mzML files were filtered, all of the LVN peaks should be present
            // in the first replicate, and all of the NVN peaks should be present in the other.
            foreach (var nodeTranGroup in docContainer.Document.MoleculeTransitionGroups)
            {
                foreach (var docNode in nodeTranGroup.Children)
                {
                    var nodeTran = (TransitionDocNode) docNode;
                    Assert.IsTrue(nodeTran.HasResults);
                    Assert.AreEqual(2, nodeTran.Results.Count);
                    if ((nodeTran.Transition.Group.Peptide.IsCustomIon
                        ? nodeTranGroup.CustomIon.Name
                        : nodeTran.Transition.Group.Peptide.Sequence).StartsWith("LVN"))
                        Assert.IsTrue(nodeTran.Results[1][0].IsEmpty);
                    else
                        Assert.IsFalse(nodeTran.Results[1][0].IsEmpty);
                }
            }

            // Chromatograms should be present in the cache for a number of isotopes.
            var docMs1Isotopes = docContainer.Document.ChangeSettings(doc.Settings
                .ChangeTransitionFullScan(fs => fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Count,
                                                                           3, IsotopeEnrichments.DEFAULT))
                .ChangeTransitionFilter(filter => filter.ChangeIonTypes(new[] {IonType.precursor})));
            docCheckpoints.Add(docMs1Isotopes);
            AssertEx.IsDocumentState(docMs1Isotopes, null, 2, 2, 2 );   // Need to reset auto-manage for transitions
            var refineAutoSelect = new RefinementSettings { AutoPickChildrenAll = PickLevel.transitions };
            docMs1Isotopes = refineAutoSelect.Refine(docMs1Isotopes);
            AssertEx.IsDocumentState(docMs1Isotopes, null, 2, 2, 6);
            AssertResult.IsDocumentResultsState(docMs1Isotopes, rep1, 1, 1, 0, 3, 0);
            AssertResult.IsDocumentResultsState(docMs1Isotopes, rep2, 1, 1, 0, 3, 0);
            docCheckpoints.Add(docMs1Isotopes);

            // Add M-1 transitions, and verify that they have chromatogram data also, but
            // empty peaks in all cases
            var docMs1All = docMs1Isotopes.ChangeSettings(docMs1Isotopes.Settings
                .ChangeTransitionFullScan(fs => fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Percent,
                                                                           0, IsotopeEnrichments.DEFAULT))
                .ChangeTransitionIntegration(i => i.ChangeIntegrateAll(false)));    // For compatibility with v2.5 and earlier
            docCheckpoints.Add(docMs1All);
            AssertEx.IsDocumentState(docMs1All, null, 2, 2, 10);
            AssertResult.IsDocumentResultsState(docMs1All, rep1, 1, 1, 0, 4, 0);
            AssertResult.IsDocumentResultsState(docMs1All, rep2, 1, 1, 0, 4, 0);
            var ms1AllTranstions = docMs1All.MoleculeTransitions.ToArray();
            var tranM1 = ms1AllTranstions[0];
            Assert.AreEqual(-1, tranM1.Transition.MassIndex);
            Assert.IsTrue(tranM1.Results[0] != null && tranM1.Results[1] != null);
            Assert.IsTrue(tranM1.Results[0][0].IsEmpty && tranM1.Results[1][0].IsEmpty);
            tranM1 = ms1AllTranstions[5];
            Assert.AreEqual(-1, tranM1.Transition.MassIndex);
            Assert.IsTrue(tranM1.Results[0] != null && tranM1.Results[1] != null);
            Assert.IsTrue(tranM1.Results[0][0].IsEmpty && tranM1.Results[1][0].IsEmpty);
        }
Пример #23
0
        protected override void DoTest()
        {
            // This test is quite specific to the input data set - needs results for all nodes to export the list.  Shut off the special non-proteomic test mode, otherwise you get:
            // To export a scheduled method, you must first choose a retention time predictor in Peptide Settings / Prediction, or import results for all peptides in the document.
            TestSmallMolecules = false;

            // For now, CSV files are produced with invariant culture because some manufacturers do not handle internationalized CSVs.
            _cultureInfo = CultureInfo.InvariantCulture;
            _fieldSeparator = TextUtil.GetCsvSeparator(_cultureInfo);
            string isolationWidth = string.Format(_cultureInfo, "Narrow (~{0:0.0} m/z)", 1.3);
            const double slens = 1.234;

            // Load document which is already configured for DDA, and contains data for scheduling
            string standardDocumentFile = TestFilesDir.GetTestPath("BSA_Protea_label_free_meth3.sky");
            RunUI(() => { SkylineWindow.OpenFile(standardDocumentFile); });
            WaitForDocumentLoaded();
            if (SmallMoleculeTestMode != RefinementSettings.ConvertToSmallMoleculesMode.none)
            {
                ConvertDocumentToSmallMolecules(SmallMoleculeTestMode, AsSmallMoleculesNegative);
                WaitForDocumentLoaded();
            }

            var t46 = 46.790;
            var t39 = 39.900;
            var halfWin = 1.0;
            if (AsExplicitRetentionTimes)
            {
                const double timeOffset = 10;  // To verify that explicit retention times are in use
                const double winOffset = .4;

                RunUI(() => SkylineWindow.ModifyDocument("Convert to explicit retention times", document =>
                {
                    var refine = new RefinementSettings();
                    return refine.ConvertToExplicitRetentionTimes(document, timeOffset, winOffset);
                }));

                t46 += timeOffset;
                t39 += timeOffset;
                halfWin += winOffset*0.5;
            }

            // Conversion to negative charge states shifts the masses
            var mzFirst = AsSmallMoleculesNegative ? 580.304419 : 582.318971;
            var mzLast = AsSmallMoleculesNegative ? 442.535467 : 444.55002;
            var zFirst = AsSmallMoleculesNegative ? -2 : 2;
            var zLast = AsSmallMoleculesNegative ? -3 : 3;
            var ceFirst = AsSmallMoleculesNegative ? 20.3 : 20.4;
            var ceLast = AsSmallMoleculesNegative ? 16.2 : 19.2;
            double? slensA = null;
            double? slensB = null;
            if (WithSLens)
            {
                slensA = slens;
                slensB = ThermoMassListExporter.DEFAULT_SLENS;
            }

            // Export Agilent unscheduled DDA list.
            ExportIsolationList(
                "AgilentUnscheduledDda.csv",
                ExportInstrumentType.AGILENT_TOF, FullScanAcquisitionMethod.None, ExportMethodType.Standard,
                AgilentIsolationListExporter.GetDdaHeader(_fieldSeparator),
                FieldSeparate("True", mzFirst, 20, zFirst, "Preferred", 0, string.Empty, isolationWidth, ceFirst),
                FieldSeparate("True", mzLast, 20, zLast, "Preferred", 0, string.Empty, isolationWidth, ceLast));

            // Export Agilent scheduled DDA list.
            ExportIsolationList(
                "AgilentScheduledDda.csv",
                ExportInstrumentType.AGILENT_TOF, FullScanAcquisitionMethod.None, ExportMethodType.Scheduled,
                AgilentIsolationListExporter.GetDdaHeader(_fieldSeparator),
                FieldSeparate("True", mzFirst, 20, zFirst, "Preferred", t46, 2*halfWin, isolationWidth, ceFirst),
                FieldSeparate("True", mzLast, 20, zLast, "Preferred", t39, 2*halfWin, isolationWidth, ceLast));

            // Export Thermo unscheduled DDA list.
            const double nce = ThermoQExactiveIsolationListExporter.NARROW_NCE;
            bool AsSmallMolecules = (SmallMoleculeTestMode != RefinementSettings.ConvertToSmallMoleculesMode.none);
            bool AsSmallMoleculeMasses = (SmallMoleculeTestMode == RefinementSettings.ConvertToSmallMoleculesMode.masses_only);
            var peptideA = AsSmallMolecules
                ? (AsSmallMoleculeMasses ? "Ion [1164.639040/1165.343970] (light)" : (AsSmallMoleculesNegative ? "LVNELTEFAK(-H2) (light)" : "LVNELTEFAK(+H2) (light)"))
                : "LVNELTEFAK (light)";
            var peptideB = AsSmallMolecules
                ? (AsSmallMoleculeMasses ? "Ion [1333.651707/1334.400621] (light)" : (AsSmallMoleculesNegative ? "IKNLQSLDPSH(-H3) (light)" : "IKNLQSLDPSH(+H3) (light)"))
                : "IKNLQS[+80.0]LDPSH (light)";
            var polarity = AsSmallMoleculesNegative ? "Negative" : "Positive";
            var thermoQExactiveIsolationListExporter = new ThermoQExactiveIsolationListExporter(SkylineWindow.Document)
            {
                UseSlens = WithSLens
            };
            ExportIsolationList(
                "ThermoUnscheduledDda.csv",
                ExportInstrumentType.THERMO_Q_EXACTIVE, FullScanAcquisitionMethod.None, ExportMethodType.Standard,
                thermoQExactiveIsolationListExporter.GetHeader(_fieldSeparator),
                FieldSeparate(mzFirst, string.Empty, string.Empty, Math.Abs(zFirst), polarity, string.Empty, string.Empty, nce, slensA, peptideA),
                FieldSeparate(mzLast, string.Empty, string.Empty, Math.Abs(zLast), polarity, string.Empty, string.Empty, nce, slensB, peptideB));

            // Export Thermo scheduled DDA list.
            if (!AsSmallMoleculesNegative) // .skyd file chromatograms are not useful in this conversion due to mass shift
              ExportIsolationList(
                "ThermoScheduledDda.csv",
                ExportInstrumentType.THERMO_Q_EXACTIVE, FullScanAcquisitionMethod.None, ExportMethodType.Scheduled,
                thermoQExactiveIsolationListExporter.GetHeader(_fieldSeparator),
                FieldSeparate(mzFirst, string.Empty, string.Empty, Math.Abs(zFirst), polarity, t46 - halfWin, t46 + halfWin, nce, slensA, peptideA),
                FieldSeparate(mzLast, string.Empty, string.Empty, Math.Abs(zLast), polarity, t39 - halfWin, t39 + halfWin, nce, slensB, peptideB));

            // Export Agilent unscheduled Targeted list.
            ExportIsolationList(
                "AgilentUnscheduledTargeted.csv",
                ExportInstrumentType.AGILENT_TOF, FullScanAcquisitionMethod.Targeted, ExportMethodType.Standard,
                AgilentIsolationListExporter.GetTargetedHeader(_fieldSeparator),
                FieldSeparate("True", mzFirst, zFirst, 0, string.Empty, isolationWidth, ceFirst, string.Empty),
                FieldSeparate("True", mzLast, zLast, 0, string.Empty, isolationWidth, ceLast, string.Empty));

            // Export Agilent scheduled Targeted list.
            if (!AsSmallMoleculesNegative) // .skyd file chromatograms are not useful in this conversion due to mass shift
                ExportIsolationList(
                "AgilentScheduledTargeted.csv",
                ExportInstrumentType.AGILENT_TOF, FullScanAcquisitionMethod.Targeted, ExportMethodType.Scheduled,
                AgilentIsolationListExporter.GetTargetedHeader(_fieldSeparator),
                FieldSeparate("True", mzFirst, zFirst, t46, 2*halfWin, isolationWidth, ceFirst, string.Empty),
                FieldSeparate("True", mzLast, zLast, t39, 2*halfWin, isolationWidth, ceLast, string.Empty));

            // Export Thermo unscheduled Targeted list.
            ExportIsolationList(
                "ThermoUnscheduledTargeted.csv",
                ExportInstrumentType.THERMO_Q_EXACTIVE, FullScanAcquisitionMethod.Targeted, ExportMethodType.Standard,
                thermoQExactiveIsolationListExporter.GetHeader(_fieldSeparator),
                FieldSeparate(mzFirst, string.Empty, string.Empty, Math.Abs(zFirst), polarity, string.Empty, string.Empty, nce, slensA, peptideA),
                FieldSeparate(mzLast, string.Empty, string.Empty, Math.Abs(zLast), polarity, string.Empty, string.Empty, nce, slensB, peptideB));

            // Export Thermo scheduled Targeted list.
            if (!AsSmallMoleculesNegative) // .skyd file chromatograms are not useful in this conversion due to mass shift
                ExportIsolationList(
                "ThermoScheduledTargeted.csv",
                ExportInstrumentType.THERMO_Q_EXACTIVE, FullScanAcquisitionMethod.Targeted, ExportMethodType.Scheduled,
                thermoQExactiveIsolationListExporter.GetHeader(_fieldSeparator),
                FieldSeparate(mzFirst, string.Empty, string.Empty, Math.Abs(zFirst), polarity, t46 - halfWin, t46 + halfWin, nce, slensA, peptideA),
                FieldSeparate(mzLast, string.Empty, string.Empty, Math.Abs(zLast), polarity, t39 - halfWin, t39 + halfWin, nce, slensB, peptideB));

            // Export Thermo Fusion unscheduled Targeted list.
            var thermoFusionMassListExporter = new ThermoFusionMassListExporter(SkylineWindow.Document)
            {
                UseSlens = WithSLens
            };
            ExportIsolationList(
                "FusionUnscheduledTargeted.csv",
                ExportInstrumentType.THERMO_FUSION, FullScanAcquisitionMethod.Targeted, ExportMethodType.Standard,
                thermoFusionMassListExporter.GetHeader(_fieldSeparator),
                FieldSeparate(mzFirst, zFirst, string.Empty, string.Empty, nce),
                FieldSeparate(mzLast, zLast, string.Empty, string.Empty, nce));

            // Export Thermo Fusion scheduled Targeted list.
            if (!AsSmallMoleculesNegative) // .skyd file chromatograms are not useful in this conversion due to mass shift
                ExportIsolationList(
                "FusionScheduledTargeted.csv",
                ExportInstrumentType.THERMO_FUSION, FullScanAcquisitionMethod.Targeted, ExportMethodType.Scheduled,
                thermoFusionMassListExporter.GetHeader(_fieldSeparator),
                FieldSeparate(mzFirst, zFirst, t46 - halfWin, t46 + halfWin, nce, slensA),
                FieldSeparate(mzLast, zLast, t39 - halfWin, t39 + halfWin, nce, slensB));

            string fragmentsFirst;
            if (!AsSmallMolecules || AsExplicitRetentionTimes)
                fragmentsFirst = FieldSeparate("582.3190", "951.4782", "595.3086", "708.3927", "837.4353", "1017.5251");
            else if (!AsSmallMoleculesNegative)
                fragmentsFirst = FieldSeparate("582.3190", "595.3086", "708.3927", "837.4353", "951.4782", "1017.5251");
            else
                fragmentsFirst = FieldSeparate("580.3044", "595.3097", "708.3938", "837.4364", "951.4793", "1017.5262");
            string fragmentsLast;
            if (!AsSmallMolecules || AsExplicitRetentionTimes)
                fragmentsLast = FieldSeparate("444.5500", "496.7443", "340.1615", "406.8553", "609.7794", "545.7319");
            else if (!AsSmallMoleculesNegative)
                fragmentsLast = FieldSeparate("340.1615", "406.8553", "444.5500", "455.1885", "488.7104", "496.7443");
            else
                fragmentsLast = FieldSeparate("340.1626", "406.8564", "442.5355", "455.1896", "488.7115", "496.7454");
            var rtFirst = !AsExplicitRetentionTimes
                ? FieldSeparate("45.8", "47.8")
                : FieldSeparate("55.6", "58.0");
            var rtLast = !AsExplicitRetentionTimes
                ? FieldSeparate("38.9", "40.9")
                : FieldSeparate("48.7", "51.1");
            var trapCeFirstTrap = !AsSmallMoleculesNegative
                ? FieldSeparate("21.2", "27.9")
                : FieldSeparate("21.2", "27.8");
            var trapCeLastTrap = !AsSmallMoleculesNegative
                ? FieldSeparate("17.3", "23.0")
                : FieldSeparate("17.2", "23.0");
            var trapCeFirstTransfer = !AsSmallMoleculesNegative
                ? FieldSeparate("26.2", "32.9")
                : FieldSeparate("26.2", "32.8");
            var trapCeLastTransfer = !AsSmallMoleculesNegative
                ? FieldSeparate("22.3", "28.0")
                : FieldSeparate("22.2", "28.0");

            // Export Waters Synapt (trap region) unscheduled Targeted list
            ExportIsolationList(
                "WatersTrapUnscheduledTargeted.mrm",
                ExportInstrumentType.WATERS_SYNAPT_TRAP, FullScanAcquisitionMethod.Targeted, ExportMethodType.Standard,
                WatersIsolationListExporter.GetHeader(_fieldSeparator),
                FieldSeparate(0, "0.0", "30.0", mzFirst.ToString("0.0000", CultureInfo.InvariantCulture), fragmentsFirst, trapCeFirstTrap, "2.0", "2.0", 30, "0.0000", 0, 199),
                FieldSeparate(0, "0.0", "30.0", mzLast.ToString("0.0000", CultureInfo.InvariantCulture), fragmentsLast, trapCeLastTrap, "2.0", "2.0", 30, "0.0000", 0, 199));

            // Export Waters Synapt (trap region) scheduled Targeted list
            ExportIsolationList(
                "WatersTrapScheduledTargeted.mrm",
                ExportInstrumentType.WATERS_SYNAPT_TRAP, FullScanAcquisitionMethod.Targeted, ExportMethodType.Scheduled,
                WatersIsolationListExporter.GetHeader(_fieldSeparator),
                FieldSeparate(0, rtFirst, mzFirst.ToString("0.0000", CultureInfo.InvariantCulture), fragmentsFirst, trapCeFirstTrap, "2.0", "2.0", 30, "0.0000", 0, 199),
                FieldSeparate(0, rtLast, mzLast.ToString("0.0000", CultureInfo.InvariantCulture), fragmentsLast, trapCeLastTrap, "2.0", "2.0", 30, "0.0000", 0, 199));

            // Export Waters Synapt (transfer region) unscheduled Targeted list
            ExportIsolationList(
                "WatersTransferUnscheduledTargeted.mrm",
                ExportInstrumentType.WATERS_SYNAPT_TRANSFER, FullScanAcquisitionMethod.Targeted, ExportMethodType.Standard,
                WatersIsolationListExporter.GetHeader(_fieldSeparator),
                FieldSeparate(0, "0.0", "30.0", mzFirst.ToString("0.0000", CultureInfo.InvariantCulture), fragmentsFirst, "4.0", "4.0", trapCeFirstTransfer, 30, "0.0000", 0, 199),
                FieldSeparate(0, "0.0", "30.0", mzLast.ToString("0.0000", CultureInfo.InvariantCulture), fragmentsLast, "4.0", "4.0", trapCeLastTransfer, 30, "0.0000", 0, 199));

            // Export Waters Synapt (transfer region) scheduled Targeted list
            ExportIsolationList(
                "WatersTransferScheduledTargeted.mrm",
                ExportInstrumentType.WATERS_SYNAPT_TRANSFER, FullScanAcquisitionMethod.Targeted, ExportMethodType.Scheduled,
                WatersIsolationListExporter.GetHeader(_fieldSeparator),
                FieldSeparate(0, rtFirst, mzFirst.ToString("0.0000", CultureInfo.InvariantCulture), fragmentsFirst, "4.0", "4.0", trapCeFirstTransfer, 30, "0.0000", 0, 199),
                FieldSeparate(0, rtLast, mzLast.ToString("0.0000", CultureInfo.InvariantCulture), fragmentsLast, "4.0", "4.0", trapCeLastTransfer, 30, "0.0000", 0, 199));

            // Export Waters Xevo unscheduled Targeted list
            ExportIsolationList(
                "WatersXevoUnscheduledTargeted.mrm",
                ExportInstrumentType.WATERS_XEVO_QTOF, FullScanAcquisitionMethod.Targeted, ExportMethodType.Standard,
                WatersIsolationListExporter.GetHeader(_fieldSeparator),
                FieldSeparate(0, "0.0", "30.0", mzFirst.ToString("0.0000", CultureInfo.InvariantCulture), fragmentsFirst, trapCeFirstTrap, 30, "0.0000", 0, 199),
                FieldSeparate(0, "0.0", "30.0", mzLast.ToString("0.0000", CultureInfo.InvariantCulture), fragmentsLast, trapCeLastTrap, 30, "0.0000", 0, 199));

            // Export Waters Xevo scheduled Targeted list
            ExportIsolationList(
                "WatersXevoScheduledTargeted.mrm",
                ExportInstrumentType.WATERS_XEVO_QTOF, FullScanAcquisitionMethod.Targeted, ExportMethodType.Scheduled,
                WatersIsolationListExporter.GetHeader(_fieldSeparator),
                FieldSeparate(0, rtFirst, mzFirst.ToString("0.0000", CultureInfo.InvariantCulture), fragmentsFirst, trapCeFirstTrap, 30, "0.0000", 0, 199),
                FieldSeparate(0, rtLast, mzLast.ToString("0.0000", CultureInfo.InvariantCulture), fragmentsLast, trapCeLastTrap, 30, "0.0000", 0, 199));

            // Check error if analyzer is not set correctly.
            CheckMassAnalyzer(ExportInstrumentType.AGILENT_TOF, FullScanMassAnalyzerType.tof);
            CheckMassAnalyzer(ExportInstrumentType.THERMO_Q_EXACTIVE, FullScanMassAnalyzerType.orbitrap);
        }
Пример #24
0
        /* TODO bspratt drift time libs for small molecules

        [TestMethod]
        public void WatersImsMsePredictedDriftTimesChromatogramTestAsSmallMolecules()
        {
            WatersImsMseChromatogramTest(DriftFilterType.predictor, true);
        }

        [TestMethod]
        public void WatersImsMseLibraryDriftTimesChromatogramTestAsSmallMolecules()
        {
            WatersImsMseChromatogramTest(DriftFilterType.library, true);
        }

         */
        private void WatersImsMseChromatogramTest(DriftFilterType mode,
            RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules = RefinementSettings.ConvertToSmallMoleculesMode.none)
        {
            string subdir = (asSmallMolecules == RefinementSettings.ConvertToSmallMoleculesMode.none) ? null : asSmallMolecules.ToString();
            var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE, subdir);
            TestSmallMolecules = false; // Don't need that extra magic node

            bool withDriftTimePredictor = (mode == DriftFilterType.predictor); // Load the doc that has a drift time predictor?
            bool withDriftTimeFilter = (mode != DriftFilterType.none); // Perform drift time filtering?  (either with predictor, or with bare times in blib file)
            string docPath;
            SrmDocument document = InitWatersImsMseDocument(testFilesDir, withDriftTimePredictor ? "single_with_driftinfo.sky" : "single_no_driftinfo.sky", asSmallMolecules, out docPath);
            AssertEx.IsDocumentState(document, (withDriftTimePredictor || (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none)) ? 1 : 0, 1, 1, 1, 8); // Drift time lib load bumps the doc version
            var docContainer = new ResultsTestDocumentContainer(document, docPath);
            var doc = docContainer.Document;
            var docOriginal = doc;

            string testModeStr = withDriftTimePredictor ? "with drift time predictor" : "without drift time info";

            if (withDriftTimeFilter && !withDriftTimePredictor)
            {
                // Use the bare drift times in the spectral library
                var librarySpec = new BiblioSpecLiteSpec("drift test",
                                                    testFilesDir.GetTestPath("mse-mobility.filtered-scaled.blib"));
                doc = doc.ChangeSettings(
                    doc.Settings.ChangePeptideLibraries(lib => lib.ChangeLibrarySpecs(new[] { librarySpec })).
                    ChangePeptidePrediction(p => p.ChangeLibraryDriftTimesResolvingPower(100)).
                    ChangePeptidePrediction(p => p.ChangeUseLibraryDriftTimes(true))
                    );
                testModeStr = "with drift times from spectral library";
            }

            var listChromatograms = new List<ChromatogramSet>();
            // A small subset of the QC_HDMSE_02_UCA168_3495_082213 data set (RT 21.5-22.5) from Will Thompson
            const string path = @"waters-mobility.mz5";
            listChromatograms.Add(AssertResult.FindChromatogramSet(doc, new MsDataFilePath(path)) ??
                                    new ChromatogramSet(Path.GetFileName(path).Replace('.', '_'), new[] { path }));
            var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms));
            Assert.IsTrue(docContainer.SetDocument(docResults, docOriginal, true));
            docContainer.AssertComplete();
            document = docContainer.Document;

            float tolerance = (float)document.Settings.TransitionSettings.Instrument.MzMatchTolerance;
            double maxHeight = 0;
            var results = document.Settings.MeasuredResults;
            Assert.AreEqual(1, document.MoleculePrecursorPairs.Count());
            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, testModeStr);
                var chromGroup = chromGroupInfo[0];
                var expectedPeaks = ((asSmallMolecules == RefinementSettings.ConvertToSmallMoleculesMode.masses_only) ? 6 : 5);
                Assert.AreEqual(withDriftTimeFilter ? 3 : expectedPeaks, chromGroup.NumPeaks, testModeStr); // This will be higher if we don't filter on DT
                foreach (var tranInfo in chromGroup.TransitionPointSets)
                {
                    maxHeight = Math.Max(maxHeight, tranInfo.MaxIntensity);
                }
            }
            Assert.AreEqual(withDriftTimeFilter? 5226 : 20075 , maxHeight, 1, testModeStr);  // Without DT filtering, this will be much greater

            // 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(21.94865, (double)nodePep.GetMeasuredRetentionTime(0), .0001, testModeStr);
                    Assert.AreEqual(1.0, (double)nodePep.GetPeakCountRatio(0), 0.0001, testModeStr);
                    nPeptides++;
                }
            }
            Assert.AreEqual(1, nPeptides);

            if (withDriftTimePredictor || withDriftTimeFilter)
            {
                // Verify that the .imdb pr .blib file goes out in the share zipfile
                for (int complete = 0; complete <= 1; complete++)
                {
                    var sharePath = testFilesDir.GetTestPath(complete==1?"share_complete.zip":"share_minimized.zip");
                    var share = new SrmDocumentSharing(document, docPath, sharePath, complete==1);
                    using (var longWaitDlg = new LongWaitDlg
                    {
                        // ReSharper disable once LocalizableElement
                        Text = "unit test WatersImsTest -- sharing document",
                    })
                    {
                        longWaitDlg.PerformWork(null, 1000, share.Share);
                        Assert.IsFalse(longWaitDlg.IsCanceled);
                    }

                    var files = share.ListEntries().ToArray();
                    Assert.IsTrue(files.Contains(withDriftTimePredictor ? "scaled.imdb" : "mse-mobility.filtered-scaled.blib"));
                    // And round trip it to make sure we haven't left out any new features in minimized imdb or blib files
                    using (var longWaitDlg = new LongWaitDlg
                    {
                        // ReSharper disable once LocalizableElement
                        Text = "unit test WatersImsTest",
                    })
                    {
                        longWaitDlg.PerformWork(null, 1000, share.Extract);
                        Assert.IsFalse(longWaitDlg.IsCanceled);
                    }
                    using (TextReader reader = new StreamReader(share.DocumentPath))
                    {
                        XmlSerializer documentSerializer = new XmlSerializer(typeof(SrmDocument));
                        var document2 = (SrmDocument) documentSerializer.Deserialize(reader);
                        Assert.IsNotNull(document2);
                        var im = document.Settings.GetIonMobilities(new MsDataFilePath(path));
                        var pep = document2.Molecules.First();
                        foreach (TransitionGroupDocNode nodeGroup in pep.Children)
                        {
                            double windowDT;
                            var centerDriftTime = document.Settings.PeptideSettings.Prediction.GetDriftTime(
                                                       pep, nodeGroup, im, out windowDT);
                            Assert.AreEqual(3.86124, centerDriftTime.DriftTimeMsec(false) ?? 0, .0001, testModeStr);
                            Assert.AreEqual(0.077224865797235934, windowDT, .0001, testModeStr);
                        }
                    }
                }
            }

            // Release file handles
            docContainer.Release();
            testFilesDir.Dispose();
            string cachePath = ChromatogramCache.FinalPathForName(docPath, null);
            FileEx.SafeDelete(cachePath);
        }
        protected override void DoTest()
        {
            // Lest we get "To export a scheduled method, you must first choose a retention time predictor in Peptide Settings / Prediction, or import results for all peptides in the document."
            TestSmallMolecules = false;

            // Skyline Collision Energy Optimization
            RunUI(() => SkylineWindow.OpenFile(GetTestPath("CE_Vantage_15mTorr.sky"))); // Not L10N

            if (AsSmallMolecules)
            {
                var doc = WaitForDocumentLoaded();
                var refine = new RefinementSettings();
                SkylineWindow.SetDocument(refine.ConvertToSmallMolecules(doc), doc);
            }

            // Deriving a New Linear Equation, p. 2
            var transitionSettingsUI = ShowDialog<TransitionSettingsUI>(SkylineWindow.ShowTransitionSettingsUI);
            var editList =
                ShowDialog<EditListDlg<SettingsListBase<CollisionEnergyRegression>, CollisionEnergyRegression>>
                (transitionSettingsUI.EditCEList);
            RunUI(() => editList.SelectItem("Thermo")); // Not L10N
            EditCEDlg editItem = ShowDialog<EditCEDlg>(editList.EditItem);

            PauseForScreenShot<EditCEDlg>("Edit Collision Energy Equation form", 3);

            ChargeRegressionLine regressionLine2 = new ChargeRegressionLine(2, 0.034, 3.314);
            ChargeRegressionLine regressionLine3 = new ChargeRegressionLine(3, 0.044, 3.314);

            CheckRegressionLines(new[] {regressionLine2, regressionLine3}, editItem.Regression.Conversions);

            RunUI(() =>
            {
                editItem.DialogResult = DialogResult.OK;
                editList.DialogResult = DialogResult.Cancel;
                transitionSettingsUI.DialogResult = DialogResult.Cancel;
            });
            WaitForClosedForm(transitionSettingsUI);

            // Measuring Retention Times for Method Scheduling, p. 3
            {
                var exportMethodDlg = ShowDialog<ExportMethodDlg>(() => SkylineWindow.ShowExportMethodDialog(ExportFileType.List));
                RunUI(() =>
                {
                    exportMethodDlg.InstrumentType = ExportInstrumentType.THERMO;
                    exportMethodDlg.ExportStrategy = ExportStrategy.Single;
                    exportMethodDlg.OptimizeType = ExportOptimize.NONE;
                    exportMethodDlg.MethodType = ExportMethodType.Standard;
                });

                PauseForScreenShot<ExportMethodDlg.TransitionListView>("Export Transition List form", 4);

                RunUI(() => exportMethodDlg.OkDialog(GetTestPath("CE_Vantage_15mTorr_unscheduled.csv"))); // Not L10N
                WaitForClosedForm(exportMethodDlg);
            }

            string filePathTemplate = GetTestPath("CE_Vantage_15mTorr_unscheduled.csv"); // Not L10N
            CheckTransitionList(filePathTemplate, 1, 6);

            const string unscheduledName = "Unscheduled"; // Not L10N
            RunDlg<ImportResultsDlg>(SkylineWindow.ImportResults, importResultsDlg =>
            {
                importResultsDlg.RadioAddNewChecked = true;
                var path =
                    new[] {new KeyValuePair<string, MsDataFileUri[]>(unscheduledName,
                        // This is not actually a valid file path (missing OptimizeCE)
                        // but Skyline should correctly find the file in the same folder
                        // as the document.
                        new[] { MsDataFileUri.Parse(GetTestPath("CE_Vantage_15mTorr_unscheduled" + ExtThermoRaw))})}; // Not L10N
                importResultsDlg.NamedPathSets = path;
                importResultsDlg.OkDialog();
            });
            WaitForCondition(5*60*1000, () => SkylineWindow.Document.Settings.MeasuredResults.IsLoaded);    // 5 minutes
            AssertEx.IsDocumentState(SkylineWindow.Document, null, 7, 27, 30, 120);
            var docUnsched = SkylineWindow.Document;
            AssertResult.IsDocumentResultsState(SkylineWindow.Document,
                                                unscheduledName,
                                                docUnsched.MoleculeCount,
                                                docUnsched.MoleculeTransitionGroupCount, 0,
                                                docUnsched.MoleculeTransitionCount - 1, 0);

            RunUI(() =>
            {
                SkylineWindow.ExpandProteins();
                SkylineWindow.ExpandPeptides();
            });

            PauseForScreenShot("Main Skyline window", 5);

            // Creating Optimization Methods, p. 5
            {
                var exportMethodDlg = ShowDialog<ExportMethodDlg>(() => SkylineWindow.ShowExportMethodDialog(ExportFileType.List));
                RunUI(() =>
                {
                    exportMethodDlg.InstrumentType = ExportInstrumentType.THERMO;
                    exportMethodDlg.ExportStrategy = ExportStrategy.Buckets;
                    exportMethodDlg.MaxTransitions = 110;
                    exportMethodDlg.IgnoreProteins = true;
                    exportMethodDlg.OptimizeType = ExportOptimize.CE;
                    exportMethodDlg.MethodType = ExportMethodType.Scheduled;
                });

                PauseForScreenShot<ExportMethodDlg.TransitionListView>("Export Transition List form", 6);

                RunUI(() => exportMethodDlg.OkDialog(GetTestPath("CE_Vantage_15mTorr.csv"))); // Not L10N
                WaitForClosedForm(exportMethodDlg);
            }

            string filePathTemplate1 = GetTestPath("CE_Vantage_15mTorr_000{0}.csv"); // Not L10N
            CheckTransitionList(filePathTemplate1, 5, 9);

            var filePath = GetTestPath("CE_Vantage_15mTorr_0001.csv"); // Not L10N
            CheckCEValues(filePath, 11);

            // Analyze Optimization Data, p. 7
            RunDlg<ImportResultsDlg>(SkylineWindow.ImportResults, importResultsDlg =>
            {
                importResultsDlg.RadioAddNewChecked = true;
                importResultsDlg.OptimizationName = ExportOptimize.CE;
                importResultsDlg.NamedPathSets = DataSourceUtil.GetDataSourcesInSubdirs(TestFilesDirs[0].FullPath).ToArray();
                importResultsDlg.NamedPathSets[0] =
                     new KeyValuePair<string, MsDataFileUri[]>("Optimize CE", importResultsDlg.NamedPathSets[0].Value.Take(5).ToArray()); // Not L10N
                importResultsDlg.OkDialog();
            });
            RunUI(() =>
            {
                SkylineWindow.ShowSingleTransition();
                SkylineWindow.AutoZoomBestPeak();
                SkylineWindow.ShowPeakAreaReplicateComparison();
            });

            if (AsSmallMolecules)
            {
                return;  // Too peptide-centric from here to end of test
            }

            FindNode("IHGFDLAAINLQR");
            RestoreViewOnScreen(8);
            WaitForCondition(15*60*1000, () => SkylineWindow.Document.Settings.MeasuredResults.IsLoaded); // 10 minutes

            PauseForScreenShot("Main Skyline window", 8);

            // p. 8
            // Not L10N
            RemovePeptide("EGIHAQQK");

            FindNode("IDALNENK");

            RunUI(() => SkylineWindow.NormalizeAreaGraphTo(AreaNormalizeToView.area_percent_view));

            PauseForScreenShot("Main Skyline window", 9);

            RunUI(SkylineWindow.EditDelete);

            RemovePeptide("LICDNTHITK");

            // Creating a New Equation for CE, p. 9
            var transitionSettingsUI1 = ShowDialog<TransitionSettingsUI>(SkylineWindow.ShowTransitionSettingsUI);
            var editCEDlg1 = ShowDialog<EditListDlg<SettingsListBase<CollisionEnergyRegression>, CollisionEnergyRegression>>(transitionSettingsUI1.EditCEList);
            var addItem = ShowDialog<EditCEDlg>(editCEDlg1.AddItem);
            RunUI(() =>
            {
                addItem.RegressionName = "Thermo Vantage Tutorial"; // Not L10N
                addItem.UseCurrentData();
            });

            var graphRegression = ShowDialog<GraphRegression>(addItem.ShowGraph);

            PauseForScreenShot<GraphRegression>("Collision Energy Regression graphs", 10);

            var graphDatas = graphRegression.RegressionGraphDatas.ToArray();
            Assert.AreEqual(2, graphDatas.Length);

            ChargeRegressionLine regressionLine21 = new ChargeRegressionLine(2, 0.0305, 2.5061);
            ChargeRegressionLine regressionLine31 = new ChargeRegressionLine(3, 0.0397, 1.4217);
            var expectedRegressions = new[] {regressionLine21, regressionLine31};

            CheckRegressionLines(expectedRegressions, new[]
                                                          {
                                                              new ChargeRegressionLine(2,
                                                                  Math.Round(graphDatas[0].RegressionLine.Slope, 4),
                                                                  Math.Round(graphDatas[0].RegressionLine.Intercept, 4)),
                                                              new ChargeRegressionLine(3,
                                                                  Math.Round(graphDatas[1].RegressionLine.Slope, 4),
                                                                  Math.Round(graphDatas[1].RegressionLine.Intercept, 4)),
                                                          });

            RunUI(graphRegression.CloseDialog);
            WaitForClosedForm(graphRegression);
            RunUI(addItem.OkDialog);
            WaitForClosedForm(addItem);
            RunUI(editCEDlg1.OkDialog);
            WaitForClosedForm(editCEDlg1);
            RunUI(transitionSettingsUI1.OkDialog);
            WaitForClosedForm(transitionSettingsUI1);

            // Optimizing Each Transition, p. 10
            RunDlg<TransitionSettingsUI>(SkylineWindow.ShowTransitionSettingsUI, transitionSettingsUI2 =>
            {
                transitionSettingsUI2.UseOptimized = true;
                transitionSettingsUI2.OptimizeType = OptimizedMethodType.Transition.GetLocalizedString();
                transitionSettingsUI2.OkDialog();
            });
            RunDlg<ExportMethodDlg>(() => SkylineWindow.ShowExportMethodDialog(ExportFileType.List), exportMethodDlg =>
            {
                exportMethodDlg.ExportStrategy = ExportStrategy.Single;
                exportMethodDlg.OkDialog(GetTestPath("CE_Vantage_15mTorr_optimized.csv")); // Not L10N
            });

            var filePathTemplate2 = GetTestPath("CE_Vantage_15mTorr_optimized.csv"); // Not L10N

            CheckTransitionList(filePathTemplate2, 1, 9);

            RunUI(() => SkylineWindow.SaveDocument());
            WaitForConditionUI(() => !SkylineWindow.Dirty);
        }
 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);
     }));
 }
Пример #27
0
 private void ExportWithExplicitCollisionEnergyValues(string pathList)
 {
     var original = SkylineWindow.Document;
     var refine = new RefinementSettings();
     var document = refine.ConvertToSmallMolecules(original);
     for (var loop = 0; loop < 2; loop++)
     {
         SkylineWindow.SetDocument(document, SkylineWindow.Document);
         var exportMethodDlg = ShowDialog<ExportMethodDlg>(() => SkylineWindow.ShowExportMethodDialog(ExportFileType.List));
         RunUI(() =>
         {
             exportMethodDlg.InstrumentType = ExportInstrumentType.THERMO_QUANTIVA;
             exportMethodDlg.OptimizeType = ExportOptimize.CE;
             exportMethodDlg.MethodType = ExportMethodType.Standard;
         });
         RunUI(() => exportMethodDlg.OkDialog(pathList));
         WaitForClosedForm(exportMethodDlg);
         var actual = File.ReadAllLines(pathList);
         if (loop == 1)
         {
             // Explicit CE values
             Assert.AreEqual(document.MoleculeTransitionCount+1, actual.Length); // Should be just one line per transition, and a header
             break;
         }
         else
         {
             Assert.AreEqual(document.MoleculeTransitionCount*11 + 1, actual.Length); // Multiple steps, and a header
         }
         // Change the current document to use explicit CE values, verify that this changes the output
         var ce = 1;
         for (bool changing = true; changing; )
         {
             changing = false;
             foreach (var peptideGroupDocNode in document.MoleculeGroups)
             {
                 var pepGroupPath = new IdentityPath(IdentityPath.ROOT, peptideGroupDocNode.Id);
                 foreach (var nodePep in peptideGroupDocNode.Molecules)
                 {
                     var pepPath = new IdentityPath(pepGroupPath, nodePep.Id);
                     foreach (var nodeTransitionGroup in nodePep.TransitionGroups)
                     {
                         if (!nodeTransitionGroup.ExplicitValues.CollisionEnergy.HasValue)
                         {
                             var tgPath = new IdentityPath(pepPath, nodeTransitionGroup.Id);
                             document = (SrmDocument)document.ReplaceChild(tgPath.Parent,
                                 nodeTransitionGroup.ChangeExplicitValues(nodeTransitionGroup.ExplicitValues.ChangeCollisionEnergy(ce++)));
                             changing = true;
                             break;
                         }
                     }
                 }
                 if (changing)
                     break;
             }
         }
     }
     SkylineWindow.SetDocument(original, SkylineWindow.Document);
 }
Пример #28
0
 public static SrmDocument ChangeAutoManageChildren(SrmDocument document, PickLevel which, bool autoPick)
 {
     var refine = new RefinementSettings { AutoPickChildrenAll = which, AutoPickChildrenOff = !autoPick };
     return refine.Refine(document);
 }