Ejemplo n.º 1
0
        private void AssertChromatogramWindow(SrmDocument document, ChromatogramSet chromatogramSet,
                                              double expectedStartTime, double expectedEndTime, params ChromatogramGroupInfo[] chromGroupInfos)
        {
            ChromatogramGroupInfo[] basePeakChromatograms;
            Assert.IsTrue(document.Settings.MeasuredResults.TryLoadAllIonsChromatogram(chromatogramSet, ChromExtractor.base_peak, true,
                                                                                       out basePeakChromatograms));
            if (basePeakChromatograms.Length > 0)
            {
                double runStartTime = basePeakChromatograms.Min(chromGroup => chromGroup.Times[0]);
                double runEndTime   =
                    basePeakChromatograms.Max(chromGroup => chromGroup.Times[chromGroup.Times.Length - 1]);
                expectedStartTime = Math.Max(runStartTime, expectedStartTime);
                expectedEndTime   = Math.Min(runEndTime, expectedEndTime);
            }
            const double delta = .15;

            foreach (var chromGroupInfo in chromGroupInfos)
            {
                double startTime = chromGroupInfo.Times[0];
                double endTime   = chromGroupInfo.Times[chromGroupInfo.Times.Length - 1];
                if (Math.Abs(expectedStartTime - startTime) > delta)
                {
                    Assert.AreEqual(expectedStartTime, startTime, delta);
                }
                if (Math.Abs(expectedEndTime - endTime) > delta)
                {
                    Assert.AreEqual(expectedEndTime, endTime, delta);
                }
            }
        }
Ejemplo n.º 2
0
 public Key(SrmDocument document, ChromatogramSet chromatogramSet, MsDataFileUri filePath, IdentityPath precursorIdentityPath)
 {
     _documentReference     = document.ReferenceId;
     _chromatogramSet       = chromatogramSet;
     _filePath              = filePath;
     _precursorIdentityPath = precursorIdentityPath;
 }
Ejemplo n.º 3
0
            public SummaryPeptidePeakData(SrmDocument document,
                                          PeptideDocNode nodePep,
                                          IList <TransitionGroupDocNode> nodeGroups,
                                          ChromatogramSet chromatogramSet,
                                          ChromatogramGroupInfo chromGroupInfoPrimary)
            {
                _peakIndex             = -1;
                _chromGroupInfoPrimary = chromGroupInfoPrimary;

                NodePep  = nodePep;
                FileInfo = chromatogramSet.GetFileInfo(chromGroupInfoPrimary);
                TransitionGroupPeakData = new SummaryTransitionGroupPeakData[nodeGroups.Count];
                for (int i = 0; i < nodeGroups.Count; i++)
                {
                    TransitionGroupPeakData[i] = new SummaryTransitionGroupPeakData(document,
                                                                                    nodePep, nodeGroups[i], chromatogramSet, chromGroupInfoPrimary);
                }
                // Avoid extra ToArray() calls, since they show up in a profiler for big files
                bool?standard;

                if (AllSameStandardType(TransitionGroupPeakData, out standard))
                {
                    AnalyteGroupPeakData  = standard.HasValue && !standard.Value ? TransitionGroupPeakData : EMPTY_DATA;
                    StandardGroupPeakData = standard.HasValue && standard.Value ? TransitionGroupPeakData : EMPTY_DATA;
                }
                else
                {
                    AnalyteGroupPeakData  = TransitionGroupPeakData.Where(t => !t.IsStandard).ToArray();
                    StandardGroupPeakData = TransitionGroupPeakData.Where(t => t.IsStandard).ToArray();
                }
            }
Ejemplo n.º 4
0
        private string[] FindMissingFiles(IEnumerable <ChromatogramSet> chromatogramSets)
        {
            string documentPath = DocumentUIContainer.DocumentFilePath;
            string cachePath    = ChromatogramCache.FinalPathForName(documentPath, null);

            // Collect all missing paths
            var listPathsMissing = new List <string>();
            // Avoid checking paths multiple times for existence
            var setPaths = new HashSet <string>();

            foreach (var filePath in chromatogramSets.SelectMany(set => set.MSDataFilePaths))
            {
                MsDataFilePath msDataFilePath = filePath as MsDataFilePath;
                if (null == msDataFilePath)
                {
                    continue;
                }
                string filePathPart = msDataFilePath.FilePath;
                if (setPaths.Contains(filePathPart))
                {
                    continue;
                }
                setPaths.Add(filePathPart);
                if (ChromatogramSet.GetExistingDataFilePath(cachePath, msDataFilePath) != null)
                {
                    continue;
                }
                listPathsMissing.Add(filePathPart);
            }
            listPathsMissing.Sort();
            return(listPathsMissing.ToArray());
        }
Ejemplo n.º 5
0
        public static void MatchChromatograms(ResultsTestDocumentContainer docContainer,
                                              MsDataFileUri path1, MsDataFileUri path2, int delta, int missing,
                                              LockMassParameters lockMassParameters = null)
        {
            var doc = docContainer.Document;
            var listChromatograms = new List <ChromatogramSet>();

            foreach (var path in new[] { path1, path2 })
            {
                var setAdd = FindChromatogramSet(doc, path);
                if (setAdd == null)
                {
                    string addName = (path.GetFileName() ?? "").Replace('.', '_');
                    addName = Helpers.GetUniqueName(addName, n => listChromatograms.All(set => n != set.Name));
                    setAdd  = new ChromatogramSet(addName, new[] { path });
                }
                listChromatograms.Add(setAdd);
            }
            var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms));

            Assert.IsTrue(docContainer.SetDocument(docResults, doc, true));
            docContainer.AssertComplete();
            docResults = docContainer.Document;
            MatchChromatograms(docResults, 0, 1, delta, missing);
        }
Ejemplo n.º 6
0
        public ChromatogramGroupInfo GetChromatogramGroupInfo(SrmDocument document,
                                                              ChromatogramSet chromatogramSet, MsDataFileUri filePath,
                                                              IdentityPath precursorIdentityPath, bool loadPoints)
        {
            var key       = new Key(document, chromatogramSet, filePath, precursorIdentityPath);
            var cacheSlot = loadPoints ? _withPoints : _withoutPoints;

            if (cacheSlot != null && Equals(key, cacheSlot.Item1))
            {
                return(cacheSlot.Item2);
            }
            var chromatogramGroupInfo = LoadChromatogramInfo(document, chromatogramSet, filePath, precursorIdentityPath,
                                                             loadPoints);

            cacheSlot = Tuple.Create(key, chromatogramGroupInfo);
            if (loadPoints)
            {
                _withPoints = cacheSlot;
            }
            else
            {
                _withoutPoints = cacheSlot;
            }
            return(chromatogramGroupInfo);
        }
Ejemplo n.º 7
0
        public void MsDataFileUriEncodingTest()
        {
            var fname               = "test.mzML";
            var pathSample          = SampleHelp.EncodePath(fname, null, -1, null, true, false);
            var lockmassParametersA = new LockMassParameters(1.23, 3.45, 4.56);
            var lockmassParametersB = new LockMassParameters(1.23, null, 4.56);

            Assert.IsTrue(lockmassParametersA.CompareTo(LockMassParameters.EMPTY) > 0);
            Assert.IsTrue(lockmassParametersA.CompareTo(null) < 0);
            Assert.IsTrue(lockmassParametersB.CompareTo(lockmassParametersA) < 0);
            Assert.IsTrue(lockmassParametersA.CompareTo(new LockMassParameters(1.23, 3.45, 4.56)) == 0);


            var c = new ChromatogramSet("test", new[] { MsDataFileUri.Parse(pathSample) });

            Assert.AreEqual(fname, c.MSDataFilePaths.First().GetFilePath());
            Assert.IsTrue(c.MSDataFilePaths.First().GetCentroidMs1());
            Assert.IsFalse(c.MSDataFilePaths.First().GetCentroidMs2());

            pathSample = SampleHelp.EncodePath(fname, null, -1, lockmassParametersA, false, true);
            c          = new ChromatogramSet("test", new[] { MsDataFileUri.Parse(pathSample) });
            Assert.AreEqual(lockmassParametersA, c.MSDataFilePaths.First().GetLockMassParameters());
            Assert.IsTrue(c.MSDataFilePaths.First().GetCentroidMs2());
            Assert.IsFalse(c.MSDataFilePaths.First().GetCentroidMs1());

            pathSample = SampleHelp.EncodePath(fname, "test_0", 1, lockmassParametersB, false, false);
            c          = new ChromatogramSet("test", new[] { MsDataFileUri.Parse(pathSample) });
            Assert.AreEqual(lockmassParametersB, c.MSDataFilePaths.First().GetLockMassParameters());
            Assert.AreEqual("test_0", c.MSDataFilePaths.First().GetSampleName());
            Assert.AreEqual(1, c.MSDataFilePaths.First().GetSampleIndex());
            Assert.IsFalse(c.MSDataFilePaths.First().GetCentroidMs1());
            Assert.IsFalse(c.MSDataFilePaths.First().GetCentroidMs2());
        }
Ejemplo n.º 8
0
        private ChromatogramGroupInfo LoadChromatogramInfo(SrmDocument document, ChromatogramSet chromatogramSet, MsDataFileUri filePath,
                                                           IdentityPath precursorIdentityPath, bool loadPoints)
        {
            var measuredResults = document.Settings.MeasuredResults;

            if (null == measuredResults)
            {
                return(null);
            }
            var tolerance        = (float)document.Settings.TransitionSettings.Instrument.MzMatchTolerance;
            var peptideDocNode   = (PeptideDocNode)document.FindNode(precursorIdentityPath.Parent);
            var precursorDocNode = (TransitionGroupDocNode)peptideDocNode.FindNode(precursorIdentityPath.Child);

            ChromatogramGroupInfo[] chromatogramGroupInfos;
            if (!measuredResults.TryLoadChromatogram(chromatogramSet, peptideDocNode, precursorDocNode, tolerance, loadPoints,
                                                     out chromatogramGroupInfos))
            {
                return(null);
            }
            foreach (var chromatogramGroupInfo in chromatogramGroupInfos)
            {
                if (Equals(chromatogramGroupInfo.FilePath, filePath))
                {
                    return(chromatogramGroupInfo);
                }
            }
            return(null);
        }
Ejemplo n.º 9
0
 private AlignToFileOp(ChromatogramSet chromatogramSet, ChromFileInfo chromFileInfo,
                       FileRetentionTimeAlignments fileRetentionTimeAlignments, IDictionary <ChromFileInfoId, Tuple <ChromatogramSet, ChromFileInfo> > chromSetInfos)
 {
     ChromatogramSet             = chromatogramSet;
     ChromFileInfo               = chromFileInfo;
     FileRetentionTimeAlignments = fileRetentionTimeAlignments;
     _chromSetInfos              = chromSetInfos;
 }
Ejemplo n.º 10
0
            public SummaryTransitionGroupPeakData(SrmDocument document,
                                                  PeptideDocNode nodePep,
                                                  TransitionGroupDocNode nodeGroup,
                                                  ChromatogramSet chromatogramSet,
                                                  ChromatogramGroupInfo chromGroupInfoPrimary)
            {
                _peakIndex = -1;

                NodeGroup  = nodeGroup;
                IsStandard = document.Settings.PeptideSettings.Modifications.InternalStandardTypes
                             .Contains(nodeGroup.TransitionGroup.LabelType);
                TransitionPeakData = Ms1TranstionPeakData = Ms2TranstionPeakData = EMPTY_DATA;

                ChromatogramGroupInfo[] arrayChromInfo;
                var   measuredResults  = document.Settings.MeasuredResults;
                float mzMatchTolerance = (float)document.Settings.TransitionSettings.Instrument.MzMatchTolerance;

                if (measuredResults.TryLoadChromatogram(chromatogramSet, nodePep, nodeGroup, mzMatchTolerance, false,
                                                        out arrayChromInfo))
                {
                    _chromGroupInfo = arrayChromInfo.FirstOrDefault(ci =>
                                                                    Equals(ci.FilePath, chromGroupInfoPrimary.FilePath));

                    if (_chromGroupInfo != null)
                    {
                        int ms1Count = 0, ms2Count = 0, totalCount = 0;
                        // Assume there will be one per transtion
                        var listPeakData = new ITransitionPeakData <ISummaryPeakData> [nodeGroup.TransitionCount];
                        foreach (var nodeTran in nodeGroup.Transitions)
                        {
                            var tranInfo = _chromGroupInfo.GetTransitionInfo(nodeTran, mzMatchTolerance, chromatogramSet.OptimizationFunction);
                            if (tranInfo == null)
                            {
                                continue;
                            }
                            listPeakData[totalCount++] = new SummaryTransitionPeakData(document, nodeTran, chromatogramSet, tranInfo);
                            if (nodeTran.IsMs1)
                            {
                                ms1Count++;
                            }
                            else
                            {
                                ms2Count++;
                            }
                        }
                        // If something was missing reallocate, which can't be slower than List.ToArray()
                        if (totalCount < listPeakData.Length)
                        {
                            var peakDatasShort = new ITransitionPeakData <ISummaryPeakData> [totalCount];
                            Array.Copy(listPeakData, peakDatasShort, totalCount);
                            listPeakData = peakDatasShort;
                        }
                        TransitionPeakData   = listPeakData.ToArray();
                        Ms1TranstionPeakData = GetTransitionTypePeakData(ms1Count, ms2Count, true);
                        Ms2TranstionPeakData = GetTransitionTypePeakData(ms1Count, ms2Count, false);
                    }
                }
            }
Ejemplo n.º 11
0
 public static bool UseFullPath(ChromatogramSet chromatogramSet)
 {
     if (chromatogramSet.FileCount <= 1)
     {
         return(false);
     }
     return(chromatogramSet.MSDataFilePaths.Select(GetName).Distinct().Count() !=
            chromatogramSet.FileCount);
 }
Ejemplo n.º 12
0
            public SummaryTransitionPeakData(SrmDocument document,
                                             TransitionDocNode nodeTran,
                                             ChromatogramSet chromatogramSet,
                                             ChromatogramInfo tranChromInfo)
            {
                NodeTran = nodeTran;

                _chromInfo = tranChromInfo;
            }
Ejemplo n.º 13
0
        public double?GetPeptideConcentration(ChromatogramSet chromatogramSet)
        {
            if (null == chromatogramSet)
            {
                return(null);
            }
            double concentrationMultiplier = PeptideQuantifier.PeptideDocNode.ConcentrationMultiplier.GetValueOrDefault(1.0);

            return(chromatogramSet.AnalyteConcentration * concentrationMultiplier / chromatogramSet.SampleDilutionFactor);
        }
Ejemplo n.º 14
0
        public SampleType GetSampleType(CalibrationPoint calibrationPoint)
        {
            if (null == calibrationPoint.LabelType)
            {
                ChromatogramSet chromatogramSet = SrmSettings.MeasuredResults.Chromatograms[calibrationPoint.ReplicateIndex];
                return(chromatogramSet.SampleType);
            }

            return(GetSpecifiedXValue(calibrationPoint).HasValue ? SampleType.STANDARD : SampleType.UNKNOWN);
        }
Ejemplo n.º 15
0
        public GroupIdentifier GetGroupIdentifier(SrmSettings settings, ChromatogramSet chromatogramSet)
        {
            AnnotationDef annotationDef =
                settings.DataSettings.AnnotationDefs.FirstOrDefault(a => a.Name == ControlAnnotation);

            if (annotationDef == null)
            {
                return(default(GroupIdentifier));
            }
            return(GroupIdentifier.MakeGroupIdentifier(chromatogramSet.Annotations.GetAnnotation(annotationDef)));
        }
Ejemplo n.º 16
0
        private void ExportImport(ResultsTestDocumentContainer docContainer, string resultsPath)
        {
            var optRegression = docContainer.Document.Settings.TransitionSettings.Prediction.CollisionEnergy;
            int optSteps      = optRegression.StepCount * 2 + 1;
            int optSteps1     = optSteps - 1; // First precursor is below 10 volts CE for 1 step
            int optSteps2     = optSteps - 3; // Second precursor is below 10 volts CE for 3 steps

            // First export
            var exporter = new AbiMassListExporter(docContainer.Document)
            {
                OptimizeType      = ExportOptimize.CE,
                OptimizeStepCount = optRegression.StepCount,
                OptimizeStepSize  = optRegression.StepSize
            };
            string tranListPath = Path.ChangeExtension(docContainer.DocumentFilePath, TextUtil.EXT_CSV);

            exporter.Export(tranListPath);
            // Make sure line count matches expectations for steps below 10 volts CE
            Assert.AreEqual(5 * optSteps1 + 5 * optSteps2, File.ReadAllLines(tranListPath).Length);

            // Then import
            var resultsUri      = new MsDataFilePath(resultsPath);
            var chromSet        = new ChromatogramSet("Optimize", new[] { resultsUri }, Annotations.EMPTY, optRegression);
            var measuredResults = new MeasuredResults(new[] { chromSet });

            docContainer.ChangeMeasuredResults(measuredResults, 2, optSteps1 + optSteps2, 5 * optSteps1 + 5 * optSteps2);

            // Check expected optimization data with missing values for steps below 10 volts CE
            int expectedMissingSteps = optSteps - optSteps1;

            foreach (var nodeGroup in docContainer.Document.MoleculeTransitionGroups)
            {
                foreach (var nodeTran in nodeGroup.Transitions)
                {
                    Assert.IsTrue(nodeTran.HasResults, "No results for transition Mz: {0}", nodeTran.Mz);
                    Assert.IsNotNull(nodeTran.Results[0]);
                    Assert.AreEqual(optSteps, nodeTran.Results[0].Count);
                    for (int i = 0; i < optSteps; i++)
                    {
                        if (i < expectedMissingSteps)
                        {
                            Assert.IsTrue(nodeTran.Results[0][i].IsEmpty);
                        }
                        else
                        {
                            Assert.IsFalse(nodeTran.Results[0][i].IsEmpty);
                        }
                    }
                }

                expectedMissingSteps = optSteps - optSteps2;
            }
        }
Ejemplo n.º 17
0
 public void ChangeChromatogramSet(EditDescription editDescription, ChromatogramSet chromatogramSet)
 {
     ModifyDocument(editDescription.ChangeElementRef(GetElementRef()), document =>
     {
         var measuredResults           = document.Settings.MeasuredResults;
         var chromatograms             = measuredResults.Chromatograms.ToArray();
         chromatograms[ReplicateIndex] = chromatogramSet;
         measuredResults = measuredResults.ChangeChromatograms(chromatograms);
         return(document.ChangeMeasuredResults(measuredResults));
     }
                    );
 }
Ejemplo n.º 18
0
        private static TransitionGroupDocNode PickTransitionGroup(SrmDocument doc, PeptideTreeNode nodePepTree, int resultsIndex)
        {
            // Determine which transition group to use
            var nodeTranGroups = nodePepTree.DocNode.TransitionGroups.ToArray();

            if (!nodeTranGroups.Any())
            {
                return(null);
            }

            if (nodeTranGroups.Length == 1)
            {
                return(nodeTranGroups.First());
            }

            var standards    = doc.Settings.PeptideSettings.Modifications.InternalStandardTypes;
            var standardList = nodeTranGroups.Where(tranGroup => standards.Contains(tranGroup.TransitionGroup.LabelType)).ToArray();

            if (standardList.Length == 1)
            {
                return(standardList.First());
            }

            if (standardList.Length > 1)
            {
                nodeTranGroups = standardList;
            }

            // Still not sure, pick the one with the most peak area
            TransitionGroupDocNode best = null;
            float mzMatchTolerance      = (float)doc.Settings.TransitionSettings.Instrument.MzMatchTolerance;
            float highestAreaSum        = 0;

            foreach (var tranGroup in nodeTranGroups)
            {
                ChromatogramSet         chromSet = doc.Settings.MeasuredResults.Chromatograms[resultsIndex];
                ChromatogramGroupInfo[] chromGroupInfos;
                if (!doc.Settings.MeasuredResults.TryLoadChromatogram(chromSet, nodePepTree.DocNode, tranGroup, mzMatchTolerance, false, out chromGroupInfos))
                {
                    continue;
                }

                float areaSum = chromGroupInfos.Where(info => info != null && info.TransitionPointSets != null)
                                .Sum(chromGroupInfo => chromGroupInfo.TransitionPointSets.Sum(chromInfo => chromInfo.Peaks.Sum(peak => peak.Area)));
                if (areaSum > highestAreaSum)
                {
                    best           = tranGroup;
                    highestAreaSum = areaSum;
                }
            }
            return(best);
        }
Ejemplo n.º 19
0
 LoadAllChromatograms(SrmDocument document, ChromatogramSet chromatogramSet)
 {
     foreach (var peptide in document.Molecules)
     {
         foreach (var transitionGroup in peptide.TransitionGroups)
         {
             ChromatogramGroupInfo[] infos;
             document.Settings.MeasuredResults.TryLoadChromatogram(chromatogramSet, peptide, transitionGroup,
                                                                   (float)TransitionInstrument.DEFAULT_MZ_MATCH_TOLERANCE, true, out infos);
             yield return(new Tuple <PeptideDocNode, TransitionGroupDocNode, ChromatogramGroupInfo[]>(peptide, transitionGroup, infos));
         }
     }
 }
Ejemplo n.º 20
0
 public bool TrySetReplicateChecked(ChromatogramSet chromatogramSet, bool isChecked)
 {
     for (int index = 0; index < checkedListBoxResults.Items.Count; index++)
     {
         ListBoxItem item = (ListBoxItem)checkedListBoxResults.Items[index];
         if (ReferenceEquals(chromatogramSet, item.ChromatogramSet))
         {
             checkedListBoxResults.SetItemChecked(index, isChecked);
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 21
0
            public SummaryTransitionGroupPeakData(SrmDocument document,
                                                  PeptideDocNode nodePep,
                                                  TransitionGroupDocNode nodeGroup,
                                                  ChromatogramSet chromatogramSet,
                                                  ChromatogramGroupInfo chromGroupInfoPrimary)
            {
                _peakIndex = -1;

                NodeGroup  = nodeGroup;
                IsStandard = document.Settings.PeptideSettings.Modifications.InternalStandardTypes
                             .Contains(nodeGroup.TransitionGroup.LabelType);
                TransitionPeakData = Ms1TranstionPeakData = Ms2TranstionPeakData = EMPTY_DATA;

                ChromatogramGroupInfo[] arrayChromInfo;
                var   measuredResults  = document.Settings.MeasuredResults;
                float mzMatchTolerance = (float)document.Settings.TransitionSettings.Instrument.MzMatchTolerance;

                if (measuredResults.TryLoadChromatogram(chromatogramSet, nodePep, nodeGroup, mzMatchTolerance, false,
                                                        out arrayChromInfo))
                {
                    _chromGroupInfo = arrayChromInfo.FirstOrDefault(ci =>
                                                                    Equals(ci.FilePath, chromGroupInfoPrimary.FilePath));

                    if (_chromGroupInfo != null)
                    {
                        int ms1Count = 0, ms2Count = 0;
                        var listPeakData = new List <ITransitionPeakData <ISummaryPeakData> >();
                        foreach (var nodeTran in nodeGroup.Transitions)
                        {
                            var tranInfo = _chromGroupInfo.GetTransitionInfo(nodeTran.Mz, mzMatchTolerance);
                            if (tranInfo == null)
                            {
                                continue;
                            }
                            listPeakData.Add(new SummaryTransitionPeakData(document, nodeTran, chromatogramSet, tranInfo));
                            if (nodeTran.IsMs1)
                            {
                                ms1Count++;
                            }
                            else
                            {
                                ms2Count++;
                            }
                        }
                        TransitionPeakData   = listPeakData.ToArray();
                        Ms1TranstionPeakData = GetTransitionTypePeakData(ms1Count, ms2Count, true);
                        Ms2TranstionPeakData = GetTransitionTypePeakData(ms1Count, ms2Count, false);
                    }
                }
            }
Ejemplo n.º 22
0
        private ToolStripMenuItem MakeExcludeStandardMenuItem(int replicateIndex)
        {
            var document = DocumentUiContainer.DocumentUI;

            if (!document.Settings.HasResults)
            {
                return(null);
            }
            ChromatogramSet chromatogramSet = null;

            if (replicateIndex >= 0 &&
                replicateIndex < document.Settings.MeasuredResults.Chromatograms.Count)
            {
                chromatogramSet = document.Settings.MeasuredResults.Chromatograms[replicateIndex];
            }
            if (chromatogramSet == null)
            {
                return(null);
            }
            if (!chromatogramSet.SampleType.AllowExclude)
            {
                return(null);
            }
            PeptideDocNode      peptideDocNode;
            PeptideGroupDocNode peptideGroupDocNode;

            if (!TryGetSelectedPeptide(out peptideGroupDocNode, out peptideDocNode))
            {
                return(null);
            }
            bool isExcluded   = peptideDocNode.IsExcludeFromCalibration(replicateIndex);
            var  menuItemText = isExcluded ? QuantificationStrings.CalibrationForm_MakeExcludeStandardMenuItem_Include_Standard
                : QuantificationStrings.CalibrationForm_MakeExcludeStandardMenuItem_Exclude_Standard;
            var peptideIdPath = new IdentityPath(peptideGroupDocNode.Id, peptideDocNode.Id);
            var menuItem      = new ToolStripMenuItem(menuItemText, null, (sender, args) =>
            {
                _skylineWindow.ModifyDocument(menuItemText,
                                              doc => SetExcludeStandard(doc, peptideIdPath, replicateIndex, !isExcluded), docPair =>
                {
                    var msgType = isExcluded
                            ? MessageType.set_included_standard
                            : MessageType.set_excluded_standard;
                    return(AuditLogEntry.CreateSingleMessageEntry(docPair.OldDoc,
                                                                  new MessageInfo(msgType, PeptideTreeNode.GetLabel(peptideDocNode, string.Empty), chromatogramSet.Name)));
                });
            });

            return(menuItem);
        }
Ejemplo n.º 23
0
        public static void SelectAndApplyPeak(string modifiedSequence, double?precursorMz, string resultsName, bool subsequent, double rt)
        {
            bool         found         = false;
            var          skylineWindow = Program.MainWindow;
            var          doc           = skylineWindow.Document;
            IdentityPath identityPath  = null;
            var          libKeyToMatch = new PeptideLibraryKey(modifiedSequence, 0);

            foreach (PeptideGroupDocNode nodePepGroup in doc.MoleculeGroups)
            {
                foreach (var nodePep in nodePepGroup.Peptides.Where(nodePep => LibKeyIndex.KeysMatch(libKeyToMatch, nodePep.ModifiedTarget.GetLibKey(Adduct.EMPTY))))
                {
                    var nodeTranGroup = precursorMz.HasValue
                        ? nodePep.TransitionGroups.First(tranGroup => Math.Abs(tranGroup.PrecursorMz - precursorMz.Value) < 0.01)
                        : nodePep.TransitionGroups.First();
                    identityPath = new IdentityPath(nodePepGroup.Id, nodePep.Id, nodeTranGroup.Id);
                    IdentityPath path = identityPath;
                    skylineWindow.SelectedPath = path;
                    found = true;
                    break;
                }
                if (found)
                {
                    break;
                }
            }
            if (!found)
            {
                Assert.Fail("Could not find peptide {0}", modifiedSequence);
            }

            found = false;
            var chromatograms = doc.Settings.MeasuredResults.Chromatograms;

            foreach (var chromatogram in chromatograms.Where(chromSet => chromSet.Name.Equals(resultsName)))
            {
                found = true;
                ChromatogramSet chromSet = chromatogram;
                skylineWindow.SelectedResultsIndex = chromatograms.IndexOf(chromSet);
                skylineWindow.ModifyDocument("change peak", document =>
                                             document.ChangePeak(identityPath, chromSet.Name, chromSet.MSDataFilePaths.First(), null, rt, UserSet.TRUE));
                break;
            }
            if (!found)
            {
                Assert.Fail("Could not find results {0}", resultsName);
            }
            skylineWindow.ApplyPeak(subsequent);
        }
Ejemplo n.º 24
0
 public PeakTransitionGroupId(PeptideGroupDocNode nodePepGroup,
                              PeptideDocNode nodePep,
                              IsotopeLabelType labelType,
                              ChromatogramSet chromatogramSet,
                              ChromatogramGroupInfo chromGroupInfo,
                              IDictionary <int, int> runEnumDict)
 {
     NodePepGroup    = nodePepGroup;
     NodePep         = nodePep;
     LabelType       = labelType;
     ChromatogramSet = chromatogramSet;
     FilePath        = chromGroupInfo.FilePath;
     FileId          = chromatogramSet.FindFile(chromGroupInfo);
     Run             = runEnumDict[FileId.GlobalIndex];
 }
Ejemplo n.º 25
0
        public PeakBoundsMatch(TransitionGroupChromInfo chromInfoTrue,
                               TransitionGroupChromInfo chromInfoPicked,
                               MatchKey key,
                               ChromatogramSet chromSet,
                               MsDataFileUri filePath,
                               TransitionGroupDocNode nodeGroup,
                               PeptideDocNode nodePep,
                               bool hasNoQValues,
                               bool hasNoScores,
                               bool apexPresent)
        {
            _chromatogramSet = chromSet;

            ChromInfoTrue   = chromInfoTrue;
            ChromInfoPicked = chromInfoPicked;
            Key             = key;
            FilePath        = filePath;
            NodeGroup       = nodeGroup;
            NodePep         = nodePep;
            // Read apex
            if (apexPresent)
            {
                PickedApex          = ParsePickedTimeAnnotation(ComparePeakBoundaries.APEX_ANNOTATION);
                PickedStartBoundary = ParsePickedTimeAnnotation(ComparePeakBoundaries.START_TIME_ANNOTATION);
                PickedEndBoundary   = ParsePickedTimeAnnotation(ComparePeakBoundaries.END_TIME_ANNOTATION);
            }
            else
            {
                PickedApex          = ChromInfoPicked.RetentionTime;
                PickedStartBoundary = ChromInfoPicked.StartRetentionTime;
                PickedEndBoundary   = ChromInfoPicked.EndRetentionTime;
            }
            QValue = GetScoreValue(ChromInfoPicked, MProphetResultsHandler.AnnotationName, ci => ci.QValue);
            if (QValue == null && !IsMissingPickedPeak && !hasNoQValues)
            {
                throw new IOException(string.Format(
                                          Resources.PeakBoundsMatch_QValue_Unable_to_read_q_value_annotation_for_peptide__0__of_file__1_,
                                          ModifiedSequence, FileName));
            }
            Score = GetScoreValue(ChromInfoPicked, MProphetResultsHandler.MAnnotationName, ci => ci.ZScore);
            if (Score == null && !IsMissingPickedPeak && !hasNoScores)
            {
                throw new IOException(string.Format(
                                          Resources.PeakBoundsMatch_PeakBoundsMatch_Unable_to_read_a_score_annotation_for_peptide__0__of_file__1_,
                                          ModifiedSequence, FileName));
            }
        }
Ejemplo n.º 26
0
        private void Import(ResultsTestDocumentContainer docContainer, string resultsPath, bool optFlag)
        {
            var optRegression   = optFlag ? docContainer.Document.Settings.TransitionSettings.Prediction.CollisionEnergy : null;
            int optSteps        = optRegression != null ? optRegression.StepCount * 2 + 1 : 1;
            var resultsUri      = new MsDataFilePath(resultsPath);
            var chromSet        = new ChromatogramSet("Optimize", new[] { resultsUri }, Annotations.EMPTY, optRegression);
            var measuredResults = new MeasuredResults(new[] { chromSet });

            docContainer.ChangeMeasuredResults(measuredResults, 1, 1 * optSteps, 3 * optSteps);

            // Check expected optimization data.
            foreach (var nodeTran in docContainer.Document.MoleculeTransitions)
            {
                Assert.IsTrue(nodeTran.HasResults, "No results for transition Mz: {0}", nodeTran.Mz);
                Assert.IsNotNull(nodeTran.Results[0]);
                Assert.AreEqual(optSteps, nodeTran.Results[0].Count);
            }
        }
Ejemplo n.º 27
0
        public double GetArea(TracerFormula tracerFormula, double startTime, double endTime)
        {
            double result     = 0;
            int    startIndex = ChromatogramSet.IndexFromTime(startTime);
            int    endIndex   = ChromatogramSet.IndexFromTime(endTime);

            for (int i = startIndex; i <= endIndex; i++)
            {
                int binStartIndex = Math.Max(i - 1, 0);
                int binEndIndex   = Math.Min(i + 1, Times.Count - 1);
                if (binStartIndex == binEndIndex)
                {
                    continue;
                }
                double width = (Times[binEndIndex] - Times[binStartIndex]) / (binEndIndex - binStartIndex);
                result += Points[tracerFormula][i] * width;
            }
            return(result);
        }
Ejemplo n.º 28
0
        private ToolStripMenuItem MakeExcludeStandardMenuItem(int replicateIndex)
        {
            var document = DocumentUiContainer.DocumentUI;

            if (!document.Settings.HasResults)
            {
                return(null);
            }
            ChromatogramSet chromatogramSet = null;

            if (replicateIndex >= 0 &&
                replicateIndex < document.Settings.MeasuredResults.Chromatograms.Count)
            {
                chromatogramSet = document.Settings.MeasuredResults.Chromatograms[replicateIndex];
            }
            if (chromatogramSet == null)
            {
                return(null);
            }
            if (!chromatogramSet.SampleType.AllowExclude)
            {
                return(null);
            }
            PeptideDocNode      peptideDocNode;
            PeptideGroupDocNode peptideGroupDocNode;

            if (!TryGetSelectedPeptide(out peptideGroupDocNode, out peptideDocNode))
            {
                return(null);
            }
            bool isExcluded   = peptideDocNode.IsExcludeFromCalibration(replicateIndex);
            var  menuItemText = isExcluded ? QuantificationStrings.CalibrationForm_MakeExcludeStandardMenuItem_Include_Standard
                : QuantificationStrings.CalibrationForm_MakeExcludeStandardMenuItem_Exclude_Standard;
            var peptideIdPath = new IdentityPath(peptideGroupDocNode.Id, peptideDocNode.Id);
            var menuItem      = new ToolStripMenuItem(menuItemText, null, (sender, args) =>
            {
                _skylineWindow.ModifyDocument(menuItemText,
                                              doc => SetExcludeStandard(doc, peptideIdPath, replicateIndex, !isExcluded));
            });

            return(menuItem);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Return a number to use as the peak boundary based on the peptide sequence, replicate name, and
        /// sample name. This number is then used to verify that the peak boundaries were applied correctly.
        /// </summary>
        public double GetPeakStartTime(PeptideDocNode peptide, ChromatogramSet chromatogramSet, MsDataFileUri msDataFileUri)
        {
            double time = peptide.Peptide.Sequence.Length;

            var replicateTimes = new Dictionary <string, double>()
            {
                { "ReplicateOne", 1 }, { "ReplicateTwo", 0 }, { "ReplicateThree", 2 }
            };

            time += replicateTimes[chromatogramSet.Name];

            var sampleTimes = new Dictionary <string, double>()
            {
                { "blank", 0 }, { "rfp9_after_h_1", -.25 }, { "test", .3 }, { "rfp9_before_h_1", .4 }
            };

            time += sampleTimes[msDataFileUri.GetSampleName()];

            return(time);
        }
Ejemplo n.º 30
0
        public PeakTransitionGroupId(PeptideGroupDocNode nodePepGroup,
                                     PeptideDocNode nodePep,
                                     IsotopeLabelType labelType,
                                     ChromatogramSet chromatogramSet,
                                     ChromatogramGroupInfo chromGroupInfo,
                                     IDictionary <int, int> runEnumDict)
        {
            NodePepGroup    = nodePepGroup;
            LabelType       = labelType;
            ChromatogramSet = chromatogramSet;
            FilePath        = chromGroupInfo.FilePath;
            FileId          = chromatogramSet.FindFile(chromGroupInfo);
            Run             = runEnumDict[FileId.GlobalIndex];

            // Avoid hanging onto the peptide, since it can end up being the primary memory root
            // for large-scale command-line processing
            RawTextId           = nodePep.ModifiedTarget.ToString();
            RawUnmodifiedTextId = nodePep.Target.ToString();
            IsDecoy             = nodePep.IsDecoy;
            Key = new PeakTransitionGroupIdKey(nodePep.Id.GlobalIndex, FileId.GlobalIndex);
        }