コード例 #1
0
ファイル: RefineTest.cs プロジェクト: suchp-max/proteowizard
        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();
        }
コード例 #2
0
ファイル: RefineTest.cs プロジェクト: rfellers/pwiz
        public void RefineDocumentTest()
        {
            var document = InitRefineDocument(RefinementSettings.ConvertToSmallMoleculesMode.none);

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

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

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

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

            // Try settings that remove everything from the document
            refineSettings = new RefinementSettings {
                MinPeptidesPerProtein = 20
            };
            Assert.AreEqual(0, refineSettings.Refine(document).PeptideGroupCount);
            refineSettings.MinPeptidesPerProtein      = 1;
            refineSettings.MinTransitionsPepPrecursor = 20;
            Assert.AreEqual(0, refineSettings.Refine(document).PeptideGroupCount);
        }
コード例 #3
0
        public static SrmDocument ChangeAutoManageChildren(SrmDocument document, PickLevel which, bool autoPick)
        {
            var refine = new RefinementSettings {
                AutoPickChildrenAll = which, AutoPickChildrenOff = !autoPick
            };

            return(refine.Refine(document));
        }
コード例 #4
0
ファイル: SrmDocEditTest.cs プロジェクト: rfellers/pwiz
        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);
        }
コード例 #5
0
        public void RefineResultsTest()
        {
            Settings.Default.RTCalculatorName = Settings.Default.RTScoreCalculatorList.GetDefaults().First().Name;

            var document = InitRefineDocument(RefinementSettings.ConvertToSmallMoleculesMode.none);

            // 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].IsEmpty)
                {
                    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.ChangeModifications(IsotopeLabelType.heavy, 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.PrecursorAdduct,
                                heavyGroup.TransitionGroup.PrecursorAdduct);
                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);
                }
            }
        }
コード例 #6
0
        public void RunTestFindNode(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules)
        {
            if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none)
            {
                TestDirectoryName = asSmallMolecules.ToString();
            }

            SrmDocument doc = CreateStudy7Doc();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            docMulti = (new RefinementSettings()).ConvertToSmallMolecules(docMulti, TestContext.TestDir, 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));
        }
コード例 #7
0
        private void DoFullScanFilterTest(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules,
                                          out List <SrmDocument> docCheckpoints, bool centroided = false)
        {
            docCheckpoints = new List <SrmDocument>();

            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(ref 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)));
            }
            using (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
                Assume.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(ref docPath, 1, ref expectedPepCount, ref expectedTransGroupCount, ref expectedTransCount, asSmallMolecules);
                docCheckpoints.Add(doc);
                Assume.AreEqual(FullScanMassAnalyzerType.orbitrap, doc.Settings.TransitionSettings.FullScan.ProductMassAnalyzer);
                // Make sure saving this type of document works
                AssertEx.Serializable(doc, AssertEx.DocumentCloned);
                Assume.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(ref docPath, 3, ref expectedPepCount, ref expectedTransGroupCount, ref expectedTransCount, asSmallMolecules);
                Assume.AreEqual(FullScanMassAnalyzerType.none, doc.Settings.TransitionSettings.FullScan.ProductMassAnalyzer);
                Assume.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);
                Assume.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.MoleculeTransitions)
                {
                    Assume.IsTrue(nodeTran.HasResults);
                    Assume.IsNotNull(nodeTran.Results[0]);
                    if (410 > nodeTran.Mz || nodeTran.Mz > 910)
                    {
                        Assume.IsTrue(nodeTran.Results[0][0].IsForcedIntegration);
                    }
                    else
                    {
                        Assume.IsFalse(nodeTran.Results[0][0].IsForcedIntegration);
                    }
                }

                // 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));

                if (asSmallMolecules == RefinementSettings.ConvertToSmallMoleculesMode.masses_only)
                {
                    return; // Can't work with isotope distributions when we don't have ion formulas
                }
                int indexResults       = listResults.Count - 1;
                var matchIdentifierDRV = "DRV";
                if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none)
                {
                    matchIdentifierDRV = RefinementSettings.TestingConvertedFromProteomicPeptideNameDecorator + matchIdentifierDRV;
                }
                int index = 0;
                foreach (var nodeTran in docContainer.Document.MoleculeTransitions)
                {
                    Assume.IsTrue(nodeTran.HasResults);
                    Assume.AreEqual(listResults.Count, nodeTran.Results.Count);
                    var peptide = nodeTran.Transition.Group.Peptide;

                    if (peptide.IsCustomMolecule && index == 24)
                    {
                        // Conversion to small molecule loses some of the nuance of "Sequence" vs "FastaSequence", comparisons are inexact
                        Assume.AreEqual("pep_DRVY[+80.0]IHPF", nodeTran.PrimaryCustomIonEquivalenceKey);
                        break;
                    }

                    // DRV without FASTA sequence should not have data for non-precursor transitions
                    if (!peptide.TextId.StartsWith(matchIdentifierDRV) ||
                        (!peptide.IsCustomMolecule && !peptide.Begin.HasValue))
                    {
                        Assume.IsNotNull(nodeTran.Results[indexResults]);
                        Assume.IsFalse(nodeTran.Results[indexResults][0].IsEmpty);
                    }
                    else if (nodeTran.Transition.IonType != IonType.precursor)
                    {
                        Assert.IsTrue(nodeTran.Results[indexResults].IsEmpty);
                    }
                    else
                    {
                        // Random, bogus peaks chosen in both files
                        Assume.IsNotNull(nodeTran.Results[indexResults]);
                        Assume.AreEqual(2, nodeTran.Results[indexResults].Count);
                        Assume.IsFalse(nodeTran.Results[indexResults][0].IsEmpty);
                        Assume.IsFalse(nodeTran.Results[indexResults][1].IsEmpty);
                    }
                    index++;
                }

                // 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(ref docPath, 2, ref expectedPepCount, ref expectedTransGroupCount, ref expectedTransCount, asSmallMolecules);
                Assume.AreEqual(FullScanMassAnalyzerType.none, doc.Settings.TransitionSettings.FullScan.ProductMassAnalyzer);
                Assume.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, IsotopeEnrichmentsList.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, IsotopeEnrichmentsList.DEFAULT)
                                                                                                      .ChangePrecursorResolution(FullScanMassAnalyzerType.centroided, ppm, 0)));
                AssertEx.Serializable(docNoCentroid, AssertEx.DocumentCloned);
                Assume.IsTrue(docContainer.SetDocument(docNoCentroid, docContainer.Document));
                const double mzTest      = 400.0;
                var          filterWidth = docNoCentroid.Settings.TransitionSettings.FullScan.GetPrecursorFilterWindow(mzTest);
                Assume.AreEqual(mzTest * 2.0 * ppm * 1E-6, filterWidth);

                // Verify relationship between normal and high-selectivity extraction
                var docTofNormal = docNoCentroid.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fs =>
                                                                                                      fs.ChangePrecursorResolution(FullScanMassAnalyzerType.tof, 50 * 1000, null)));
                AssertEx.Serializable(docTofNormal, AssertEx.DocumentCloned);
                var docTofSelective = docTofNormal.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fs =>
                                                                                                        fs.ChangePrecursorResolution(FullScanMassAnalyzerType.tof, 25 * 1000, null)
                                                                                                        .ChangeUseSelectiveExtraction(true)));
                AssertEx.Serializable(docTofSelective, AssertEx.DocumentCloned);
                var filterWidthTof       = docTofNormal.Settings.TransitionSettings.FullScan.GetPrecursorFilterWindow(mzTest);
                var filterWidthSelective = docTofSelective.Settings.TransitionSettings.FullScan.GetPrecursorFilterWindow(mzTest);
                Assume.AreEqual(filterWidth, filterWidthTof);
                Assume.AreEqual(filterWidth, filterWidthSelective);


                // 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) }),
                    };
                    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_, filePath));

                // Import FT data with only MS1
                docPath                 = testFilesDir.GetTestPath("Yeast_HI3 Peptides_test.sky");
                expectedPepCount        = 2;
                expectedTransGroupCount = 2;
                expectedTransCount      = 2;
                doc = InitFullScanDocument(ref docPath, 2, ref expectedPepCount, ref expectedTransGroupCount, ref expectedTransCount, asSmallMolecules);
                Assume.AreEqual(FullScanMassAnalyzerType.none, doc.Settings.TransitionSettings.FullScan.ProductMassAnalyzer);
                Assume.AreEqual(FullScanMassAnalyzerType.none, doc.Settings.TransitionSettings.FullScan.PrecursorMassAnalyzer);
                var docMs1 = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fs =>
                                                                                      fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Count, 1, IsotopeEnrichmentsList.DEFAULT)
                                                                                      .ChangePrecursorResolution(FullScanMassAnalyzerType.tof, 50 * 1000, null)));
                Assume.AreEqual(filterWidth, docMs1.Settings.TransitionSettings.FullScan.GetPrecursorFilterWindow(mzTest));
                docMs1 = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fs =>
                                                                                  fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Count, 1, IsotopeEnrichmentsList.DEFAULT)
                                                                                  .ChangePrecursorResolution(FullScanMassAnalyzerType.ft_icr, 50 * 1000, mzTest)));
                AssertEx.Serializable(docMs1, AssertEx.DocumentCloned);
                Assume.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.
                var matchIdentifierLVN = "LVN";
                if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none)
                {
                    matchIdentifierLVN = RefinementSettings.TestingConvertedFromProteomicPeptideNameDecorator + matchIdentifierLVN;
                }
                foreach (var nodeTranGroup in docContainer.Document.MoleculeTransitionGroups)
                {
                    foreach (var docNode in nodeTranGroup.Children)
                    {
                        var nodeTran = (TransitionDocNode)docNode;
                        Assume.IsTrue(nodeTran.HasResults);
                        Assume.AreEqual(1, nodeTran.Results.Count);
                        if (nodeTran.Transition.Group.Peptide.Target.ToString().StartsWith(matchIdentifierLVN))
                        {
                            Assume.IsFalse(nodeTran.Results[0][0].IsEmpty);
                        }
                        else
                        {
                            Assume.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;
                        Assume.IsTrue(nodeTran.HasResults);
                        Assume.AreEqual(2, nodeTran.Results.Count);
                        if (nodeTran.Transition.Group.Peptide.Target.ToString().StartsWith(matchIdentifierLVN))
                        {
                            Assume.IsTrue(nodeTran.Results[1][0].IsEmpty);
                        }
                        else
                        {
                            Assume.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, IsotopeEnrichmentsList.DEFAULT))
                                                                          .ChangeTransitionFilter(filter => filter.ChangePeptideIonTypes(new[] { IonType.precursor })
                                                                                                  .ChangeSmallMoleculeIonTypes(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, IsotopeEnrichmentsList.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].IsEmpty && !tranM1.Results[1].IsEmpty);
                Assert.IsTrue(tranM1.Results[0][0].IsEmpty && tranM1.Results[1][0].IsForcedIntegration);
                tranM1 = ms1AllTranstions[5];
                Assert.AreEqual(-1, tranM1.Transition.MassIndex);
                Assert.IsTrue(!tranM1.Results[0].IsEmpty && !tranM1.Results[1].IsEmpty);
                Assert.IsTrue(tranM1.Results[0][0].IsForcedIntegration && tranM1.Results[1][0].IsEmpty);
            }
        }