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 RetentionTimeValues FromTransitionChromInfo(TransitionChromInfo transitionChromInfo) { if (null == transitionChromInfo || transitionChromInfo.StartRetentionTime == 0 || transitionChromInfo.EndRetentionTime == 0) { return(null); } double apexTime; if (transitionChromInfo.Height == 0) { // TransitionChromInfo.RetentionTime cannot be trusted if the height is zero, so always // set it to the midpoint between the start and end times. apexTime = (transitionChromInfo.StartRetentionTime + transitionChromInfo.EndRetentionTime) / 2; } else { apexTime = transitionChromInfo.RetentionTime; } return(new RetentionTimeValues(apexTime, transitionChromInfo.StartRetentionTime, transitionChromInfo.EndRetentionTime, transitionChromInfo.Height, transitionChromInfo.Fwhm)); }
protected override FindMatch MatchTransition(TransitionChromInfo transitionChromInfo) { if (transitionChromInfo.IsTruncated.GetValueOrDefault(false)) { return(new FindMatch(Resources.TruncatedPeakFinder_MatchTransition_Truncated_peak)); } return(null); }
protected override FindMatch MatchTransition(TransitionChromInfo transitionChromInfo) { if (transitionChromInfo.IsTruncated.GetValueOrDefault(false)) { return new FindMatch(Resources.TruncatedPeakFinder_MatchTransition_Truncated_peak); } return null; }
private float? GetValue(TransitionChromInfo chromInfo) { if (chromInfo == null) return null; if (_ratioIndex == RATIO_INDEX_NONE) return chromInfo.Area; return chromInfo.GetRatio(_ratioIndex); }
private float?GetValue(TransitionChromInfo chromInfo) { if (chromInfo == null) { return(null); } return(chromInfo.MassError); }
public static RetentionTimeValues?GetValues(TransitionChromInfo transitionChromInfo) { if (null == transitionChromInfo || transitionChromInfo.StartRetentionTime == 0 || transitionChromInfo.EndRetentionTime == 0) { return(null); } return(new RetentionTimeValues(transitionChromInfo.RetentionTime, transitionChromInfo.StartRetentionTime, transitionChromInfo.EndRetentionTime, transitionChromInfo.Fwhm)); }
public static RetentionTimeValues? GetValues(TransitionChromInfo transitionChromInfo) { if (null == transitionChromInfo || transitionChromInfo.StartRetentionTime == 0 || transitionChromInfo.EndRetentionTime == 0) { return null; } return new RetentionTimeValues(transitionChromInfo.RetentionTime, transitionChromInfo.StartRetentionTime, transitionChromInfo.EndRetentionTime, transitionChromInfo.Fwhm); }
private float?GetValue(TransitionChromInfo chromInfo) { if (chromInfo == null) { return(null); } if (_ratioIndex == RATIO_INDEX_NONE) { return(chromInfo.Area); } return(chromInfo.GetRatio(_ratioIndex)); }
private TransitionChromInfo GetTransitionChromInfo(int chromIndex, int pepIndex, int transIndex) { TransitionChromInfo result = null; RunUI(() => { var nodePep = SkylineWindow.DocumentUI.Peptides.ElementAt(pepIndex); var nodeGroup = nodePep.TransitionGroups.First(); var transition = nodeGroup.Transitions.ElementAt(transIndex); result = transition.ChromInfos.ToArray()[chromIndex]; }); return(result); }
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); }
protected override double GetValue(TransitionChromInfo chromInfo) { var retentionTimeValues = ScaleRetentionTimeValues(chromInfo.FileId, RetentionTimeValues.GetValues(chromInfo)); if (!retentionTimeValues.HasValue) { return(0); } switch (RTValue) { case RTPeptideValue.Retention: return(retentionTimeValues.Value.RetentionTime); case RTPeptideValue.FWHM: return(retentionTimeValues.Value.Fwhm ?? 0); case RTPeptideValue.FWB: return(retentionTimeValues.Value.Fwb); } return(0); }
private void WriteTransitionChromInfo(XmlWriter writer, TransitionChromInfo chromInfo) { if (chromInfo.OptimizationStep != 0) { writer.WriteAttribute(ATTR.step, chromInfo.OptimizationStep); } // Only write peak information, if it is not empty if (!chromInfo.IsEmpty) { writer.WriteAttributeNullable(ATTR.mass_error_ppm, chromInfo.MassError); writer.WriteAttribute(ATTR.retention_time, chromInfo.RetentionTime); writer.WriteAttribute(ATTR.start_time, chromInfo.StartRetentionTime); writer.WriteAttribute(ATTR.end_time, chromInfo.EndRetentionTime); writer.WriteAttributeNullable(ATTR.ion_mobility, chromInfo.IonMobility.IonMobility.Mobility); writer.WriteAttributeNullable(ATTR.ion_mobility_window, chromInfo.IonMobility.IonMobilityExtractionWindowWidth); writer.WriteAttribute(ATTR.area, chromInfo.Area); writer.WriteAttribute(ATTR.background, chromInfo.BackgroundArea); writer.WriteAttribute(ATTR.height, chromInfo.Height); writer.WriteAttribute(ATTR.fwhm, chromInfo.Fwhm); writer.WriteAttribute(ATTR.fwhm_degenerate, chromInfo.IsFwhmDegenerate); writer.WriteAttributeNullable(ATTR.truncated, chromInfo.IsTruncated); writer.WriteAttribute(ATTR.identified, chromInfo.Identified.ToString().ToLowerInvariant()); writer.WriteAttribute(ATTR.rank, chromInfo.Rank); if (SkylineVersion.SrmDocumentVersion.CompareTo(DocumentFormat.VERSION_3_61) >= 0) { writer.WriteAttributeNullable(ATTR.points_across, chromInfo.PointsAcrossPeak); } if (chromInfo.Rank != chromInfo.RankByLevel) { writer.WriteAttribute(ATTR.rank_by_level, chromInfo.RankByLevel); } } writer.WriteAttribute(ATTR.user_set, chromInfo.UserSet); writer.WriteAttribute(ATTR.forced_integration, chromInfo.IsForcedIntegration, false); WriteAnnotations(writer, chromInfo.Annotations); }
protected override double GetValue(TransitionChromInfo chromInfo) { return(chromInfo.Area); }
protected override FindMatch MatchTransition(TransitionChromInfo transitionChromInfo) { return(transitionChromInfo.IsUserSetManual ? new FindMatch(Resources.ManuallyIntegratedPeakFinder_MatchTransition_Manually_integrated_peak) : null); }
protected override double GetValue(TransitionChromInfo chromInfo) { return(chromInfo.MassError ?? 0); }
public void AddChromInfo(TransitionGroupDocNode nodeGroup, TransitionDocNode nodeTran, TransitionChromInfo info) { if (info.IsEmpty) return; var key = new TransitionKey(nodeGroup, nodeTran.Key(nodeGroup), nodeGroup.TransitionGroup.LabelType); if (TranAreas.ContainsKey(key)) throw new InvalidDataException(String.Format(Resources.PeptideChromInfoCalculator_AddChromInfo_Duplicate_transition___0___found_for_peak_areas, nodeTran.Transition)); TranAreas.Add(key, info.Area); }
private static float GetPeakCountRatio(TransitionChromInfo chromInfo, bool integrateAll) { return(chromInfo.IsGoodPeak(integrateAll) ? 1 : 0); }
protected override FindMatch MatchTransition(TransitionChromInfo transitionChromInfo) { return transitionChromInfo.IsUserSetManual ? new FindMatch(Resources.ManuallyIntegratedPeakFinder_MatchTransition_Manually_integrated_peak) : null; }
protected abstract FindMatch MatchTransition(TransitionChromInfo transitionChromInfo);
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); } } }
protected abstract double GetValue(TransitionChromInfo info);
private static float GetPeakCountRatio(TransitionChromInfo chromInfo) { return(chromInfo.Area > 0 ? 1 : 0); }
private static void AddBestPeakTimes(TransitionChromInfo chromInfo, ref double bestStartTime, ref double bestEndTime) { // Make sure all parts of the best peak are included in the // best peak window double end = chromInfo.EndRetentionTime; if (end <= 0) return; double start = chromInfo.StartRetentionTime; bestStartTime = Math.Min(bestStartTime, start); bestEndTime = Math.Max(bestEndTime, end); }
protected override double GetValue(TransitionChromInfo chromInfo) { var retentionTimeValues = ScaleRetentionTimeValues(chromInfo.FileId, RetentionTimeValues.GetValues(chromInfo)); if (!retentionTimeValues.HasValue) { return 0; } switch (RTValue) { case RTPeptideValue.Retention: return retentionTimeValues.Value.RetentionTime; case RTPeptideValue.FWHM: return retentionTimeValues.Value.Fwhm ?? 0; case RTPeptideValue.FWB: return retentionTimeValues.Value.Fwb; } return 0; }
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); } } }
public static TransitionDocNode FromTransitionProto(AnnotationScrubber scrubber, SrmSettings settings, TransitionGroup group, ExplicitMods mods, IsotopeDistInfo isotopeDist, ExplicitTransitionValues pre422ExplicitTransitionValues, SkylineDocumentProto.Types.Transition transitionProto) { var stringPool = scrubber.StringPool; IonType ionType = DataValues.FromIonType(transitionProto.FragmentType); MeasuredIon measuredIon = null; if (transitionProto.MeasuredIonName != null) { measuredIon = settings.TransitionSettings.Filter.MeasuredIons.SingleOrDefault( i => i.Name.Equals(transitionProto.MeasuredIonName.Value)); if (measuredIon == null) { throw new InvalidDataException(string.Format(Resources.TransitionInfo_ReadXmlAttributes_The_reporter_ion__0__was_not_found_in_the_transition_filter_settings_, transitionProto.MeasuredIonName)); } ionType = IonType.custom; } bool isCustom = Transition.IsCustom(ionType, group); bool isPrecursor = Transition.IsPrecursor(ionType); CustomMolecule customIon = null; if (isCustom) { if (measuredIon != null) { customIon = measuredIon.SettingsCustomIon; } else if (isPrecursor) { customIon = group.CustomMolecule; } else { var formula = DataValues.FromOptional(transitionProto.Formula); var moleculeID = MoleculeAccessionNumbers.FromString(DataValues.FromOptional(transitionProto.MoleculeId)); // Tab separated list of InChiKey, CAS etc var monoMassH = DataValues.FromOptional(transitionProto.MonoMassH); var averageMassH = DataValues.FromOptional(transitionProto.AverageMassH); var monoMass = DataValues.FromOptional(transitionProto.MonoMass) ?? monoMassH; var averageMass = DataValues.FromOptional(transitionProto.AverageMass) ?? averageMassH; customIon = new CustomMolecule(formula, new TypedMass(monoMass.Value, monoMassH.HasValue ? MassType.MonoisotopicMassH : MassType.Monoisotopic), new TypedMass(averageMass.Value, averageMassH.HasValue ? MassType.AverageMassH : MassType.Average), DataValues.FromOptional(transitionProto.CustomIonName), moleculeID); } } Transition transition; var adductString = DataValues.FromOptional(transitionProto.Adduct); var adduct = string.IsNullOrEmpty(adductString) ? Adduct.FromChargeProtonated(transitionProto.Charge) : Adduct.FromStringAssumeChargeOnly(adductString); if (isCustom) { transition = new Transition(group, isPrecursor ? group.PrecursorAdduct :adduct, transitionProto.MassIndex, customIon, ionType); } else if (isPrecursor) { transition = new Transition(group, ionType, group.Peptide.Length - 1, transitionProto.MassIndex, group.PrecursorAdduct, DataValues.FromOptional(transitionProto.DecoyMassShift)); } else { int offset = Transition.OrdinalToOffset(ionType, transitionProto.FragmentOrdinal, group.Peptide.Length); transition = new Transition(group, ionType, offset, transitionProto.MassIndex, adduct, DataValues.FromOptional(transitionProto.DecoyMassShift)); } var losses = TransitionLosses.FromLossProtos(settings, transitionProto.Losses); var mass = settings.GetFragmentMass(group, mods, transition, isotopeDist); var isotopeDistInfo = GetIsotopeDistInfo(transition, losses, isotopeDist); if (group.DecoyMassShift.HasValue && transitionProto.DecoyMassShift == null) { throw new InvalidDataException(Resources.SrmDocument_ReadTransitionXml_All_transitions_of_decoy_precursors_must_have_a_decoy_mass_shift); } TransitionLibInfo libInfo = null; if (transitionProto.LibInfo != null) { libInfo = new TransitionLibInfo(transitionProto.LibInfo.Rank, transitionProto.LibInfo.Intensity); } var annotations = scrubber.ScrubAnnotations(Annotations.FromProtoAnnotations(transitionProto.Annotations), AnnotationDef.AnnotationTarget.transition); var results = TransitionChromInfo.FromProtoTransitionResults(scrubber, settings, transitionProto.Results); var explicitTransitionValues = pre422ExplicitTransitionValues ?? ExplicitTransitionValues.Create( DataValues.FromOptional(transitionProto.ExplicitCollisionEnergy), DataValues.FromOptional(transitionProto.ExplicitIonMobilityHighEnergyOffset), DataValues.FromOptional(transitionProto.ExplicitSLens), DataValues.FromOptional(transitionProto.ExplicitConeVoltage), DataValues.FromOptional(transitionProto.ExplicitDeclusteringPotential)); return(new TransitionDocNode(transition, annotations, losses, mass, new TransitionQuantInfo(isotopeDistInfo, libInfo, !transitionProto.NotQuantitative), explicitTransitionValues, results)); }
private static bool IntersectPeaks(ChromPeak peak, TransitionChromInfo chromInfo) { if (chromInfo == null) return false; // Allow start and end to share the same time, but nothing more. return Math.Min(chromInfo.EndRetentionTime, peak.EndTime) - Math.Max(chromInfo.StartRetentionTime, peak.StartTime) > 0; }
public FinderChromFileKey(TransitionChromInfo transitionChromInfo) { ChromFileInfoId = transitionChromInfo.FileId; OptStep = transitionChromInfo.OptimizationStep; }
public static double?GetArea(bool treatMissingAsZero, double?qValueCutoff, bool allowTruncated, TransitionGroupDocNode transitionGroup, TransitionDocNode transition, int replicateIndex, TransitionChromInfo chromInfo) { if (treatMissingAsZero && chromInfo.IsEmpty) { return(0); } if (chromInfo.IsEmpty) { return(null); } if (!allowTruncated && chromInfo.IsTruncated.GetValueOrDefault()) { return(null); } if (qValueCutoff.HasValue) { TransitionGroupChromInfo transitionGroupChromInfo = FindTransitionGroupChromInfo(transitionGroup, replicateIndex, chromInfo.FileId); if (transitionGroupChromInfo != null && transitionGroupChromInfo.QValue > qValueCutoff.Value) { return(treatMissingAsZero ? 0 : default(double?)); } } return(chromInfo.Area); }
protected override double GetValue(TransitionChromInfo chromInfo) { return chromInfo.Area; }
public void ChangeChromInfo(EditDescription editDescription, TransitionChromInfo newChromInfo) { var newDocNode = Transition.DocNode.ChangeResults(GetResultFile().ChangeChromInfo(Transition.DocNode.Results, newChromInfo)); Transition.ChangeDocNode(editDescription, newDocNode); }
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; } } }
private void DisplayOptimizationTotals(IRegressionFunction timeRegressionFunction, ChromatogramSet chromatograms, float mzMatchTolerance, ref double bestStartTime, ref double bestEndTime) { // Construct and add graph items for all relevant transition groups. float fontSize = FontSize; int lineWidth = LineWidth; int iColor = 0; // Get the one and only group var nodeGroup = _nodeGroups[0]; var chromGroupInfo = ChromGroupInfos[0]; ChromFileInfoId fileId = chromatograms.FindFile(chromGroupInfo); int numPeaks = chromGroupInfo.NumPeaks; // Collect the chromatogram info for the transition children // of this transition group. var listChromInfoSets = new List<ChromatogramInfo[]>(); var listTranisitionChromInfoSets = new List<TransitionChromInfo[]>(); int totalOptCount = chromatograms.OptimizationFunction.StepCount*2 + 1; foreach (TransitionDocNode nodeTran in nodeGroup.Children) { var infos = chromGroupInfo.GetAllTransitionInfo((float) nodeTran.Mz, mzMatchTolerance, chromatograms.OptimizationFunction); if (infos.Length == 0) continue; // Make sure the total number of chrom info entries match the expected // no matter what, so that chromatogram colors will match up with peak // area charts. if (infos.Length != totalOptCount) infos = ResizeArrayChromInfo(infos, totalOptCount); listChromInfoSets.Add(infos); var transitionChromInfos = new TransitionChromInfo[totalOptCount]; int steps = infos.Length/2; int offset = totalOptCount/2 - steps; for (int i = 0; i < infos.Length; i++) { transitionChromInfos[i + offset] = GetTransitionChromInfo(nodeTran, _chromIndex, fileId, i - steps); } listTranisitionChromInfoSets.Add(transitionChromInfos); } if (listChromInfoSets.Count == 0 || totalOptCount == 0) throw new InvalidDataException(Resources.GraphChromatogram_DisplayOptimizationTotals_No_optimization_data_available); // Enumerate optimization steps, grouping the data into graph data by step var listGraphData = new List<OptimizationGraphData>(); for (int i = 0; i < listChromInfoSets.Count; i++) { var chromInfos = listChromInfoSets[i]; var transitionChromInfos = listTranisitionChromInfoSets[i]; for (int j = 0; j < chromInfos.Length; j++) { if (listGraphData.Count <= j) listGraphData.Add(new OptimizationGraphData(numPeaks)); listGraphData[j].Add(chromInfos[j], transitionChromInfos[j]); } } // Total and transform the data, and compute which optimization // set has the most intense peak for each peak group. int bestPeakData = -1; TransitionChromInfo tranPeakInfo = null; float maxPeakHeight = float.MinValue; var maxPeakData = new int[numPeaks]; var maxPeakHeights = new float[numPeaks]; for (int i = 0; i < numPeaks; i++) maxPeakHeights[i] = float.MinValue; var transform = Transform; for (int i = 0; i < listGraphData.Count; i++) { var graphData = listGraphData[i]; var infoPrimary = graphData.InfoPrimary; if (infoPrimary == null) continue; // Sum intensities of all transitions in this // optimization bucket infoPrimary.SumIntensities(graphData.ChromInfos); // Apply any transform the user has chosen infoPrimary.Transform(transform); for (int j = 0; j < numPeaks; j++) { float height = graphData.PeakHeights[j]; if (height > maxPeakHeights[j]) { maxPeakHeights[j] = height; maxPeakData[j] = i; } } if (maxPeakHeight < graphData.TotalHeight) { maxPeakHeight = graphData.TotalHeight; bestPeakData = i; tranPeakInfo = graphData.TransitionInfoPrimary; } AddBestPeakTimes(graphData.TransitionInfoPrimary, ref bestStartTime, ref bestEndTime); } // Hide all peaks between the best peak extents if (tranPeakInfo != null) { for (int j = 0; j < numPeaks; j++) { if (maxPeakHeights[j] == 0) continue; var graphData = listGraphData[maxPeakData[j]]; if (graphData.InfoPrimary == null) continue; ChromPeak peak = graphData.InfoPrimary.GetPeak(j); if (peak.IsForcedIntegration) continue; if (IntersectPeaks(peak, tranPeakInfo)) maxPeakHeights[j] = 0; } } // Create graph items int totalSteps = totalOptCount/2; for (int i = 0; i < listGraphData.Count; i++) { var graphData = listGraphData[i]; if (graphData.InfoPrimary != null) { int step = i - totalSteps; int width = lineWidth; Color color; if (step == 0) { color = ChromGraphItem.ColorSelected; width++; } else if (nodeGroup.HasLibInfo) color = COLORS_LIBRARY[iColor % COLORS_LIBRARY.Length]; else color = COLORS_LIBRARY[iColor % COLORS_LIBRARY.Length]; // color = COLORS_HEURISTIC[iColor % COLORS_HEURISTIC.Length]; TransitionChromInfo tranPeakInfoGraph = null; if (bestPeakData == i) tranPeakInfoGraph = tranPeakInfo; var graphItem = new ChromGraphItem(nodeGroup, null, graphData.InfoPrimary, tranPeakInfoGraph, timeRegressionFunction, GetAnnotationFlags(i, maxPeakData, maxPeakHeights), null, 0, false, false, step, color, fontSize, width); _graphHelper.AddChromatogram(PaneKey.PRECURSORS, graphItem); } iColor++; } }
private TransitionChromInfoData(MeasuredResults measuredResults, int replicateIndex, ChromFileInfo chromFileInfo, TransitionChromInfo transitionChromInfo) : base(measuredResults, replicateIndex, chromFileInfo, transitionChromInfo) { }
/// <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 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)); } }