public void FindPeaks(double[] retentionTimes, TimeIntervals timeIntervals, ExplicitRetentionTimeInfo explicitRT) { Finder = Crawdads.NewCrawdadPeakFinder(); Finder.SetChromatogram(Times, Intensities); if (timeIntervals == null) { RawPeaks = Finder.CalcPeaks(MAX_PEAKS, TimesToIndices(retentionTimes)); } else { var identifiedIndices = TimesToIndices(retentionTimes); var allPeaks = timeIntervals.Intervals.SelectMany(interval => FindIntervalPeaks(interval.Key, interval.Value, identifiedIndices)); RawPeaks = allPeaks.OrderByDescending(peak => Tuple.Create(peak.Identified, peak.Area)) .Take(MAX_PEAKS).ToArray(); } // Calculate smoothing for later use in extending the Crawdad peaks IntensitiesSmooth = ChromatogramInfo.SavitzkyGolaySmooth(Intensities.ToArray()); // Accept only peaks within the user-provided RT window, if any if (explicitRT != null) { var winLow = (float)(explicitRT.RetentionTime - 0.5 * (explicitRT.RetentionTimeWindow ?? 0)); var winHigh = winLow + (float)(explicitRT.RetentionTimeWindow ?? 0); RawPeaks = RawPeaks.Where(rp => { var t = Times[rp.TimeIndex]; return(winLow <= t && t <= winHigh); }); } }
public static void MakeChromatogramInfo(SignedMz precursorMz, LibraryChromGroup chromGroup, LibraryChromGroup.ChromData chromData, out ChromatogramInfo chromatogramInfo, out TransitionChromInfo transitionChromInfo) { var crawPeakFinder = Crawdads.NewCrawdadPeakFinder(); crawPeakFinder.SetChromatogram(chromGroup.Times, chromData.Intensities); var crawdadPeak = crawPeakFinder.GetPeak( FindNearestIndex(chromGroup.Times, (float)chromGroup.StartTime), FindNearestIndex(chromGroup.Times, (float)chromGroup.EndTime)); var chromPeak = new ChromPeak(crawPeakFinder, crawdadPeak, 0, chromGroup.Times, chromData.Intensities, null); transitionChromInfo = new TransitionChromInfo(null, 0, chromPeak, new float?[0], Annotations.EMPTY, UserSet.FALSE); var peaks = new[] { chromPeak }; var header = new ChromGroupHeaderInfo(precursorMz, 0, // file index 1, // numTransitions 0, // startTransitionIndex peaks.Length, // numPeaks 0, // startPeakIndex 0, // startscoreindex 0, // maxPeakIndex chromGroup.Times.Length, // numPoints 0, // compressedSize 0, // uncompressedsize 0, //location 0, -1, -1, null, null); chromatogramInfo = new ChromatogramInfo(header, new Dictionary <Type, int>(), 0, new ChromCachedFile[0], new[] { new ChromTransition(chromData.Mz, 0, 0, 0, ChromSource.unknown), }, peaks, null, chromGroup.Times, new[] { chromData.Intensities }, null, null); }
public static void MakeChromatogramInfo(double precursorMz, LibraryChromGroup chromGroup, LibraryChromGroup.ChromData chromData, out ChromatogramInfo chromatogramInfo, out TransitionChromInfo transitionChromInfo) { var crawPeakFinder = new CrawdadPeakFinder(); crawPeakFinder.SetChromatogram(chromGroup.Times, chromData.Intensities); var crawdadPeak = crawPeakFinder.GetPeak( FindNearestIndex(chromGroup.Times, (float)chromGroup.StartTime), FindNearestIndex(chromGroup.Times, (float)chromGroup.EndTime)); var chromPeak = new ChromPeak(crawPeakFinder, crawdadPeak, 0, chromGroup.Times, chromData.Intensities, null); transitionChromInfo = new TransitionChromInfo(null, 0, chromPeak, new float?[0], Annotations.EMPTY, UserSet.FALSE); var peaks = new[] { chromPeak }; var header = new ChromGroupHeaderInfo5(new ChromGroupHeaderInfo( (float)precursorMz, 0, 1, 0, peaks.Length, 0, 0, chromGroup.Times.Length, 0, 0)); chromatogramInfo = new ChromatogramInfo(header, new Dictionary <Type, int>(), 0, new ChromCachedFile[0], new[] { new ChromTransition(chromData.Mz, 0, 0, 0, ChromSource.unknown), }, peaks, null, chromGroup.Times, new[] { chromData.Intensities }, null, null); }
public static int FindScanIndex(ChromatogramInfo chromatogramInfo, double retentionTime) { if (chromatogramInfo.TimeIntensities.ScanIds == null) { return(-1); } return(FindScanIndex(chromatogramInfo.Times, retentionTime, 0, chromatogramInfo.Times.Count)); }
public void FindPeaks(double[] retentionTimes) { Finder = Crawdads.NewCrawdadPeakFinder(); Finder.SetChromatogram(Times, Intensities); RawPeaks = Finder.CalcPeaks(MAX_PEAKS, TimesToIndices(retentionTimes)); // Calculate smoothing for later use in extending the Crawdad peaks IntensitiesSmooth = ChromatogramInfo.SavitzkyGolaySmooth(Intensities.ToArray()); }
public SummaryTransitionPeakData(SrmDocument document, TransitionDocNode nodeTran, ChromatogramSet chromatogramSet, ChromatogramInfo tranChromInfo) { NodeTran = nodeTran; _chromInfo = tranChromInfo; }
public void FindPeaks(double[] retentionTimes, bool requireDocNode) { Finder = new CrawdadPeakFinder(); Finder.SetChromatogram(Times, Intensities); if (requireDocNode && DocNode == null) { RawPeaks = new CrawdadPeak[0]; } else { RawPeaks = Finder.CalcPeaks(MAX_PEAKS, TimesToIndices(retentionTimes)); // Calculate smoothing for later use in extending the Crawdad peaks IntensitiesSmooth = ChromatogramInfo.SavitzkyGolaySmooth(Intensities); } }
public static void MakeChromatogramInfo(SignedMz precursorMz, LibraryChromGroup chromGroup, LibraryChromGroup.ChromData chromData, out ChromatogramInfo chromatogramInfo, out TransitionChromInfo transitionChromInfo) { var timeIntensities = new TimeIntensities(chromGroup.Times, chromData.Intensities, null, null); var crawPeakFinder = Crawdads.NewCrawdadPeakFinder(); crawPeakFinder.SetChromatogram(chromGroup.Times, chromData.Intensities); var crawdadPeak = crawPeakFinder.GetPeak( FindNearestIndex(chromGroup.Times, (float)chromGroup.StartTime), FindNearestIndex(chromGroup.Times, (float)chromGroup.EndTime)); var chromPeak = new ChromPeak(crawPeakFinder, crawdadPeak, 0, timeIntensities, null); transitionChromInfo = new TransitionChromInfo(null, 0, chromPeak, IonMobilityFilter.EMPTY, // CONSIDER(bspratt) IMS in chromatogram libraries? new float?[0], Annotations.EMPTY, UserSet.FALSE); var peaks = new[] { chromPeak }; var header = new ChromGroupHeaderInfo(precursorMz, 0, // file index 1, // numTransitions 0, // startTransitionIndex peaks.Length, // numPeaks 0, // startPeakIndex 0, // startscoreindex 0, // maxPeakIndex chromGroup.Times.Length, // numPoints 0, // compressedSize 0, // uncompressedsize 0, //location 0, -1, -1, null, null, null, eIonMobilityUnits.none); // CONSIDER(bspratt) IMS in chromatogram libraries? var driftTimeFilter = IonMobilityFilter.EMPTY; // CONSIDER(bspratt) IMS in chromatogram libraries? var groupInfo = new ChromatogramGroupInfo(header, new Dictionary <Type, int>(), new byte[0], new ChromCachedFile[0], new[] { new ChromTransition(chromData.Mz, 0, (float)(driftTimeFilter.IonMobility.Mobility ?? 0), (float)(driftTimeFilter.IonMobilityExtractionWindowWidth ?? 0), ChromSource.unknown), }, peaks, null) { TimeIntensitiesGroup = TimeIntensitiesGroup.Singleton(timeIntensities) }; chromatogramInfo = new ChromatogramInfo(groupInfo, 0); }
private void VerifyChromatogramData(CultureInfo cultureInfo, ChromatogramInfo chromatogram, DataGridViewRow row, DataGridViewColumn colTimes, DataGridViewColumn colIntensities, DataGridViewColumn colMassErrors, DataGridViewColumn colSpectrumIds) { var csvSeparator = TextUtil.GetCsvSeparator(cultureInfo); var strTimes = (string)row.Cells[colTimes.Index].FormattedValue; Assert.IsNotNull(strTimes); var times = strTimes.Split(csvSeparator) .Select(value => float.Parse(value, cultureInfo)); VerifyFloatsEqual(chromatogram.Times, times, colTimes.DefaultCellStyle.Format); var strIntensities = (string)row.Cells[colIntensities.Index].FormattedValue; Assert.IsNotNull(strIntensities); var rawIntensities = strIntensities.Split(csvSeparator) .Select(value => float.Parse(value, cultureInfo)); VerifyFloatsEqual(chromatogram.Intensities, rawIntensities, colIntensities.DefaultCellStyle.Format); var strMassErrors = (string)row.Cells[colMassErrors.Index].FormattedValue; Assert.IsNotNull(strMassErrors); var rawMassErrors = strMassErrors.Split(csvSeparator) .Select(value => float.Parse(value, cultureInfo)); VerifyFloatsEqual(chromatogram.TimeIntensities.MassErrors, rawMassErrors, colMassErrors.DefaultCellStyle.Format); var strRawSpectrumIds = (string)row.Cells[colSpectrumIds.Index].FormattedValue; Assert.IsNotNull(strRawSpectrumIds); var rawSpectrumIds = strRawSpectrumIds.Split(csvSeparator).ToArray(); var msDataFileScanIds = SkylineWindow.Document.Settings.MeasuredResults.LoadMSDataFileScanIds( chromatogram.FilePath); var expectedSpectrumIds = chromatogram.TimeIntensities.ScanIds .Select(msDataFileScanIds.GetMsDataFileSpectrumId).ToArray(); CollectionAssert.AreEqual(expectedSpectrumIds, rawSpectrumIds); }
private void AddPeakRawTimes(GraphPane graphPane, ICollection <GraphObj> annotations, ScaledRetentionTime startTime, ScaledRetentionTime endTime, ChromatogramInfo info) { var hasTimes = info.RawTimes != null && info.RawTimes.Any(); // has measured points var scaledHeight = graphPane.YAxis.Scale.Max / 20; // 5% of graph pane height var rawtimes = new List <double>(); if (hasTimes) { rawtimes.AddRange(GetRawTimes(startTime, endTime, info)); if (rawtimes.Count == 0) { return; } foreach (var time in rawtimes) { LineObj stick = new LineObj(time, scaledHeight, time, 0) { IsClippedToChartRect = true, Location = { CoordinateFrame = CoordType.AxisXYScale }, ZOrder = ZOrder.A_InFront, Line = { Width = 1, Style = DashStyle.Dash, Color = ColorSelected }, Tag = new GraphObjTag(this, GraphObjType.raw_time, new ScaledRetentionTime(time)), }; annotations.Add(stick); } } var countTxt = hasTimes ? " " + rawtimes.Count : " ?"; // Not L10N var isBold = !hasTimes; // Question mark if no times exist is visually clearer if bold TextObj pointCount = new TextObj(countTxt, endTime.DisplayTime, scaledHeight) // Not L10N { FontSpec = new FontSpec(FontSpec.Family, FontSpec.Size, ColorSelected, isBold, false, false) { Border = new Border { IsVisible = false }, Fill = new Fill() }, Location = { AlignH = AlignH.Left, AlignV = AlignV.Bottom } }; annotations.Add(pointCount); }
public ChromGraphItem(TransitionGroupDocNode transitionGroupNode, TransitionDocNode transition, ChromatogramInfo chromatogram, TransitionChromInfo tranPeakInfo, IRegressionFunction timeRegressionFunction, bool[] annotatePeaks, double[] dotProducts, double bestProduct, bool isFullScanMs, bool isSummary, int step, Color color, float fontSize, int width, FullScanInfo fullScanInfo = null) { TransitionGroupNode = transitionGroupNode; TransitionNode = transition; Chromatogram = chromatogram; TransitionChromInfo = tranPeakInfo; TimeRegressionFunction = timeRegressionFunction; Color = color; FullScanInfo = fullScanInfo; _step = step; _fontSpec = CreateFontSpec(color, fontSize); _width = width; _dotProducts = dotProducts; _bestProduct = bestProduct; _isFullScanMs = isFullScanMs; _isSummary = isSummary; _arrayLabelIndexes = new int[annotatePeaks.Length]; if (chromatogram == null) { _measuredTimes = new double[0]; _displayTimes = _measuredTimes; _intensities = new double[0]; } else { // Cache values early to avoid accessing slow enumerators // which show up under profiling. Chromatogram.AsArrays(out _measuredTimes, out _intensities); if (TimeRegressionFunction == null) { _displayTimes = _measuredTimes; } else { _displayTimes = _measuredTimes.Select(TimeRegressionFunction.GetY).ToArray(); } // Add peak times to hash set for labeling int iLastStart = 0; for (int i = 0; i < chromatogram.NumPeaks; i++) { int maxIndex = -1; if (annotatePeaks[i]) { ChromPeak peak = chromatogram.GetPeak(i); maxIndex = GetMaxIndex(peak.StartTime, peak.EndTime, ref iLastStart); } _arrayLabelIndexes[i] = maxIndex; if (maxIndex != -1 && !_annotatedTimes.ContainsKey(maxIndex)) _annotatedTimes.Add(maxIndex, i); } // Calculate best peak index if (tranPeakInfo != null) { iLastStart = 0; _bestPeakTimeIndex = GetMaxIndex(tranPeakInfo.StartRetentionTime, tranPeakInfo.EndRetentionTime, ref iLastStart); } } }
private void DisplayTransitions(IRegressionFunction timeRegressionFunction, TransitionDocNode nodeTranSelected, ChromatogramSet chromatograms, float mzMatchTolerance, TransitionGroupDocNode nodeGroup, ChromatogramGroupInfo chromGroupInfo, PaneKey graphPaneKey, DisplayTypeChrom displayType, ref double bestStartTime, ref double bestEndTime) { var fileId = chromatograms.FindFile(chromGroupInfo); // Get points for all transitions, and pick maximum peaks. ChromatogramInfo[] arrayChromInfo; var displayTrans = GetDisplayTransitions(nodeGroup, displayType).ToArray(); int numTrans = displayTrans.Length; int numSteps = 0; bool allowEmpty = false; if (IsSingleTransitionDisplay && nodeTranSelected != null) { if (!displayTrans.Contains(nodeTranSelected)) { arrayChromInfo = new ChromatogramInfo[0]; displayTrans = new TransitionDocNode[0]; numTrans = 0; } else { arrayChromInfo = chromGroupInfo.GetAllTransitionInfo((float) nodeTranSelected.Mz, mzMatchTolerance, chromatograms.OptimizationFunction); if (chromatograms.OptimizationFunction != null) { // Make sure the number of steps matches what will show up in the summary // graphs, or the colors won't match up. int numStepsExpected = chromatograms.OptimizationFunction.StepCount*2 + 1; if (arrayChromInfo.Length != numStepsExpected) { arrayChromInfo = ResizeArrayChromInfo(arrayChromInfo, numStepsExpected); allowEmpty = true; } } numTrans = arrayChromInfo.Length; displayTrans = new TransitionDocNode[numTrans]; for (int i = 0; i < numTrans; i++) displayTrans[i] = nodeTranSelected; } numSteps = numTrans/2; } else { arrayChromInfo = new ChromatogramInfo[numTrans]; for (int i = 0; i < numTrans; i++) { var nodeTran = displayTrans[i]; // Get chromatogram info for this transition arrayChromInfo[i] = chromGroupInfo.GetTransitionInfo((float) nodeTran.Mz, mzMatchTolerance); } } int bestPeakTran = -1; TransitionChromInfo tranPeakInfo = null; float maxPeakHeight = float.MinValue; int numPeaks = chromGroupInfo.NumPeaks; var maxPeakTrans = new int[numPeaks]; var maxPeakHeights = new float[numPeaks]; for (int i = 0; i < numPeaks; i++) maxPeakHeights[i] = float.MinValue; var transform = Transform; // Prepare arrays of values for library dot-product double[] expectedIntensities = null; double[][] peakAreas = null; bool isShowingMs = displayTrans.Any(nodeTran => nodeTran.IsMs1); bool isShowingMsMs = displayTrans.Any(nodeTran => !nodeTran.IsMs1); bool isFullScanMs = DocumentUI.Settings.TransitionSettings.FullScan.IsEnabledMs && isShowingMs; if ((isFullScanMs && !isShowingMsMs && nodeGroup.HasIsotopeDist) || (!isFullScanMs && nodeGroup.HasLibInfo)) { expectedIntensities = new double[numTrans]; peakAreas = new double[numPeaks][]; for (int i = 0; i < numPeaks; i++) peakAreas[i] = new double[numTrans]; } // Find the transition with the maximum peak height for the best peak for (int i = 0; i < numTrans; i++) { var nodeTran = displayTrans[i]; int step = (numSteps > 0 ? i - numSteps : 0); var transitionChromInfo = GetTransitionChromInfo(nodeTran, _chromIndex, fileId, step); if (transitionChromInfo == null) continue; if (maxPeakHeight < transitionChromInfo.Height) { maxPeakHeight = transitionChromInfo.Height; bestPeakTran = i; tranPeakInfo = transitionChromInfo; } AddBestPeakTimes(transitionChromInfo, ref bestStartTime, ref bestEndTime); } for (int i = 0; i < numTrans; i++) { var nodeTran = displayTrans[i]; // Store library intensities for dot-product if (expectedIntensities != null) { if (isFullScanMs) expectedIntensities[i] = nodeTran.HasDistInfo ? nodeTran.IsotopeDistInfo.Proportion : 0; else expectedIntensities[i] = nodeTran.HasLibInfo ? nodeTran.LibInfo.Intensity : 0; } var info = arrayChromInfo[i]; if (info == null) continue; // Apply any active transform info.Transform(transform); for (int j = 0; j < numPeaks; j++) { var peak = info.GetPeak(j); // Exclude any peaks between the boundaries of the chosen peak. if (IntersectPeaks(peak, tranPeakInfo)) continue; // Store peak intensity for dot-product if (peakAreas != null) peakAreas[j][i] = peak.Area; // Keep track of which transition has the max height for each peak if (maxPeakHeights[j] < peak.Height) { maxPeakHeights[j] = peak.Height; maxPeakTrans[j] = i; } } } // Calculate library dot-products, if possible double[] dotProducts = null; double bestProduct = 0; int minProductTrans = isFullScanMs ? TransitionGroupDocNode.MIN_DOT_PRODUCT_MS1_TRANSITIONS : TransitionGroupDocNode.MIN_DOT_PRODUCT_TRANSITIONS; if (peakAreas != null && numTrans >= minProductTrans) { var tranGroupChromInfo = GetTransitionGroupChromInfo(nodeGroup, fileId, _chromIndex); double? dotProduct = null; if (tranGroupChromInfo != null) { dotProduct = isFullScanMs ? tranGroupChromInfo.IsotopeDotProduct : tranGroupChromInfo.LibraryDotProduct; } if (dotProduct.HasValue) { bestProduct = dotProduct.Value; var statExpectedIntensities = new Statistics(expectedIntensities); for (int i = 0; i < peakAreas.Length; i++) { var statPeakAreas = new Statistics(peakAreas[i]); double dotProductCurrent = statPeakAreas.NormalizedContrastAngleSqrt(statExpectedIntensities); // Only show products that are greater than the best peak product, // and by enough to be a significant improvement. Also the library product // on the group node is stored as a float, which means the version // hear calculated as a double can be larger, but really represent // the same number. if (dotProductCurrent > bestProduct && dotProductCurrent > 0.5 && dotProductCurrent - bestProduct > 0.05) { if (dotProducts == null) dotProducts = new double[numPeaks]; dotProducts[i] = dotProductCurrent; } } } } // Create graph items int iColor = 0; int lineWidth = LineWidth; float fontSize = FontSize; // We want the product ion colors to stay the same whether they are displayed: // 1. In a single pane with the precursor ions (Transitions -> All) // 2. In a separate pane of the split graph (Transitions -> All AND Transitions -> Split Graph) // 3. In a single pane by themselves (Transition -> Products) // We will use an offset in the colors array for cases 2 and 3 so that we do not reuse the precursor ion colors. var nodeDisplayType = GetDisplayType(DocumentUI, nodeGroup); int colorOffset = 0; if(displayType == DisplayTypeChrom.products && (nodeDisplayType != DisplayTypeChrom.single || (nodeDisplayType == DisplayTypeChrom.single && chromatograms.OptimizationFunction == null))) { colorOffset = GetDisplayTransitions(nodeGroup, DisplayTypeChrom.precursors).Count(); } for (int i = 0; i < numTrans; i++) { var info = arrayChromInfo[i]; if (info == null && !allowEmpty) continue; var nodeTran = displayTrans[i]; int step = numSteps != 0 ? i - numSteps : 0; Color color; bool shade = false; int width = lineWidth; if ((numSteps == 0 && ReferenceEquals(nodeTran, nodeTranSelected) || (numSteps > 0 && step == 0))) { color = ChromGraphItem.ColorSelected; shade = true; width++; } else { color = COLORS_LIBRARY[(iColor + colorOffset) % COLORS_LIBRARY.Length]; } TransitionChromInfo tranPeakInfoGraph = null; if (bestPeakTran == i) tranPeakInfoGraph = tranPeakInfo; var scanName = nodeTran.FragmentIonName; if (nodeTran.Transition.Charge != 1) // Positive singly charged is uninteresting scanName += Transition.GetChargeIndicator(nodeTran.Transition.Charge); if (nodeTran.Transition.MassIndex != 0) scanName += Environment.NewLine + Transition.GetMassIndexText(nodeTran.Transition.MassIndex); var fullScanInfo = new FullScanInfo { ChromInfo = info, ScanName = scanName }; if (fullScanInfo.ChromInfo != null && fullScanInfo.ChromInfo.ExtractionWidth > 0) _enableTrackingDot = true; var graphItem = new ChromGraphItem(nodeGroup, nodeTran, info, tranPeakInfoGraph, timeRegressionFunction, GetAnnotationFlags(i, maxPeakTrans, maxPeakHeights), dotProducts, bestProduct, isFullScanMs, false, step, color, fontSize, width, fullScanInfo); _graphHelper.AddChromatogram(graphPaneKey, graphItem); if (shade) { ShadeGraph(tranPeakInfo,info,timeRegressionFunction,dotProducts,bestProduct,isFullScanMs,step,fontSize,width,fullScanInfo,graphPaneKey); } iColor++; } var graphPane = _graphHelper.GetGraphPane(graphPaneKey); if (graphPane == null) _enableTrackingDot = false; if (_enableTrackingDot) { graphPane.CurveList.Insert(FULLSCAN_TRACKING_INDEX, CreateScanPoint(Color.Black)); graphPane.CurveList.Insert(FULLSCAN_SELECTED_INDEX, CreateScanPoint(Color.Red)); } }
/// <summary> /// Display summed transitions for multiple selected peptides. /// </summary> private void DisplayPeptides(IRegressionFunction timeRegressionFunction, ChromatogramSet chromatograms, float mzMatchTolerance, int countLabelTypes, IList<PeptideDocNode> peptideDocNodes, ref double bestStartTime, ref double bestEndTime, out double leftPeakWidth, out double rightPeakWidth) { leftPeakWidth = 0; rightPeakWidth = 0; // Construct and add graph items for all relevant transition groups. float fontSize = FontSize; int lineWidth = LineWidth; var chromGroupInfos = ChromGroupInfos; var lookupChromGroupInfoIndex = new Dictionary<int, int>(_nodeGroups.Length); for (int i = 0; i < _nodeGroups.Length; i++) lookupChromGroupInfoIndex[_nodeGroups[i].Id.GlobalIndex] = i; // Generate a unique short identifier for each peptide. var peptideNames = new Tuple<string,bool>[peptideDocNodes.Count]; for (int i = 0; i < peptideDocNodes.Count; i++) peptideNames[i] = new Tuple<string,bool>(peptideDocNodes[i].RawTextId, peptideDocNodes[i].IsProteomic); var uniqueNames = new UniquePrefixGenerator(peptideNames, 3); var displayPeptides = new List<DisplayPeptide>(); for (int peptideIndex = 0; peptideIndex < peptideDocNodes.Count; peptideIndex++) { var peptideDocNode = peptideDocNodes[peptideIndex]; TransitionChromInfo bestPeakInfo = null; ChromatogramInfo sumInfo = null; float maxPeakHeight = float.MinValue; foreach (var precursor in peptideDocNode.TransitionGroups) { int indexInfo; if (!lookupChromGroupInfoIndex.TryGetValue(precursor.Id.GlobalIndex, out indexInfo)) continue; var chromGroupInfo = chromGroupInfos[indexInfo]; if (chromGroupInfo == null) continue; ChromFileInfoId fileId = chromatograms.FindFile(chromGroupInfo); foreach (var nodeTran in precursor.Transitions) { var info = chromGroupInfo.GetTransitionInfo((float)nodeTran.Mz, mzMatchTolerance); if (info == null) continue; if (sumInfo == null) sumInfo = info; else { float[] sumTimes; float[] sumIntensities; if (!AddTransitions.Add( info.Times, info.Intensities, sumInfo.Times, sumInfo.Intensities, out sumTimes, out sumIntensities)) continue; sumInfo = new ChromatogramInfo(sumTimes, sumIntensities); } // Keep track of which chromatogram owns the tallest member of // the peak on the document tree. var transitionChromInfo = GetTransitionChromInfo(nodeTran, _chromIndex, fileId, 0); if (transitionChromInfo == null) continue; if (transitionChromInfo.Height > maxPeakHeight) { maxPeakHeight = transitionChromInfo.Height; bestPeakInfo = transitionChromInfo; } } } if (sumInfo != null && bestPeakInfo != null) { displayPeptides.Add(new DisplayPeptide { PeptideIndex = peptideIndex, SumInfo = sumInfo, BestPeakInfo = bestPeakInfo }); } } // Order the peptides by height of best peak. displayPeptides = displayPeptides.OrderByDescending(e => e.BestPeakInfo.Height).ToList(); // Display only the top peptides. int lastPeptideIndex = Math.Min(MaxPeptidesDisplayed, displayPeptides.Count); var graphItems = new List<ChromGraphItem>(); for (int i = lastPeptideIndex-1; i >= 0; i--) // smallest peaks first for good z-ordering in graph { var bestPeakInfo = displayPeptides[i].BestPeakInfo; var sumInfo = displayPeptides[i].SumInfo; var peptideDocNode = peptideDocNodes[displayPeptides[i].PeptideIndex]; // Intersect best peak with summed transition. if (bestPeakInfo != null && sumInfo.Times.Length > 0) { float startRetentionTime = Math.Max(bestPeakInfo.StartRetentionTime, sumInfo.Times[0]); float endRetentionTime = Math.Min(bestPeakInfo.EndRetentionTime, sumInfo.Times[sumInfo.Times.Length - 1]); if (endRetentionTime > startRetentionTime) { if (bestStartTime > startRetentionTime) { bestStartTime = startRetentionTime; leftPeakWidth = endRetentionTime - startRetentionTime; } if (bestEndTime < endRetentionTime) { bestEndTime = endRetentionTime; rightPeakWidth = endRetentionTime - startRetentionTime; } bestPeakInfo = new TransitionChromInfo(startRetentionTime, endRetentionTime); } } // Get peptide graph color from SequenceTree. var peptideGraphInfo = _stateProvider.GetPeptideGraphInfo(peptideDocNode); Color color = peptideGraphInfo.Color; sumInfo.Transform(Transform); bool[] annotateAll = new bool[sumInfo.NumPeaks]; ChromGraphItem graphItem = new ChromGraphItem(null, null, sumInfo, bestPeakInfo, timeRegressionFunction, annotateAll, null, 0, false, false, 0, color, fontSize, lineWidth) { CurveAnnotation = uniqueNames.GetUniquePrefix(peptideDocNode.RawTextId, peptideDocNode.IsProteomic), IdPath = _groupPaths[displayPeptides[i].PeptideIndex], GraphInfo = peptideGraphInfo }; if (peptideGraphInfo.IsSelected) graphItems.Insert(0, graphItem); else graphItems.Add(graphItem); } foreach (var graphItem in graphItems) { var curveItem = _graphHelper.AddChromatogram(new PaneKey(), graphItem); // Make the fill color under the curve more opaque if the curve is selected. var fillAlpha = graphItem.GraphInfo.IsSelected ? 60 : 15; ((LineItem)curveItem).Line.Fill = new Fill(Color.FromArgb(fillAlpha, graphItem.GraphInfo.Color)); } }
private static ChromatogramInfo[] ResizeArrayChromInfo(ChromatogramInfo[] arrayChromInfo, int numStepsExpected) { int numStepsFound = arrayChromInfo.Length; var arrayChromInfoNew = new ChromatogramInfo[numStepsExpected]; if (numStepsFound < numStepsExpected) { Array.Copy(arrayChromInfo, 0, arrayChromInfoNew, (numStepsExpected - numStepsFound) / 2, numStepsFound); } else { Array.Copy(arrayChromInfo, (numStepsFound - numStepsExpected) / 2, arrayChromInfoNew, 0, numStepsExpected); } arrayChromInfo = arrayChromInfoNew; return arrayChromInfo; }
private IEnumerable <double> GetRawTimes(ScaledRetentionTime startTime, ScaledRetentionTime endTime, ChromatogramInfo info) { double end = endTime.DisplayTime; double start = startTime.DisplayTime; var times = info.RawTimes; if (times != null) { for (int j = 0; j < times.Count; j++) { if (start > times[j]) { continue; } if (end < times[j]) { break; } yield return(times[j]); } } }
public ChromGraphItem(TransitionGroupDocNode transitionGroupNode, TransitionDocNode transition, ChromatogramInfo chromatogram, TransitionChromInfo tranPeakInfo, IRegressionFunction timeRegressionFunction, bool[] annotatePeaks, double[] dotProducts, double bestProduct, bool isFullScanMs, bool isSummary, RawTimesInfoItem?displayRawTimes, int step, Color color, float fontSize, int width, FullScanInfo fullScanInfo = null) { TransitionGroupNode = transitionGroupNode; TransitionNode = transition; Chromatogram = chromatogram; TransitionChromInfo = tranPeakInfo; TimeRegressionFunction = timeRegressionFunction; Color = color; FullScanInfo = fullScanInfo; _step = step; _fontSpec = CreateFontSpec(color, fontSize); _width = width; _dotProducts = dotProducts; _bestProduct = bestProduct; _isFullScanMs = isFullScanMs; _isSummary = isSummary; _displayRawTimes = displayRawTimes; _arrayLabelIndexes = new int[annotatePeaks.Length]; if (chromatogram == null) { _measuredTimes = new double[0]; _displayTimes = _measuredTimes; _intensities = new double[0]; } else { // Cache values early to avoid accessing slow enumerators // which show up under profiling. Chromatogram.AsArrays(out _measuredTimes, out _intensities); if (TimeRegressionFunction == null) { _displayTimes = _measuredTimes; } else { _displayTimes = _measuredTimes.Select(TimeRegressionFunction.GetY).ToArray(); } // Add peak times to hash set for labeling int iLastStart = 0; for (int i = 0; i < chromatogram.NumPeaks; i++) { int maxIndex = -1; if (annotatePeaks[i]) { ChromPeak peak = chromatogram.GetPeak(i); maxIndex = GetMaxIndex(peak.StartTime, peak.EndTime, ref iLastStart); } _arrayLabelIndexes[i] = maxIndex; if (maxIndex != -1 && !_annotatedTimes.ContainsKey(maxIndex)) { _annotatedTimes.Add(maxIndex, i); } } // Calculate best peak index if (tranPeakInfo != null) { iLastStart = 0; _bestPeakTimeIndex = GetMaxIndex(tranPeakInfo.StartRetentionTime, tranPeakInfo.EndRetentionTime, ref iLastStart); } } }
private void ShadeGraph(TransitionChromInfo tranPeakInfo, ChromatogramInfo info, IRegressionFunction timeRegressionFunction, double[] dotProducts, double bestProduct, bool isFullScanMs, int step, float fontSize, int width, FullScanInfo fullScanInfo, PaneKey graphPaneKey) { if (tranPeakInfo == null) return; // Nothing to shade float end = tranPeakInfo.EndRetentionTime; float start = tranPeakInfo.StartRetentionTime; double[] allTimes; double[] allIntensities; info.AsArrays(out allTimes, out allIntensities); var peakTimes = new List<float>(); var peakIntensities = new List<float>(); for (int j = 0; j < allTimes.Length; j++) { if (start > allTimes[j]) continue; if (end < allTimes[j]) break; peakTimes.Add((float) allTimes[j]); peakIntensities.Add((float) allIntensities[j]); } if (peakIntensities.Count == 0) return; // Add peak area shading float[] peakTimesArray = peakTimes.ToArray(); info = new ChromatogramInfo(peakTimesArray, peakIntensities.ToArray()); var peakShadeItem = new ChromGraphItem(null, null, info, null, timeRegressionFunction, new bool[info.NumPeaks], dotProducts, bestProduct, isFullScanMs, false, step, ChromGraphItem.ColorSelected, fontSize, width, fullScanInfo); var peakShadeCurveItem = _graphHelper.AddChromatogram(graphPaneKey, peakShadeItem); peakShadeCurveItem.Label.IsVisible = false; var lineItem = peakShadeCurveItem as LineItem; if (lineItem != null) { const int fillAlpha = 50; lineItem.Line.Fill = new Fill(Color.FromArgb(fillAlpha, lineItem.Color)); } // Add peak background shading float min = Math.Min(peakIntensities.First(), peakIntensities.Last()); info = new ChromatogramInfo(peakTimesArray, peakIntensities.Select(intensity => Math.Min(intensity, min)).ToArray()); var backgroundShadeItem = new ChromGraphItem(null, null, info, null, timeRegressionFunction, new bool[info.NumPeaks], dotProducts, bestProduct, isFullScanMs, false, step, Color.DarkGray, fontSize, 2, fullScanInfo); var backgroundShadeCurveItem = _graphHelper.AddChromatogram(graphPaneKey, backgroundShadeItem); backgroundShadeCurveItem.Label.IsVisible = false; var lineItem2 = backgroundShadeCurveItem as LineItem; if (lineItem2 != null) { const int fillAlpha = 70; lineItem2.Line.Fill = new Fill(Color.FromArgb(fillAlpha, Color.Black)); } }
public Chromatogram[] GetChromatograms(DocumentLocation documentLocation) { if (documentLocation == null) { return(new Chromatogram[0]); } var result = new List <Chromatogram>(); SrmDocument document = Program.MainWindow.Document; Bookmark bookmark = Bookmark.ToBookmark(documentLocation, document); IdentityPath identityPath = bookmark.IdentityPath; var nodeList = GetDocNodes(identityPath, document); TransitionDocNode transitionDocNode = null; if (nodeList.Count > 3) { transitionDocNode = (TransitionDocNode)nodeList[3]; } var measuredResults = document.Settings.MeasuredResults; var nodePep = (PeptideDocNode)(nodeList.Count > 1 ? nodeList[1] : null); if (null == nodePep) { return(result.ToArray()); } int iColor = 0; foreach (var chromatogramSet in measuredResults.Chromatograms) { foreach (var msDataFileInfo in chromatogramSet.MSDataFileInfos) { if (bookmark.ChromFileInfoId != null && !ReferenceEquals(msDataFileInfo.FileId, bookmark.ChromFileInfoId)) { continue; } foreach (var nodeGroup in nodePep.TransitionGroups) { if (nodeList.Count > 2 && !Equals(nodeGroup, nodeList[2])) { continue; } ChromatogramGroupInfo[] arrayChromInfo; measuredResults.TryLoadChromatogram( chromatogramSet, nodePep, nodeGroup, (float)document.Settings.TransitionSettings.Instrument.MzMatchTolerance, true, out arrayChromInfo); foreach (var transition in nodeGroup.Transitions) { if (transitionDocNode != null && !Equals(transitionDocNode, transition)) { continue; } foreach (var chromatogramGroup in arrayChromInfo) { for (int iTransition = 0; iTransition < chromatogramGroup.NumTransitions; iTransition++) { ChromatogramInfo transitionInfo = chromatogramGroup.GetTransitionInfo(iTransition); if (Math.Abs(transitionInfo.ProductMz - transition.Mz) > document.Settings.TransitionSettings.Instrument.MzMatchTolerance) { continue; } Color color = GraphChromatogram.COLORS_LIBRARY[iColor % GraphChromatogram.COLORS_LIBRARY.Count]; iColor++; result.Add(new Chromatogram { Intensities = transitionInfo.Intensities.ToArray(), ProductMz = transitionInfo.ProductMz.RawValue, // For negative ion mode data this will be a negative value PrecursorMz = chromatogramGroup.PrecursorMz.RawValue, // For negative ion mode data this will be a negative value Times = transitionInfo.Times.ToArray(), Color = color }); } } } } } } if (result.Count == 1) { result[0].Color = ChromGraphItem.ColorSelected; } return(result.ToArray()); }
public void Add(ChromatogramInfo chromInfo, TransitionChromInfo transitionChromInfo) { ChromInfos.Add(chromInfo); if (transitionChromInfo != null) { float height = transitionChromInfo.Height; TotalHeight += height; if (height > MaxHeight || InfoPrimary == null) { MaxHeight = height; InfoPrimary = chromInfo; TransitionInfoPrimary = transitionChromInfo; } } if (chromInfo != null) { // Sum peak heights. This may not be strictly valid, but should // work as a good approximation for deciding which peaks to label. int i = 0; foreach (var peak in chromInfo.Peaks) { // Exclude any peaks between the boundaries of the chosen peak. if (transitionChromInfo != null && transitionChromInfo.StartRetentionTime < peak.RetentionTime && peak.RetentionTime < transitionChromInfo.EndRetentionTime) continue; if (peak.IsForcedIntegration) continue; PeakHeights[i++] += peak.Height; } } }