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); } } }
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); } } }
public IonAbundances(TransitionGroupDocNode nodeTranGroup, ChromatogramGroupInfo chromGroupInfo, float mzMatchTolerance, int peakIndex) : this() { foreach (var nodeTran in nodeTranGroup.Transitions) { var chromInfoCached = chromGroupInfo.GetTransitionInfo((float)nodeTran.Mz, mzMatchTolerance); if (chromInfoCached == null) { continue; } Add(nodeTran, chromInfoCached.GetPeak(peakIndex).Area); } }
public override bool GetChromatogram( int id, string modifiedSequence, Color peptideColor, out ChromExtra extra, out float[] times, out int[] scanIndexes, out float[] intensities, out float[] massErrors) { var chromKeyIndices = _chromKeyIndices[id]; if (_lastChromGroupInfo == null || _lastIndices.GroupIndex != chromKeyIndices.GroupIndex) { _lastChromGroupInfo = _cache.LoadChromatogramInfo(chromKeyIndices.GroupIndex); _lastChromGroupInfo.ReadChromatogram(_cache); } _lastIndices = chromKeyIndices; var tranInfo = _lastChromGroupInfo.GetTransitionInfo(chromKeyIndices.TranIndex); times = tranInfo.Times; intensities = tranInfo.Intensities; massErrors = null; if (tranInfo.MassError10Xs != null) { massErrors = tranInfo.MassError10Xs.Select(m => m / 10.0f).ToArray(); } scanIndexes = null; if (tranInfo.ScanIndexes != null) { scanIndexes = tranInfo.ScanIndexes[(int)chromKeyIndices.Key.Source]; } // Assume that each chromatogram will be read once, though this may // not always be completely true. _readChromatograms++; // But avoid reaching 100% before reading is actually complete SetPercentComplete(Math.Min(99, 100 * _readChromatograms / _chromKeyIndices.Length)); extra = new ChromExtra(chromKeyIndices.StatusId, chromKeyIndices.StatusRank); // Display in AllChromatogramsGraph if (chromKeyIndices.Key.Precursor != 0 && Status is ChromatogramLoadingStatus) { ((ChromatogramLoadingStatus)Status).Transitions.AddTransition( modifiedSequence, peptideColor, chromKeyIndices.StatusId, chromKeyIndices.StatusRank, times, intensities); } return(true); }
private static ChromPeak GetLargestPeak(TransitionGroupDocNode nodeTranGroup, ChromatogramGroupInfo chromGroupInfo, int peakIndex, float mzMatchTolerance) { var largestPeak = ChromPeak.EMPTY; foreach (var peak in from transitionDocNode in nodeTranGroup.Transitions select chromGroupInfo.GetTransitionInfo((float)transitionDocNode.Mz, mzMatchTolerance) into chromInfo where chromInfo != null select chromInfo.GetPeak(peakIndex)) { if (peak.Height > largestPeak.Height) { largestPeak = peak; } } return(largestPeak); }
public override bool GetChromatogram( int id, string modifiedSequence, Color peptideColor, out ChromExtra extra, out float[] times, out int[] scanIndexes, out float[] intensities, out float[] massErrors) { var chromKeyIndices = _chromKeyIndices[id]; if (_lastChromGroupInfo == null || _lastIndices.GroupIndex != chromKeyIndices.GroupIndex) { _lastChromGroupInfo = _cache.LoadChromatogramInfo(chromKeyIndices.GroupIndex); _lastChromGroupInfo.ReadChromatogram(_cache); } _lastIndices = chromKeyIndices; var tranInfo = _lastChromGroupInfo.GetTransitionInfo(chromKeyIndices.TranIndex); times = tranInfo.Times; intensities = tranInfo.Intensities; massErrors = null; if (tranInfo.MassError10Xs != null) { massErrors = tranInfo.MassError10Xs.Select(m => m / 10.0f).ToArray(); } scanIndexes = null; if (tranInfo.ScanIndexes != null) { scanIndexes = tranInfo.ScanIndexes[(int)chromKeyIndices.Key.Source]; } SetPercentComplete(100 * id / _chromKeyIndices.Length); extra = new ChromExtra(chromKeyIndices.StatusId, chromKeyIndices.StatusRank); // Display in AllChromatogramsGraph if (chromKeyIndices.Key.Precursor != 0) { LoadingStatus.Transitions.AddTransition( modifiedSequence, peptideColor, chromKeyIndices.StatusId, chromKeyIndices.StatusRank, times, intensities); } return(true); }
public override bool GetChromatogram(int id, Target modifiedSequence, Color peptideColor, out ChromExtra extra, out TimeIntensities timeIntensities) { var chromKeyIndices = _chromKeyIndices[id]; if (_lastChromGroupInfo == null || _lastIndices.GroupIndex != chromKeyIndices.GroupIndex) { _lastChromGroupInfo = _cache.LoadChromatogramInfo(chromKeyIndices.GroupIndex); _lastChromGroupInfo.ReadChromatogram(_cache); } _lastIndices = chromKeyIndices; var tranInfo = _lastChromGroupInfo.GetTransitionInfo(chromKeyIndices.TranIndex); timeIntensities = tranInfo.TimeIntensities; // Assume that each chromatogram will be read once, though this may // not always be completely true. _readChromatograms++; // But avoid reaching 100% before reading is actually complete SetPercentComplete(Math.Min(99, 100 * _readChromatograms / _chromKeyIndices.Length)); extra = new ChromExtra(chromKeyIndices.StatusId, chromKeyIndices.StatusRank); // Display in AllChromatogramsGraph if (chromKeyIndices.Key.Precursor != 0 && Status is ChromatogramLoadingStatus) { ((ChromatogramLoadingStatus)Status).Transitions.AddTransition( modifiedSequence, peptideColor, chromKeyIndices.StatusId, chromKeyIndices.StatusRank, timeIntensities.Times, timeIntensities.Intensities); } return(true); }
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)); } }
private static ChromPeak GetLargestPeak(TransitionGroupDocNode nodeTranGroup, ChromatogramGroupInfo chromGroupInfo, int peakIndex, float mzMatchTolerance) { var largestPeak = ChromPeak.EMPTY; foreach (var peak in from transitionDocNode in nodeTranGroup.Transitions select chromGroupInfo.GetTransitionInfo((float) transitionDocNode.Mz, mzMatchTolerance) into chromInfo where chromInfo != null select chromInfo.GetPeak(peakIndex)) { if (peak.Height > largestPeak.Height) largestPeak = peak; } return largestPeak; }
public IonAbundances(TransitionGroupDocNode nodeTranGroup, ChromatogramGroupInfo chromGroupInfo, float mzMatchTolerance, int peakIndex) : this() { foreach (var nodeTran in nodeTranGroup.Transitions) { var chromInfoCached = chromGroupInfo.GetTransitionInfo((float) nodeTran.Mz, mzMatchTolerance); if (chromInfoCached == null) continue; Add(nodeTran, chromInfoCached.GetPeak(peakIndex).Area); } }