Example #1
0
 public ResultFile(Replicate replicate, ChromFileInfoId chromFileInfoId, int optStep) : base(replicate.DataSchema)
 {
     Replicate        = replicate;
     ChromFileInfoId  = chromFileInfoId;
     _chromFileInfo   = CachedValue.Create(DataSchema, () => Replicate.ChromatogramSet.GetFileInfo(ChromFileInfoId));
     OptimizationStep = optStep;
 }
Example #2
0
 public TransitionChromInfo(ChromFileInfoId fileId, int optimizationStep, float?massError,
                            float retentionTime, float startRetentionTime, float endRetentionTime,
                            float area, float backgroundArea, float height,
                            float fwhm, bool fwhmDegenerate, bool?truncated,
                            PeakIdentification identified, IList <float?> ratios,
                            Annotations annotations, UserSet userSet)
     : base(fileId)
 {
     OptimizationStep   = optimizationStep;
     MassError          = massError;
     RetentionTime      = retentionTime;
     StartRetentionTime = startRetentionTime;
     EndRetentionTime   = endRetentionTime;
     Area           = area;
     BackgroundArea = backgroundArea;
     Height         = height;
     Fwhm           = fwhm;
     // Crawdad can set FWHM to NaN. Need to protect against that here.
     if (float.IsNaN(fwhm))
     {
         Fwhm = 0;
     }
     IsFwhmDegenerate = fwhmDegenerate;
     IsTruncated      = truncated;
     Identified       = identified;
     Ratios           = ratios;
     Annotations      = annotations;
     UserSet          = userSet;
 }
Example #3
0
 public Bookmark ChangeChromFileInfoId(ChromFileInfoId value)
 {
     return(new Bookmark(this)
     {
         ChromFileInfoId = value
     });
 }
Example #4
0
 public DataKey(ChromFileInfoId chromFileInfoId, SampleType sampleType, IsotopeLabelType isotopeLabelType)
     : this()
 {
     ChromFileInfoId  = chromFileInfoId;
     SampleType       = sampleType;
     IsotopeLabelType = isotopeLabelType;
 }
Example #5
0
        public static Results <TItem> ChangeChromInfo(Results <TItem> results, ChromFileInfoId id, TItem newChromInfo)
        {
            var  elements = new List <ChromInfoList <TItem> >();
            bool found    = false;

            foreach (var replicate in results)
            {
                var chromInfoList = new List <TItem>();
                if (replicate == null)
                {
                    elements.Add(null);
                    continue;
                }
                foreach (var chromInfo in replicate)
                {
                    if (!ReferenceEquals(chromInfo.FileId, id))
                    {
                        chromInfoList.Add(chromInfo);
                    }
                    else
                    {
                        found = true;
                        chromInfoList.Add(newChromInfo);
                    }
                }
                elements.Add(new ChromInfoList <TItem>(chromInfoList));
            }
            if (!found)
            {
                throw new InvalidOperationException(Resources.ResultsGrid_ChangeChromInfo_Element_not_found);
            }
            return(new Results <TItem>(elements));
        }
Example #6
0
 public TransitionChromInfo(ChromFileInfoId fileId, int optimizationStep, ChromPeak peak,
                            IList <float?> ratios, Annotations annotations, UserSet userSet)
     : this(fileId, optimizationStep, peak.MassError, peak.RetentionTime, peak.StartTime, peak.EndTime,
            peak.Area, peak.BackgroundArea, peak.Height, peak.Fwhm,
            peak.IsFwhmDegenerate, peak.IsTruncated, peak.Identified,
            ratios, annotations, userSet)
 {
 }
Example #7
0
 public PeptideChromInfo(ChromFileInfoId fileId, float peakCountRatio, float?retentionTime,
                         IList <PeptideLabelRatio> labelRatios)
     : base(fileId)
 {
     PeakCountRatio = peakCountRatio;
     RetentionTime  = retentionTime;
     LabelRatios    = labelRatios;
 }
Example #8
0
 private static TItem FindChromInfo <TItem>(Results <TItem> results, ChromFileInfoId fileId) where TItem : ChromInfo
 {
     if (results == null)
     {
         return(null);
     }
     return(results.SelectMany(r => r).FirstOrDefault(chromInfo => ReferenceEquals(chromInfo.FileId, fileId)));
 }
Example #9
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = ReplicateIndex;
         hashCode = (hashCode * 397) ^ ChromFileInfoId.GetHashCode();
         hashCode = (hashCode * 397) ^ OptimizationStep;
         return(hashCode);
     }
 }
Example #10
0
 public override int GetHashCode()
 {
     unchecked
     {
         int result = IdentityPath.GetHashCode();
         result = (result * 397) ^ (ChromFileInfoId != null ? ChromFileInfoId.GetHashCode() : 0);
         result = (result * 397) ^ OptStep.GetHashCode();
         return(result);
     }
 }
Example #11
0
        public double?GetMedian(ChromFileInfoId chromFileInfoId, IsotopeLabelType isotopeLabelType)
        {
            var       dataKey = new DataKey(chromFileInfoId, null, isotopeLabelType);
            DataValue dataValue;

            if (!_data.TryGetValue(dataKey, out dataValue))
            {
                return(null);
            }
            return(dataValue.Median);
        }
Example #12
0
        public double?Percentile(ChromFileInfoId chromFileInfoId, IsotopeLabelType isotopeLabelType, double percentile)
        {
            var       dataKey = new DataKey(chromFileInfoId, isotopeLabelType);
            DataValue dataValue;

            if (!_data.TryGetValue(dataKey, out dataValue))
            {
                return(null);
            }
            return(dataValue.GetValueAtPercentile(percentile));
        }
Example #13
0
        public double?NormalizeQuantile(ChromFileInfoId chromFileInfoId, IsotopeLabelType isotopeLabelType,
                                        double value)
        {
            DataValue dataValue;

            if (!_data.TryGetValue(new DataKey(chromFileInfoId, isotopeLabelType), out dataValue))
            {
                return(null);
            }
            double percentile = dataValue.FindPercentileOfValue(value);

            return(GetMeanPercentile(isotopeLabelType, percentile).Value);
        }
            private IEnumerable <int> GetReplicateIndices(Func <int, ChromFileInfoId> getFileId)
            {
                var chromatograms = _document.Settings.MeasuredResults.Chromatograms;

                if (ReplicateOrder == SummaryReplicateOrder.document && null == OrderByReplicateAnnotation)
                {
                    for (int iResult = 0; iResult < chromatograms.Count; iResult++)
                    {
                        yield return(iResult);
                    }
                }
                else
                {
                    // Create a list of tuple's that will sort according to user's options.
                    // The sort is optionally by an annotation value, and then optionally acquired time,
                    // and finally document order.
                    var           listIndexFile = new List <Tuple <object, DateTime, int> >();
                    AnnotationDef orderByReplicateAnnotationDef = null;
                    if (null != OrderByReplicateAnnotation)
                    {
                        orderByReplicateAnnotationDef = _document.Settings.DataSettings.AnnotationDefs.FirstOrDefault(
                            annotationDef => annotationDef.Name == OrderByReplicateAnnotation);
                    }
                    for (int iResult = 0; iResult < chromatograms.Count; iResult++)
                    {
                        var chromSet = _document.Settings.MeasuredResults.Chromatograms[iResult];

                        ChromFileInfoId fileId          = getFileId(iResult);
                        ChromFileInfo   fileInfo        = (fileId != null ? chromSet.GetFileInfo(fileId) : null);
                        object          annotationValue = null;
                        DateTime        replicateTime   = DateTime.MaxValue;
                        if (null != orderByReplicateAnnotationDef)
                        {
                            annotationValue = chromSet.Annotations.GetAnnotation(orderByReplicateAnnotationDef);
                        }
                        if (null != fileInfo && ReplicateOrder == SummaryReplicateOrder.time)
                        {
                            replicateTime = fileInfo.RunStartTime ?? DateTime.MaxValue;
                        }
                        listIndexFile.Add(new Tuple <object, DateTime, int>(annotationValue, replicateTime, iResult));
                    }

                    listIndexFile.Sort();
                    foreach (var tuple in listIndexFile)
                    {
                        yield return(tuple.Item3);
                    }
                }
            }
Example #15
0
 public bool Equivalent(ChromFileInfoId fileId, int step, ChromPeak peak)
 {
     return(ReferenceEquals(fileId, FileId) &&
            step == OptimizationStep &&
            Equals(peak.MassError, MassError) &&
            peak.RetentionTime == RetentionTime &&
            peak.StartTime == StartRetentionTime &&
            peak.EndTime == EndRetentionTime &&
            peak.Area == Area &&
            peak.BackgroundArea == BackgroundArea &&
            peak.Height == Height &&
            peak.Fwhm == Fwhm &&
            peak.IsFwhmDegenerate == IsFwhmDegenerate &&
            Equals(peak.IsTruncated, IsTruncated) &&
            Equals(peak.Identified, Identified));
 }
Example #16
0
 public TransitionGroupChromInfo(ChromFileInfoId fileId,
                                 int optimizationStep,
                                 float peakCountRatio,
                                 float?retentionTime,
                                 float?startTime,
                                 float?endTime,
                                 float?fwhm,
                                 float?area,
                                 float?areaMs1,
                                 float?areaFragment,
                                 float?backgroundArea,
                                 float?backgroundAreaMs1,
                                 float?backgroundAreaFragment,
                                 float?height,
                                 IList <RatioValue> ratios,
                                 float?massError,
                                 int?truncated,
                                 PeakIdentification identified,
                                 float?libraryDotProduct,
                                 float?isotopeDotProduct,
                                 Annotations annotations,
                                 UserSet userSet)
     : base(fileId)
 {
     OptimizationStep   = optimizationStep;
     PeakCountRatio     = peakCountRatio;
     RetentionTime      = retentionTime;
     StartRetentionTime = startTime;
     EndRetentionTime   = endTime;
     Fwhm                   = fwhm;
     Area                   = area;
     AreaMs1                = areaMs1;
     AreaFragment           = areaFragment;
     BackgroundArea         = backgroundArea;
     BackgroundAreaMs1      = backgroundAreaMs1;
     BackgroundAreaFragment = backgroundAreaFragment;
     Height                 = height;
     Ratios                 = ratios;
     MassError              = massError;
     Truncated              = truncated;
     Identified             = identified;
     LibraryDotProduct      = libraryDotProduct;
     IsotopeDotProduct      = isotopeDotProduct;
     Annotations            = annotations;
     UserSet                = userSet;
 }
Example #17
0
        public bool EquivalentTolerant(ChromFileInfoId fileId, int step, ChromPeak peak)
        {
            const double tol = 1e-4;

            return(ReferenceEquals(fileId, FileId) &&
                   step == OptimizationStep &&
                   Equals(peak.MassError, MassError) &&
                   IsEqualTolerant(peak.RetentionTime, RetentionTime, tol) &&
                   IsEqualTolerant(peak.StartTime, StartRetentionTime, tol) &&
                   IsEqualTolerant(peak.EndTime, EndRetentionTime, tol) &&
                   IsEqualTolerant(peak.Area, Area, tol * Area) &&
                   IsEqualTolerant(peak.BackgroundArea, BackgroundArea, tol * BackgroundArea) &&
                   IsEqualTolerant(peak.Height, Height, tol * Height) &&
                   (IsEqualTolerant(peak.Fwhm, Fwhm, tol * Fwhm) || Equals(peak.Fwhm, Fwhm)) &&
                   Equals(peak.IsFwhmDegenerate, IsFwhmDegenerate) &&
                   Equals(peak.IsTruncated, IsTruncated) &&
                   Equals(peak.Identified, Identified));
        }
Example #18
0
            protected RetentionTimeValues?ScaleRetentionTimeValues(ChromFileInfoId chromFileInfoId, RetentionTimeValues?retentionTimeValues)
            {
                if (!retentionTimeValues.HasValue)
                {
                    return(null);
                }
                if (null == RetentionTimeTransformOp)
                {
                    return(retentionTimeValues);
                }
                IRegressionFunction regressionFunction;

                if (!RetentionTimeTransformOp.TryGetRegressionFunction(chromFileInfoId, out regressionFunction))
                {
                    return(null);
                }
                return(retentionTimeValues.Value.Scale(regressionFunction));
            }
Example #19
0
            protected RetentionTimeValues ScaleRetentionTimeValues(ChromFileInfoId chromFileInfoId, RetentionTimeValues retentionTimeValues)
            {
                if (retentionTimeValues == null)
                {
                    return(null);
                }
                if (null == RetentionTimeTransformOp)
                {
                    return(retentionTimeValues);
                }
                RegressionLine regressionFunction;

                if (!RetentionTimeTransformOp.TryGetRegressionFunction(chromFileInfoId, out regressionFunction))
                {
                    return(null);
                }
                return(retentionTimeValues.Scale(regressionFunction));
            }
Example #20
0
        private double CalculateStandardArea(SrmDocument document, ChromFileInfoId chromFileInfoId, Predicate <PeptideDocNode> predicate)
        {
            double result = 0;

            foreach (var peptide in document.Molecules)
            {
                if (!predicate(peptide))
                {
                    continue;
                }
                VerifyTotalAreas(peptide, chromFileInfoId);
                foreach (var transitionGroup in peptide.TransitionGroups)
                {
                    var transitionGroupChromInfo = FindChromInfo(transitionGroup.Results, chromFileInfoId);
                    result += transitionGroupChromInfo?.Area ?? 0;
                }
            }
            return(result);
        }
Example #21
0
 /// <summary>
 /// Verifies that the total area on the TransitionGroupChromInfo is equal to the sum of the
 /// areas on the TransitionChromInfo.
 /// </summary>
 public static void VerifyTotalAreas(PeptideDocNode peptideDocNode, ChromFileInfoId chromFileInfoId)
 {
     foreach (var transitionGroup in peptideDocNode.TransitionGroups)
     {
         var precursorTotalArea       = 0.0;
         var precursorTotalBackground = 0.0;
         foreach (var transition in transitionGroup.Transitions)
         {
             var transitionChromInfo = FindChromInfo(transition.Results, chromFileInfoId);
             if (transitionChromInfo != null)
             {
                 precursorTotalArea       += transitionChromInfo.Area;
                 precursorTotalBackground += transitionChromInfo.BackgroundArea;
             }
         }
         var precursorChromInfo = FindChromInfo(transitionGroup.Results, chromFileInfoId);
         AssertValuesEqual(precursorTotalArea, precursorChromInfo?.Area ?? 0);
         AssertValuesEqual(precursorTotalBackground, precursorChromInfo?.BackgroundArea ?? 0);
     }
 }
Example #22
0
        public static Bookmark ToBookmark(DocumentLocation documentLocation, SrmDocument document)
        {
            Bookmark bookmark = new Bookmark();

            if (documentLocation.IdPath.Any())
            {
                IdentityPath identityPath = IdentityPath.ToIdentityPath(documentLocation.IdPath, document);
                if (null == identityPath)
                {
                    throw new ArgumentException(@"Unable to find target node " + documentLocation.IdPathToString());
                }
                bookmark = bookmark.ChangeIdentityPath(identityPath);
            }
            if (documentLocation.ChromFileId.HasValue)
            {
                ChromFileInfoId chromFileInfoId = null;
                if (document.Settings.HasResults)
                {
                    foreach (var chromatogramSet in document.Settings.MeasuredResults.Chromatograms)
                    {
                        var chromFileInfo =
                            chromatogramSet.MSDataFileInfos.FirstOrDefault(
                                fileInfo => fileInfo.Id.GlobalIndex == documentLocation.ChromFileId);
                        if (null != chromFileInfo)
                        {
                            chromFileInfoId = chromFileInfo.FileId;
                        }
                    }
                }
                if (null == chromFileInfoId)
                {
                    throw new ArgumentException(@"Unable to find file id " + documentLocation.ChromFileId);
                }
                bookmark = bookmark.ChangeChromFileInfoId(chromFileInfoId);
            }
            if (documentLocation.OptStep.HasValue)
            {
                bookmark = bookmark.ChangeOptStep(documentLocation.OptStep.Value);
            }
            return(bookmark);
        }
        public TransitionChromInfo FindMatchingTransitionChromInfo(ChromFileInfoId fileId, int optimizationStep, TransitionDocNode otherTransition)
        {
            if (otherTransition.Results == null)
            {
                return(null);
            }

            FileInfo fileInfo;

            if (!_fileInfos.TryGetValue(fileId, out fileInfo))
            {
                return(null);
            }

            if (otherTransition.Results.Count <= fileInfo.ResultsIndex)
            {
                return(null);
            }

            foreach (var otherChromInfo in otherTransition.Results[fileInfo.ResultsIndex])
            {
                if (otherChromInfo == null)
                {
                    continue;
                }

                if (!ReferenceEquals(otherChromInfo.FileId, fileId))
                {
                    continue;
                }

                if (otherChromInfo.OptimizationStep != 0)
                {
                    continue;
                }

                return(otherChromInfo);
            }

            return(null);
        }
        /// <summary>
        /// If the predicted retention time is auto calculated, add a "Show {Prediction} score" menu item.
        /// If there are retention time alignments available for the specified chromFileInfoId, then adds
        /// a "Align Times To {Specified File}" menu item to a context menu.
        /// </summary>
        private int InsertAlignmentMenuItems(ToolStripItemCollection items, ChromFileInfoId chromFileInfoId, int iInsert)
        {
            var predictRT = Document.Settings.PeptideSettings.Prediction.RetentionTime;

            if (predictRT != null && predictRT.IsAutoCalculated)
            {
                var menuItem = new ToolStripMenuItem(string.Format(Resources.SkylineWindow_ShowCalculatorScoreFormat, predictRT.Calculator.Name), null,
                                                     (sender, eventArgs) => SkylineWindow.AlignToRtPrediction = !SkylineWindow.AlignToRtPrediction)
                {
                    Checked = SkylineWindow.AlignToRtPrediction,
                };
                items.Insert(iInsert++, menuItem);
            }
            if (null != chromFileInfoId && DocumentUI.Settings.HasResults &&
                !DocumentUI.Settings.DocumentRetentionTimes.FileAlignments.IsEmpty)
            {
                foreach (var chromatogramSet in DocumentUI.Settings.MeasuredResults.Chromatograms)
                {
                    var chromFileInfo = chromatogramSet.GetFileInfo(chromFileInfoId);
                    if (null == chromFileInfo)
                    {
                        continue;
                    }
                    string fileItemName    = Path.GetFileNameWithoutExtension(SampleHelp.GetFileName(chromFileInfo.FilePath));
                    var    menuItemText    = string.Format(Resources.SkylineWindow_AlignTimesToFileFormat, fileItemName);
                    var    alignToFileItem = new ToolStripMenuItem(menuItemText);
                    if (ReferenceEquals(chromFileInfoId, SkylineWindow.AlignToFile))
                    {
                        alignToFileItem.Click  += (sender, eventArgs) => SkylineWindow.AlignToFile = null;
                        alignToFileItem.Checked = true;
                    }
                    else
                    {
                        alignToFileItem.Click  += (sender, eventArgs) => SkylineWindow.AlignToFile = chromFileInfoId;
                        alignToFileItem.Checked = false;
                    }
                    items.Insert(iInsert++, alignToFileItem);
                }
            }
            return(iInsert);
        }
Example #25
0
            public static AlignToFileOp GetAlignmentToFile(ChromFileInfoId chromFileInfoId, SrmSettings settings)
            {
                if (!settings.HasResults)
                {
                    return(null);
                }
                var chromSetInfos = GetChromSetInfos(settings.MeasuredResults);
                Tuple <ChromatogramSet, ChromFileInfo> chromSetInfo;

                if (!chromSetInfos.TryGetValue(chromFileInfoId, out chromSetInfo))
                {
                    return(null);
                }
                var fileRetentionTimeAlignments = settings.DocumentRetentionTimes.FileAlignments.Find(chromSetInfo.Item2);

                if (null == fileRetentionTimeAlignments)
                {
                    return(null);
                }
                return(new AlignToFileOp(chromSetInfo.Item1, chromSetInfo.Item2, fileRetentionTimeAlignments, chromSetInfos));
            }
Example #26
0
            public double GetStandardArea(SrmSettings settings, int resultsIndex, ChromFileInfoId fileId)
            {
                double globalStandardArea = 0;
                var    peptideStandards   = settings.GetPeptideStandards(StandardType.SURROGATE_STANDARD);

                if (peptideStandards == null)
                {
                    return(0);
                }
                foreach (var peptideDocNode in peptideStandards)
                {
                    if (peptideDocNode.ModifiedTarget.InvariantName != SurrogateName)
                    {
                        continue;
                    }
                    foreach (var nodeGroup in peptideDocNode.TransitionGroups)
                    {
                        if (null != _isotopeLabelType &&
                            _isotopeLabelType.Name != nodeGroup.TransitionGroup.LabelType.Name)
                        {
                            continue;
                        }
                        var chromInfos = nodeGroup.GetSafeChromInfo(resultsIndex);
                        if (chromInfos.IsEmpty)
                        {
                            continue;
                        }
                        foreach (var groupChromInfo in chromInfos)
                        {
                            if (ReferenceEquals(fileId, groupChromInfo.FileId) &&
                                groupChromInfo.OptimizationStep == 0 &&
                                groupChromInfo.Area.HasValue)
                            {
                                globalStandardArea += groupChromInfo.Area.Value;
                            }
                        }
                    }
                }
                return(globalStandardArea);
            }
Example #27
0
        public static SrmDocument ApplyPeak(SrmDocument doc, PeptideTreeNode nodePepTree, ref TransitionGroupDocNode nodeTranGroup,
                                            int resultsIndex, ChromFileInfoId resultsFile, bool subsequent, ReplicateValue groupBy, object groupByValue, ILongWaitBroker longWaitBroker)
        {
            nodeTranGroup = nodeTranGroup ?? PickTransitionGroup(doc, nodePepTree, resultsIndex);
            GetReferenceData(doc, nodePepTree.DocNode, nodeTranGroup, resultsIndex, resultsFile, out var referenceTarget, out var referenceMatchData, out var runTime);

            var annotationCalculator = new AnnotationCalculator(doc);
            var chromatograms        = doc.Settings.MeasuredResults.Chromatograms;

            for (var i = 0; i < chromatograms.Count; i++)
            {
                var chromSet = chromatograms[i];

                if (groupBy != null)
                {
                    if (!Equals(groupByValue, groupBy.GetValue(annotationCalculator, chromSet)))
                    {
                        continue;
                    }
                }

                for (var j = 0; j < chromSet.MSDataFileInfos.Count; j++)
                {
                    var fileInfo = chromSet.MSDataFileInfos[j];
                    if ((i == resultsIndex && (resultsFile == null || ReferenceEquals(resultsFile, fileInfo.FileId))) ||
                        (subsequent && runTime != null && fileInfo.RunStartTime < runTime))
                    {
                        continue;
                    }

                    var bestMatch = GetPeakMatch(doc, chromSet, fileInfo, nodeTranGroup, referenceTarget, referenceMatchData);
                    if (bestMatch != null)
                    {
                        doc = bestMatch.ChangePeak(doc, nodePepTree, nodeTranGroup, chromSet.Name, fileInfo.FilePath);
                    }
                }
                longWaitBroker.SetProgressCheckCancel(i + 1, chromatograms.Count);
            }
            return(doc);
        }
Example #28
0
            public bool TryGetRegressionFunction(ChromFileInfoId chromFileInfoId, out IRegressionFunction regressionFunction)
            {
                if (ReferenceEquals(chromFileInfoId, ChromFileInfo.Id))
                {
                    regressionFunction = null;
                    return(true);
                }
                Tuple <ChromatogramSet, ChromFileInfo> chromSetInfo;

                if (_chromSetInfos.TryGetValue(chromFileInfoId, out chromSetInfo))
                {
                    var retentionTimeAlignment =
                        FileRetentionTimeAlignments.RetentionTimeAlignments.Find(chromSetInfo.Item2);
                    if (null != retentionTimeAlignment)
                    {
                        regressionFunction = retentionTimeAlignment.RegressionLine;
                        return(true);
                    }
                }
                regressionFunction = null;
                return(false);
            }
Example #29
0
        public DocNode RemovePeak(int indexSet, ChromFileInfoId fileId, UserSet userSet)
        {
            bool peakChanged   = false;
            var  listChromInfo = Results[indexSet];

            if (listChromInfo == null)
            {
                return(this);
            }
            var listChromInfoNew = new List <TransitionChromInfo>();

            foreach (var chromInfo in listChromInfo)
            {
                if (!ReferenceEquals(chromInfo.FileId, fileId))
                {
                    listChromInfoNew.Add(chromInfo);
                }
                else if (chromInfo.OptimizationStep == 0)
                {
                    if (!chromInfo.Equivalent(fileId, 0, ChromPeak.EMPTY))
                    {
                        listChromInfoNew.Add(chromInfo.ChangePeak(ChromPeak.EMPTY, userSet));
                        peakChanged = true;
                    }
                    else
                    {
                        listChromInfoNew.Add(chromInfo);
                    }
                }
            }
            if (listChromInfo.Count == listChromInfoNew.Count && !peakChanged)
            {
                return(this);
            }
            return(ChangeResults((Results <TransitionChromInfo>)
                                 Results.ChangeAt(indexSet, new ChromInfoList <TransitionChromInfo>(listChromInfoNew))));
        }
Example #30
0
        public float? GetPeakCenterTime(ChromFileInfoId fileId)
        {
            double totalTime = 0;
            int countTime = 0;
            foreach (var chromInfo in TransitionGroups.SelectMany(nodeGroup => nodeGroup.ChromInfos))
            {
                if (fileId != null && !ReferenceEquals(fileId, chromInfo.FileId))
                    continue;
                float? centerTime = GetPeakCenterTime(chromInfo);
                if (!centerTime.HasValue)
                    continue;

                totalTime += centerTime.Value;
                countTime++;
            }
            if (countTime == 0)
                return null;
            return (float)(totalTime / countTime);
        }
 protected RetentionTimeValues? ScaleRetentionTimeValues(ChromFileInfoId chromFileInfoId, RetentionTimeValues? retentionTimeValues)
 {
     if (!retentionTimeValues.HasValue)
     {
         return null;
     }
     if (null == RetentionTimeTransformOp)
     {
         return retentionTimeValues;
     }
     IRegressionFunction regressionFunction;
     if (!RetentionTimeTransformOp.TryGetRegressionFunction(chromFileInfoId, out regressionFunction))
     {
         return null;
     }
     return retentionTimeValues.Value.Scale(regressionFunction);
 }
Example #32
0
 private static TransitionChromInfo GetTransitionChromInfo(TransitionDocNode nodeTran,
     int indexChrom,
     ChromFileInfoId fileId,
     int step)
 {
     if (!nodeTran.HasResults || nodeTran.Results.Count <= indexChrom)
         return null;
     var tranChromInfoList = nodeTran.Results[indexChrom];
     if (tranChromInfoList == null)
         return null;
     foreach (var tranChromInfo in tranChromInfoList)
     {
         if (ReferenceEquals(tranChromInfo.FileId, fileId) && tranChromInfo.OptimizationStep == step)
             return tranChromInfo;
     }
     return null;
 }
Example #33
0
 private static TransitionGroupChromInfo GetTransitionGroupChromInfo(TransitionGroupDocNode nodeGroup,
     ChromFileInfoId fileId,
     int indexChrom)
 {
     if (!nodeGroup.HasResults)
         return null;
     var tranGroupChromInfoList = nodeGroup.Results[indexChrom];
     if (tranGroupChromInfoList == null)
         return null;
     foreach (var tranGroupChromInfo in tranGroupChromInfoList)
     {
         if (ReferenceEquals(tranGroupChromInfo.FileId, fileId))
             return tranGroupChromInfo;
     }
     return null;
 }
Example #34
0
 public Bookmark ChangeChromFileInfoId(ChromFileInfoId value)
 {
     return new Bookmark(this){ChromFileInfoId = value};
 }
Example #35
0
 protected ChromInfo(ChromFileInfoId fileId)
 {
     FileId = fileId;
 }
Example #36
0
 public double CalcGlobalStandardArea(int resultsIndex, ChromFileInfoId fileId)
 {
     double globalStandardArea = 0;
     var peptideStandards = GetPeptideStandards(PeptideDocNode.STANDARD_TYPE_NORMALIZAITON);
     if (peptideStandards != null)
     {
         foreach (var nodeGroup in peptideStandards.SelectMany(nodePep => nodePep.TransitionGroups))
         {
             var chromInfos = nodeGroup.GetSafeChromInfo(resultsIndex);
             if (chromInfos == null)
                 continue;
             foreach (var groupChromInfo in chromInfos)
             {
                 if (ReferenceEquals(fileId, groupChromInfo.FileId) &&
                         groupChromInfo.OptimizationStep == 0 &&
                         groupChromInfo.Area.HasValue)
                     globalStandardArea += groupChromInfo.Area.Value;
             }
         }
     }
     return globalStandardArea;
 }
Example #37
0
        void GraphChromatogram.IStateProvider.BuildChromatogramMenu(ZedGraphControl zedGraphControl, ContextMenuStrip menuStrip, ChromFileInfoId chromFileInfoId)
        {
            // Store original menuitems in an array, and insert a separator
            ToolStripItem[] items = new ToolStripItem[menuStrip.Items.Count];
            int iUnzoom = -1;
            for (int i = 0; i < items.Length; i++)
            {
                items[i] = menuStrip.Items[i];
                string tag = (string)items[i].Tag;
                if (tag == "unzoom") // Not L10N
                    iUnzoom = i;
            }

            if (iUnzoom != -1)
                menuStrip.Items.Insert(iUnzoom, toolStripSeparator26);

            // Insert skyline specific menus
            var set = Settings.Default;
            int iInsert = 0;
            var selectedTreeNode = SelectedNode as SrmTreeNode;
            var displayType = GraphChromatogram.GetDisplayType(DocumentUI, selectedTreeNode);

            var settings = DocumentUI.Settings;
            bool retentionPredict = (settings.PeptideSettings.Prediction.RetentionTime != null);
            bool peptideIdTimes = (settings.PeptideSettings.Libraries.HasLibraries &&
                                   settings.TransitionSettings.FullScan.IsEnabled);
            if (displayType != DisplayTypeChrom.base_peak && displayType != DisplayTypeChrom.tic)
            {
                if (selectedTreeNode is TransitionTreeNode && GraphChromatogram.IsSingleTransitionDisplay)
                {
                    if (HasPeak(SelectedResultsIndex, ((TransitionTreeNode)selectedTreeNode).DocNode))
                    {
                        menuStrip.Items.Insert(iInsert++, applyPeakAllGraphMenuItem);
                        menuStrip.Items.Insert(iInsert++, applyPeakSubsequentGraphMenuItem);
                        removePeakGraphMenuItem.DropDownItems.Add(new ToolStripMenuItem());
                        menuStrip.Items.Insert(iInsert++, removePeakGraphMenuItem);
                        menuStrip.Items.Insert(iInsert++, toolStripSeparator33);
                    }
                }
                else if ((selectedTreeNode is TransitionTreeNode && displayType == DisplayTypeChrom.all) ||
                        (selectedTreeNode is TransitionGroupTreeNode) ||
                        (selectedTreeNode is PeptideTreeNode && ((PeptideTreeNode)selectedTreeNode).DocNode.Children.Any()))
                {
                    menuStrip.Items.Insert(iInsert++, applyPeakAllGraphMenuItem);
                    menuStrip.Items.Insert(iInsert++, applyPeakSubsequentGraphMenuItem);

                    var nodeGroupTree = SequenceTree.GetNodeOfType<TransitionGroupTreeNode>();
                    bool hasPeak = nodeGroupTree != null
                        ? HasPeak(SelectedResultsIndex, nodeGroupTree.DocNode)
                        : SequenceTree.GetNodeOfType<PeptideTreeNode>().DocNode.TransitionGroups.Any(tranGroup => HasPeak(SelectedResultsIndex, tranGroup));

                    if (hasPeak)
                    {
                        removePeakGraphMenuItem.DropDownItems.Clear();
                        menuStrip.Items.Insert(iInsert++, removePeakGraphMenuItem);
                    }
                    menuStrip.Items.Insert(iInsert++, toolStripSeparator33);
                }
            }
            legendChromContextMenuItem.Checked = set.ShowChromatogramLegend;
            menuStrip.Items.Insert(iInsert++, legendChromContextMenuItem);
            var fullScan = Document.Settings.TransitionSettings.FullScan;
            if (ChromatogramCache.FORMAT_VERSION_CACHE > ChromatogramCache.FORMAT_VERSION_CACHE_4
                    && fullScan.IsEnabled
                    && (fullScan.IsHighResPrecursor || fullScan.IsHighResProduct))
            {
                massErrorContextMenuItem.Checked = set.ShowMassError;
                menuStrip.Items.Insert(iInsert++, massErrorContextMenuItem);
            }
            peakBoundariesContextMenuItem.Checked = set.ShowPeakBoundaries;
            menuStrip.Items.Insert(iInsert++, peakBoundariesContextMenuItem);
            menuStrip.Items.Insert(iInsert++, retentionTimesContextMenuItem);
            if (retentionTimesContextMenuItem.DropDownItems.Count == 0)
            {
                retentionTimesContextMenuItem.DropDownItems.AddRange(new ToolStripItem[]
                    {
                        allRTContextMenuItem,
                        bestRTContextMenuItem,
                        thresholdRTContextMenuItem,
                        noneRTContextMenuItem
                    });
            }
            if (retentionPredict)
            {
                retentionTimePredContextMenuItem.Checked = set.ShowRetentionTimePred;
                menuStrip.Items.Insert(iInsert++, retentionTimePredContextMenuItem);
            }
            bool alignedTimes = settings.HasAlignedTimes();
            bool unalignedTimes = settings.HasUnalignedTimes();
            if (peptideIdTimes || alignedTimes || unalignedTimes)
            {
                menuStrip.Items.Insert(iInsert++, peptideIDTimesContextMenuItem);
                peptideIDTimesContextMenuItem.DropDownItems.Clear();
                idTimesNoneContextMenuItem.Checked = false;
                peptideIDTimesContextMenuItem.DropDownItems.Add(idTimesNoneContextMenuItem);
                if (peptideIdTimes)
                {
                    idTimesMatchingContextMenuItem.Checked = set.ShowPeptideIdTimes;
                    peptideIDTimesContextMenuItem.DropDownItems.Add(idTimesMatchingContextMenuItem);
                }
                if (settings.HasAlignedTimes())
                {
                    idTimesAlignedContextMenuItem.Checked = set.ShowAlignedPeptideIdTimes;
                    peptideIDTimesContextMenuItem.DropDownItems.Add(idTimesAlignedContextMenuItem);
                }
                if (settings.HasUnalignedTimes())
                {

                    idTimesOtherContextMenuItem.Checked = set.ShowUnalignedPeptideIdTimes;
                    peptideIDTimesContextMenuItem.DropDownItems.Add(idTimesOtherContextMenuItem);
                }
                idTimesNoneContextMenuItem.Checked = !peptideIDTimesContextMenuItem.DropDownItems
                                                                                   .Cast<ToolStripMenuItem>()
                                                                                   .Any(idItem => idItem.Checked);
            }
            menuStrip.Items.Insert(iInsert++, toolStripSeparator16);
            menuStrip.Items.Insert(iInsert++, transitionsContextMenuItem);
            // Sometimes child menuitems are stripped from the parent
            if (transitionsContextMenuItem.DropDownItems.Count == 0)
            {
                transitionsContextMenuItem.DropDownItems.AddRange(new ToolStripItem[]
                    {
                        allTranContextMenuItem,
                        precursorsTranContextMenuItem,
                        productsTranContextMenuItem,
                        singleTranContextMenuItem,
                        totalTranContextMenuItem,
                        toolStripSeparatorTran,
                        basePeakContextMenuItem,
                        ticContextMenuItem,
                        toolStripSeparatorSplitGraph,
                        splitGraphContextMenuItem,
                    });
            }
            menuStrip.Items.Insert(iInsert++, transformChromContextMenuItem);
            // Sometimes child menuitems are stripped from the parent
            if (transformChromContextMenuItem.DropDownItems.Count == 0)
            {
                transformChromContextMenuItem.DropDownItems.AddRange(new ToolStripItem[]
                    {
                        transformChromNoneContextMenuItem,
                        secondDerivativeContextMenuItem,
                        firstDerivativeContextMenuItem,
                        smoothSGChromContextMenuItem
                    });
            }
            menuStrip.Items.Insert(iInsert++, toolStripSeparator17);
            menuStrip.Items.Insert(iInsert++, autoZoomContextMenuItem);
            // Sometimes child menuitems are stripped from the parent
            if (autoZoomContextMenuItem.DropDownItems.Count == 0)
            {
                autoZoomContextMenuItem.DropDownItems.AddRange(new ToolStripItem[]
                    {
                        autoZoomNoneContextMenuItem,
                        autoZoomBestPeakContextMenuItem,
                        autoZoomRTWindowContextMenuItem,
                        autoZoomBothContextMenuItem
                    });
            }
            lockYChromContextMenuItem.Checked = set.LockYChrom;
            menuStrip.Items.Insert(iInsert++, lockYChromContextMenuItem);
            synchronizeZoomingContextMenuItem.Checked = set.AutoZoomAllChromatograms;
            menuStrip.Items.Insert(iInsert++, synchronizeZoomingContextMenuItem);
            iInsert = InsertAlignmentMenuItems(menuStrip.Items, chromFileInfoId, iInsert);
            menuStrip.Items.Insert(iInsert++, toolStripSeparator18);
            menuStrip.Items.Insert(iInsert++, chromPropsContextMenuItem);
            menuStrip.Items.Insert(iInsert, toolStripSeparator19);

            // Remove some ZedGraph menu items not of interest
            foreach (var item in items)
            {
                string tag = (string)item.Tag;
                if (tag == "set_default" || tag == "show_val") // Not L10N
                    menuStrip.Items.Remove(item);
            }
            CopyEmfToolStripMenuItem.AddToContextMenu(zedGraphControl, menuStrip);
        }
Example #38
0
 public float? GetSchedulingTime(ChromFileInfoId fileId)
 {
     return GetMeasuredRetentionTime(fileId);
 }
Example #39
0
 /// <summary>
 /// If the predicted retention time is auto calculated, add a "Show {Prediction} score" menu item.
 /// If there are retention time alignments available for the specified chromFileInfoId, then adds 
 /// a "Align Times To {Specified File}" menu item to a context menu.
 /// </summary>
 private int InsertAlignmentMenuItems(ToolStripItemCollection items, ChromFileInfoId chromFileInfoId, int iInsert)
 {
     var predictRT = Document.Settings.PeptideSettings.Prediction.RetentionTime;
     if (predictRT != null && predictRT.IsAutoCalculated)
     {
         var menuItem = new ToolStripMenuItem(string.Format(Resources.SkylineWindow_ShowCalculatorScoreFormat, predictRT.Calculator.Name), null,
             (sender, eventArgs)=>AlignToRtPrediction=!AlignToRtPrediction)
             {
                 Checked = AlignToRtPrediction,
             };
         items.Insert(iInsert++, menuItem);
     }
     if (null != chromFileInfoId && DocumentUI.Settings.HasResults &&
         !DocumentUI.Settings.DocumentRetentionTimes.FileAlignments.IsEmpty)
     {
         foreach (var chromatogramSet in DocumentUI.Settings.MeasuredResults.Chromatograms)
         {
             var chromFileInfo = chromatogramSet.MSDataFileInfos
                                                .FirstOrDefault(
                                                    chromFileInfoMatch =>
                                                    ReferenceEquals(chromFileInfoMatch.FileId, chromFileInfoId));
             if (null == chromFileInfo)
             {
                 continue;
             }
             string fileItemName = Path.GetFileNameWithoutExtension(SampleHelp.GetFileName(chromFileInfo.FilePath));
             var menuItemText = string.Format(Resources.SkylineWindow_AlignTimesToFileFormat, fileItemName);
             var alignToFileItem = new ToolStripMenuItem(menuItemText);
             if (ReferenceEquals(chromFileInfoId, AlignToFile))
             {
                 alignToFileItem.Click += (sender, eventArgs) => AlignToFile = null;
                 alignToFileItem.Checked = true;
             }
             else
             {
                 alignToFileItem.Click += (sender, eventArgs) => AlignToFile = chromFileInfoId;
                 alignToFileItem.Checked = false;
             }
             items.Insert(iInsert++, alignToFileItem);
         }
     }
     return iInsert;
 }
Example #40
0
 private string GetGraphChromStrings(int iResult, ChromFileInfoId fileId, out MsDataFileUri filePath)
 {
     filePath = null;
     if (iResult != -1)
     {
         var settings = DocumentUI.Settings;
         if (settings.HasResults && iResult < settings.MeasuredResults.Chromatograms.Count)
         {
             var chromatogramSet = settings.MeasuredResults.Chromatograms[iResult];
             if (fileId != null)
                 filePath = chromatogramSet.GetFileInfo(fileId).FilePath;
             return chromatogramSet.Name;
         }
     }
     return null;
 }
Example #41
0
 public Bookmark(IdentityPath identityPath, ChromFileInfoId chromFileInfoId, int optStep)
 {
     IdentityPath = identityPath ?? IdentityPath.ROOT;
     ChromFileInfoId = chromFileInfoId;
     OptStep = optStep;
 }
Example #42
0
 public ChromFileInfo GetFileInfo(ChromFileInfoId fileId)
 {
     return GetFileInfo(IndexOfId(fileId));
 }
Example #43
0
 public ResultFileKey(int replicateIndex, ChromFileInfoId chromFileInfoId, int optimizationStep)
 {
     ReplicateIndex = replicateIndex;
     ChromFileInfoId = chromFileInfoId;
     OptimizationStep = optimizationStep;
 }
Example #44
0
 public int IndexOfId(ChromFileInfoId fileId)
 {
     return MSDataFileInfos.IndexOf(info => ReferenceEquals(info.Id, fileId));
 }
Example #45
0
 public string GetFileSaveId(ChromFileInfoId fileId)
 {
     return GetOrdinalSaveId(IndexOfId(fileId));
 }