protected override GraphData CreateGraphData(SrmDocument document, PeptideGroupDocNode selectedProtein, TransitionGroupDocNode selectedGroup, DisplayTypeChrom displayType) { int? result = null; if (RTLinearRegressionGraphPane.ShowReplicate == ReplicateDisplay.single) result = GraphSummary.ResultsIndex; return new AreaGraphData(document, selectedGroup, selectedProtein, result, displayType, PaneKey); }
private List <PointPairList> GetPointPairLists(TransitionGroupDocNode nodeGroup, DisplayTypeChrom displayType) { var transitionGroupChromInfoDatas = TransitionGroupChromInfoData.GetTransitionGroupChromInfoDatas( _document.Settings.MeasuredResults, nodeGroup.Results); return(MakePointPairLists(displayType, transitionGroupChromInfoDatas, IsMissingValue, CreatePointPair)); }
public MassErrorGraphData(SrmDocument document, IdentityPath identityPath, DisplayTypeChrom displayType, ReplicateGroupOp replicateGroupOp, PaneKey paneKey) : base(document, identityPath, displayType, replicateGroupOp, paneKey) { }
protected override GraphData CreateGraphData(SrmDocument document, PeptideGroupDocNode selectedProtein, TransitionGroupDocNode selectedGroup, DisplayTypeChrom displayType) { int? result = null; if (RTLinearRegressionGraphPane.ShowReplicate == ReplicateDisplay.single) result = GraphSummary.ResultsIndex; return new RTGraphData(document, selectedGroup, selectedProtein, result, displayType, GraphSummary.StateProvider.GetRetentionTimeTransformOperation()); }
protected GraphData(SrmDocument document, DocNode docNode, DisplayTypeChrom displayType, GraphValues.ReplicateGroupOp replicateGroupOp, PaneKey paneKey) { _document = document; _docNode = docNode; _displayType = displayType; ReplicateGroupOp = replicateGroupOp; _paneKey = paneKey; }
protected GraphData(SrmDocument document, IEnumerable <IdentityPath> selectedDocNodePaths, DisplayTypeChrom displayType, ReplicateGroupOp replicateGroupOp, PaneKey paneKey) { _document = document; _selectedDocNodePaths = ImmutableList.ValueOf(selectedDocNodePaths); _displayType = displayType; ReplicateGroupOp = replicateGroupOp; _paneKey = paneKey; }
public AreaGraphData(SrmDocument document, TransitionGroupDocNode selectedGroup, PeptideGroupDocNode selectedProtein, int? result, DisplayTypeChrom displayType, PaneKey paneKey) : base(document, selectedGroup, selectedProtein, result, displayType, null, paneKey) { }
public AreaGraphData(SrmDocument document, TransitionGroupDocNode selectedGroup, PeptideGroupDocNode selectedProtein, int?result, DisplayTypeChrom displayType, PaneKey paneKey) : base(document, selectedGroup, selectedProtein, result, displayType, null, paneKey) { }
public RTGraphData(SrmDocument document, TransitionGroupDocNode selectedGroup, PeptideGroupDocNode selectedProtein, int?result, DisplayTypeChrom displayType, GraphValues.IRetentionTimeTransformOp retentionTimeTransformOp ) : base(document, selectedGroup, selectedProtein, result, displayType, retentionTimeTransformOp, PaneKey.DEFAULT) { }
private List <PointPairList> GetPointPairLists(TransitionGroupDocNode nodeGroup, TransitionDocNode nodeTran, DisplayTypeChrom displayType) { if (!IncludeTransition(nodeTran)) { return(new List <PointPairList>()); } var transitionChromInfoDatas = TransitionChromInfoData.GetTransitionChromInfoDatas( _document.Settings.MeasuredResults, nodeTran.Results); return(MakePointPairLists(displayType, transitionChromInfoDatas, IsMissingValue, CreatePointPair)); }
public AreaGraphData(SrmDocument document, DocNode docNode, DisplayTypeChrom displayType, GraphValues.ReplicateGroupOp replicateGroupOp, int ratioIndex, AreaNormalizeToData normalize, AreaExpectedValue expectedVisible, PaneKey paneKey) : base(document, docNode, displayType, replicateGroupOp, paneKey) { _docNode = docNode; _ratioIndex = ratioIndex; _normalize = normalize; _expectedVisible = expectedVisible; }
protected abstract GraphData CreateGraphData(SrmDocument document, PeptideGroupDocNode selectedProtein, TransitionGroupDocNode selectedGroup, DisplayTypeChrom displayType);
protected GraphData(SrmDocument document, TransitionGroupDocNode selectedGroup, PeptideGroupDocNode selectedProtein, int? iResult, DisplayTypeChrom displayType, GraphValues.IRetentionTimeTransformOp retentionTimeTransformOp, PaneKey paneKey) { RetentionTimeTransformOp = retentionTimeTransformOp; // Determine the shortest possible unique ID for each peptide or molecule var sequences = new List<Tuple<string, bool>>(); foreach (var nodePep in document.Molecules) sequences.Add(new Tuple<string, bool>(nodePep.RawTextId, nodePep.IsProteomic)); var uniquePrefixGenerator = new UniquePrefixGenerator(sequences, 3); int pointListCount = 0; var dictTypeToSet = new Dictionary<IsotopeLabelType, int>(); bool onePointPerPeptide = PeptideOrder == SummaryPeptideOrder.document && null != paneKey.IsotopeLabelType; // Figure out how many point lists to create bool displayTotals = (displayType == DisplayTypeChrom.total); if (displayTotals) { foreach (var nodeGroup in document.MoleculeTransitionGroups) { if (!paneKey.IncludesTransitionGroup(nodeGroup)) { continue; } IsotopeLabelType labelType = nodeGroup.TransitionGroup.LabelType; if (!dictTypeToSet.ContainsKey(labelType)) dictTypeToSet.Add(labelType, pointListCount++); } } else { foreach (var nodeGroup in document.MoleculeTransitionGroups) { if (!paneKey.IncludesTransitionGroup(nodeGroup)) { continue; } pointListCount = Math.Max(pointListCount, GraphChromatogram.GetDisplayTransitions(nodeGroup, displayType).Count()); } } // Build the list of points to show. var listPoints = new List<GraphPointData>(); foreach (PeptideGroupDocNode nodeGroupPep in document.MoleculeGroups) { if (AreaGraphController.AreaScope == AreaScope.protein) { if (!ReferenceEquals(nodeGroupPep, selectedProtein)) continue; } foreach (PeptideDocNode nodePep in nodeGroupPep.Children) { bool addBlankPoint = onePointPerPeptide && !nodePep.TransitionGroups.Any(paneKey.IncludesTransitionGroup); foreach (TransitionGroupDocNode nodeGroup in nodePep.Children) { var path = new IdentityPath(nodeGroupPep.PeptideGroup, nodePep.Peptide, nodeGroup.TransitionGroup); var graphPointData = new GraphPointData(nodePep, nodeGroup, path); if (addBlankPoint || paneKey.IncludesTransitionGroup(nodeGroup)) { listPoints.Add(graphPointData); } if (addBlankPoint) { break; } } } } // Sort into correct order var peptideOrder = PeptideOrder; if (peptideOrder == SummaryPeptideOrder.time) { if (displayTotals) listPoints.Sort(ComparePeptideTimes); else listPoints.Sort(CompareGroupTimes); } else if (peptideOrder == SummaryPeptideOrder.area) { listPoints.Sort(CompareGroupAreas); } // Init calculated values var pointPairLists = new List<PointPairList>(); var labels = new List<string>(); var xscalePaths = new List<IdentityPath>(); double maxY = 0; double minY = double.MaxValue; int selectedIndex = -1; for (int i = 0; i < pointListCount; i++) pointPairLists.Add(new PointPairList()); // Calculate lists and values PeptideDocNode nodePepCurrent = null; int chargeCount = 0, chargeCurrent = 0; foreach (var dataPoint in listPoints) { var nodePep = dataPoint.NodePep; var nodeGroup = dataPoint.NodeGroup; if (!ReferenceEquals(nodePep, nodePepCurrent)) { nodePepCurrent = nodePep; chargeCount = GetChargeCount(nodePep); chargeCurrent = 0; } bool addLabel = !displayTotals; if (displayTotals && nodeGroup.TransitionGroup.PrecursorCharge != chargeCurrent) { LevelPointPairLists(pointPairLists); addLabel = true; } chargeCurrent = nodeGroup.TransitionGroup.PrecursorCharge; var transitionGroup = nodeGroup.TransitionGroup; int iGroup = labels.Count; if (addLabel) { string label = uniquePrefixGenerator.GetUniquePrefix(nodePep.RawTextId, nodePep.IsProteomic) + (chargeCount > 1 ? Transition.GetChargeIndicator(transitionGroup.PrecursorCharge) : string.Empty); if (!displayTotals && null == paneKey.IsotopeLabelType) label += transitionGroup.LabelTypeText; if (peptideOrder == SummaryPeptideOrder.time) { label += string.Format(" ({0:F01})", displayTotals ? // Not L10N dataPoint.TimePepCharge : dataPoint.TimeGroup); } labels.Add(label); xscalePaths.Add(dataPoint.IdentityPath); } double groupMaxY = 0; double groupMinY = double.MaxValue; // ReSharper disable DoNotCallOverridableMethodsInConstructor int? resultIndex = iResult.HasValue && iResult >= 0 ? iResult : null; if (RTLinearRegressionGraphPane.ShowReplicate == ReplicateDisplay.best && nodePep != null) { resultIndex = null; int iBest = nodePep.BestResult; if (iBest !=-1) resultIndex = iBest; } if (displayTotals) { var labelType = nodeGroup.TransitionGroup.LabelType; if (dictTypeToSet.ContainsKey(labelType)) { if (paneKey.IncludesTransitionGroup(nodeGroup)) { pointPairLists[dictTypeToSet[labelType]].Add(CreatePointPair(iGroup, nodeGroup, ref groupMaxY, ref groupMinY, resultIndex)); } else { pointPairLists[dictTypeToSet[labelType]].Add(PointPairMissing(iGroup)); } } } else { if (paneKey.IncludesTransitionGroup(nodeGroup)) { var nodeTrans = GraphChromatogram.GetDisplayTransitions(nodeGroup, displayType).ToArray(); for (int i = 0; i < pointListCount; i++) { var pointPairList = pointPairLists[i]; pointPairList.Add(i >= nodeTrans.Length ? CreatePointPairMissing(iGroup) : CreatePointPair(iGroup, nodeTrans[i], ref groupMaxY, ref groupMinY, resultIndex)); } } else { for (int i = 0; i < pointListCount; i++) { pointPairLists[i].Add(CreatePointPairMissing(iGroup)); } } } // ReSharper restore DoNotCallOverridableMethodsInConstructor // Save the selected index and its y extent if (ReferenceEquals(selectedGroup, nodeGroup)) { selectedIndex = labels.Count - 1; SelectedMaxY = groupMaxY; SelectedMinY = groupMinY; } // If multiple groups in the selection, make sure y extent is max of them else if (selectedIndex == labels.Count - 1) { SelectedMaxY = Math.Max(groupMaxY, SelectedMaxY); SelectedMinY = Math.Min(groupMinY, SelectedMinY); } maxY = Math.Max(maxY, groupMaxY); minY = Math.Min(minY, groupMinY); } PointPairLists = pointPairLists; Labels = labels.ToArray(); XScalePaths = xscalePaths.ToArray(); SelectedIndex = selectedIndex; MaxY = maxY; if (minY != double.MaxValue) MinY = minY; }
public override void UpdateGraph(bool selectionChanged) { SrmDocument document = GraphSummary.DocumentUIContainer.DocumentUI; var results = document.Settings.MeasuredResults; bool resultsAvailable = results != null; Clear(); if (!resultsAvailable) { Title.Text = Resources.RTReplicateGraphPane_UpdateGraph_No_results_available; EmptyGraph(document); return; } var selectedTreeNode = GraphSummary.StateProvider.SelectedNode as SrmTreeNode ?? GraphSummary.StateProvider.SelectedNodes.OfType <SrmTreeNode>().FirstOrDefault(); if (selectedTreeNode == null || document.FindNode(selectedTreeNode.Path) == null) { EmptyGraph(document); return; } Title.Text = null; DisplayTypeChrom displayType = GraphChromatogram.GetDisplayType(document, selectedTreeNode); DocNode selectedNode = selectedTreeNode.Model; IdentityPath selectedPath = selectedTreeNode.Path; DocNode parentNode = selectedNode; IdentityPath parentPath = selectedTreeNode.Path; // If the selected tree node is a transition, then its siblings are displayed. if (selectedTreeNode is TransitionTreeNode) { if (displayType != DisplayTypeChrom.single) { SrmTreeNode parentTreeNode = selectedTreeNode.SrmParent; parentNode = parentTreeNode.Model; selectedPath = parentTreeNode.Path; } } // If the selected node is a peptide with one child, then show the children, // unless chromatogram display type is total else if (selectedTreeNode is PeptideTreeNode) { var children = ((DocNodeParent)selectedNode).Children; if (children.Count == 1 && displayType != DisplayTypeChrom.total) { selectedNode = parentNode = children[0]; selectedPath = new IdentityPath(parentPath, children[0].Id); } } else if (!(selectedTreeNode is PeptideGroupTreeNode) && !(selectedTreeNode is TransitionGroupTreeNode)) { Title.Text = Resources.RTReplicateGraphPane_UpdateGraph_Select_a_peptide_to_see_the_retention_time_graph; CanShowRTLegend = false; return; } // If a precursor is going to be displayed with display type single if (parentNode is TransitionGroupDocNode && displayType == DisplayTypeChrom.single) { // If no optimization data, then show all the transitions if (!results.Chromatograms.Contains(chrom => chrom.OptimizationFunction != null)) { displayType = DisplayTypeChrom.all; } } var rtTransformOp = GraphSummary.StateProvider.GetRetentionTimeTransformOperation(); var rtValue = RTPeptideGraphPane.RTValue; GraphValues.ReplicateGroupOp replicateGroupOp; if (rtValue == RTPeptideValue.All) { replicateGroupOp = GraphValues.ReplicateGroupOp.FromCurrentSettings(document.Settings, GraphValues.AggregateOp.MEAN); } else { replicateGroupOp = GraphValues.ReplicateGroupOp.FromCurrentSettings(document.Settings); } var retentionTimeValue = new GraphValues.RetentionTimeTransform(rtValue, rtTransformOp, replicateGroupOp.AggregateOp); YAxis.Title.Text = retentionTimeValue.GetAxisTitle(); var peptidePaths = GetSelectedPeptides().GetUniquePeptidePaths().ToList(); // if PeptideGroupTreeNode is selected but has only one child isMultiSelect should still be true IsMultiSelect = peptidePaths.Count > 1 || (peptidePaths.Count == 1 && GraphSummary.StateProvider.SelectedNodes.FirstOrDefault() is PeptideGroupTreeNode); GraphData graphData = new RTGraphData(document, IsMultiSelect ? peptidePaths : new[] { selectedPath }.AsEnumerable(), displayType, retentionTimeValue, replicateGroupOp); CanShowRTLegend = graphData.DocNodes.Count != 0; InitFromData(graphData); int selectedReplicateIndex = SelectedIndex; double minRetentionTime = double.MaxValue; double maxRetentionTime = -double.MaxValue; int iColor = 0, iCharge = -1; var charge = Adduct.EMPTY; int countLabelTypes = document.Settings.PeptideSettings.Modifications.CountLabelTypes; int colorOffset = 0; var transitionGroupDocNode = parentNode as TransitionGroupDocNode; if (transitionGroupDocNode != null && displayType == DisplayTypeChrom.products) { // If we are only displaying product ions, we want to use an offset in the colors array // so that we do not re-use colors that would be used for any precursor ions. colorOffset = GraphChromatogram.GetDisplayTransitions(transitionGroupDocNode, DisplayTypeChrom.precursors).Count(); } for (int i = 0; i < graphData.DocNodes.Count; i++) { var docNode = graphData.DocNodes[i]; var identityPath = graphData.DocNodePaths[i]; var pointPairLists = graphData.PointPairLists[i]; int numSteps = pointPairLists.Count / 2; for (int iStep = 0; iStep < pointPairLists.Count; iStep++) { int step = iStep - numSteps; var pointPairList = pointPairLists[iStep]; Color color; var isSelected = false; var nodeGroup = docNode as TransitionGroupDocNode; if (IsMultiSelect) { var peptides = peptidePaths.Select(path => document.FindNode(path)) .Cast <PeptideDocNode>().ToArray(); var peptideDocNode = peptides.FirstOrDefault( peptide => 0 <= peptide.FindNodeIndex(docNode.Id)); if (peptideDocNode == null) { continue; } color = GraphSummary.StateProvider.GetPeptideGraphInfo(peptideDocNode).Color; if (identityPath.Equals(selectedTreeNode.Path) && step == 0) { color = ChromGraphItem.ColorSelected; isSelected = true; } } else if (parentNode is PeptideDocNode) { // Resharper code inspection v9.0 on TC gets this one wrong // ReSharper disable ExpressionIsAlwaysNull int iColorGroup = GetColorIndex(nodeGroup, countLabelTypes, ref charge, ref iCharge); // ReSharper restore ExpressionIsAlwaysNull color = COLORS_GROUPS[iColorGroup % COLORS_GROUPS.Count]; } else if (displayType == DisplayTypeChrom.total) { color = COLORS_GROUPS[iColor % COLORS_GROUPS.Count]; } else if (ReferenceEquals(docNode, selectedNode) && step == 0) { color = ChromGraphItem.ColorSelected; isSelected = true; } else { color = COLORS_TRANSITION[(iColor + colorOffset) % COLORS_TRANSITION.Count]; } iColor++; string label = graphData.DocNodeLabels[i]; if (step != 0) { label = string.Format(Resources.RTReplicateGraphPane_UpdateGraph_Step__0__, step); } CurveItem curveItem; if (IsMultiSelect) { if (rtValue != RTPeptideValue.All) { curveItem = CreateLineItem(label, pointPairList, color); } else { curveItem = CreateMultiSelectBarItem(label, pointPairList, color); } } else if (HiLowMiddleErrorBarItem.IsHiLoMiddleErrorList(pointPairList)) { curveItem = new HiLowMiddleErrorBarItem(label, pointPairList, color, Color.Black); BarSettings.Type = BarType.Cluster; } else if (rtValue == RTPeptideValue.All) { curveItem = new MeanErrorBarItem(label, pointPairList, color, Color.Black); BarSettings.Type = BarType.Cluster; } else { curveItem = CreateLineItem(label, pointPairList, color); } if (curveItem != null) { curveItem.Tag = identityPath; var barItem = curveItem as BarItem; if (barItem != null) { barItem.Bar.Border.IsVisible = false; barItem.Bar.Fill.Brush = GetBrushForNode(docNode, color); if (!isSelected) { barItem.SortedOverlayPriority = 1; } } CurveList.Add(curveItem); if (selectedReplicateIndex != -1 && selectedReplicateIndex < pointPairList.Count) { PointPair pointPair = pointPairList[selectedReplicateIndex]; if (!pointPair.IsInvalid) { minRetentionTime = Math.Min(minRetentionTime, pointPair.Z); maxRetentionTime = Math.Max(maxRetentionTime, pointPair.Y); } } } } } // Draw a box around the currently selected replicate if (ShowSelection && minRetentionTime != double.MaxValue) { AddSelection(selectedReplicateIndex, maxRetentionTime, minRetentionTime); } // Reset the scale when the parent node changes if (_parentNode == null || !ReferenceEquals(_parentNode.Id, parentNode.Id)) { XAxis.Scale.MaxAuto = XAxis.Scale.MinAuto = true; YAxis.Scale.MaxAuto = YAxis.Scale.MinAuto = true; } _parentNode = parentNode; Legend.IsVisible = !IsMultiSelect && Settings.Default.ShowRetentionTimesLegend; GraphSummary.GraphControl.Invalidate(); AxisChange(); }
public RTGraphData(SrmDocument document, IEnumerable <IdentityPath> selectedDocNodePaths, DisplayTypeChrom displayType, GraphValues.RetentionTimeTransform retentionTimeTransform, GraphValues.ReplicateGroupOp replicateGroupOp) : base(document, selectedDocNodePaths, displayType, replicateGroupOp, PaneKey.DEFAULT) { RetentionTimeTransform = retentionTimeTransform; }
public RTGraphData(SrmDocument document, DocNode docNode, DisplayTypeChrom displayType, GraphValues.RetentionTimeTransform retentionTimeTransform, GraphValues.ReplicateGroupOp replicateGroupOp) : base(document, docNode, displayType, replicateGroupOp, PaneKey.DEFAULT) { RetentionTimeTransform = retentionTimeTransform; }
public override void UpdateGraph(bool checkData) { SrmDocument document = GraphSummary.DocumentUIContainer.DocumentUI; var results = document.Settings.MeasuredResults; bool resultsAvailable = results != null; Clear(); if (!resultsAvailable) { Title.Text = Resources.RTReplicateGraphPane_UpdateGraph_No_results_available; EmptyGraph(document); return; } var selectedTreeNode = GraphSummary.StateProvider.SelectedNode as SrmTreeNode; if (selectedTreeNode == null || document.FindNode(selectedTreeNode.Path) == null) { EmptyGraph(document); return; } Title.Text = null; DisplayTypeChrom displayType = GraphChromatogram.GetDisplayType(document, selectedTreeNode); DocNode selectedNode = selectedTreeNode.Model; DocNode parentNode = selectedNode; IdentityPath identityPath = selectedTreeNode.Path; // If the selected tree node is a transition, then its siblings are displayed. if (selectedTreeNode is TransitionTreeNode) { if (displayType != DisplayTypeChrom.single) { SrmTreeNode parentTreeNode = selectedTreeNode.SrmParent; parentNode = parentTreeNode.Model; identityPath = parentTreeNode.Path; } } // If the selected node is a peptide with one child, then show the children, // unless chromatogram display type is total else if (selectedTreeNode is PeptideTreeNode) { var children = ((DocNodeParent)selectedNode).Children; if (children.Count == 1 && displayType != DisplayTypeChrom.total) { selectedNode = parentNode = children[0]; identityPath = new IdentityPath(identityPath, parentNode.Id); } } else if (!(selectedTreeNode is TransitionGroupTreeNode)) { Title.Text = Resources.RTReplicateGraphPane_UpdateGraph_Select_a_peptide_to_see_the_retention_time_graph; CanShowRTLegend = false; return; } // If a precursor is going to be displayed with display type single if (parentNode is TransitionGroupDocNode && displayType == DisplayTypeChrom.single) { // If no optimization data, then show all the transitions if (!results.Chromatograms.Contains(chrom => chrom.OptimizationFunction != null)) { displayType = DisplayTypeChrom.all; } } var rtTransformOp = GraphSummary.StateProvider.GetRetentionTimeTransformOperation(); var rtValue = RTPeptideGraphPane.RTValue; GraphValues.ReplicateGroupOp replicateGroupOp; if (rtValue == RTPeptideValue.All) { replicateGroupOp = GraphValues.ReplicateGroupOp.FromCurrentSettings(document.Settings, GraphValues.AggregateOp.MEAN); } else { replicateGroupOp = GraphValues.ReplicateGroupOp.FromCurrentSettings(document.Settings); } var retentionTimeValue = new GraphValues.RetentionTimeTransform(rtValue, rtTransformOp, replicateGroupOp.AggregateOp); YAxis.Title.Text = retentionTimeValue.GetAxisTitle(); GraphData graphData = new RTGraphData(document, parentNode, displayType, retentionTimeValue, replicateGroupOp); CanShowRTLegend = graphData.DocNodes.Count != 0; InitFromData(graphData); int selectedReplicateIndex = SelectedIndex; double minRetentionTime = double.MaxValue; double maxRetentionTime = -double.MaxValue; int iColor = 0, iCharge = -1; int? charge = null; int countLabelTypes = document.Settings.PeptideSettings.Modifications.CountLabelTypes; int colorOffset = 0; var transitionGroupDocNode = parentNode as TransitionGroupDocNode; if (transitionGroupDocNode != null && displayType == DisplayTypeChrom.products) { // If we are only displaying product ions, we want to use an offset in the colors array // so that we do not re-use colors that would be used for any precursor ions. colorOffset = GraphChromatogram.GetDisplayTransitions(transitionGroupDocNode, DisplayTypeChrom.precursors).Count(); } for (int i = 0; i < graphData.DocNodes.Count; i++) { var docNode = graphData.DocNodes[i]; var pointPairLists = graphData.PointPairLists[i]; int numSteps = pointPairLists.Count / 2; for (int iStep = 0; iStep < pointPairLists.Count; iStep++) { int step = iStep - numSteps; var pointPairList = pointPairLists[iStep]; Color color; var nodeGroup = docNode as TransitionGroupDocNode; if (parentNode is PeptideDocNode) { // Resharper code inspection v9.0 on TC gets this one wrong // ReSharper disable ExpressionIsAlwaysNull int iColorGroup = GetColorIndex(nodeGroup, countLabelTypes, ref charge, ref iCharge); // ReSharper restore ExpressionIsAlwaysNull color = COLORS_GROUPS[iColorGroup % COLORS_GROUPS.Length]; } else if (displayType == DisplayTypeChrom.total) { color = COLORS_GROUPS[iColor % COLORS_GROUPS.Length]; } else if (docNode.Equals(selectedNode) && step == 0) { color = ChromGraphItem.ColorSelected; } else { color = COLORS_TRANSITION[(iColor + colorOffset) % COLORS_TRANSITION.Length]; } iColor++; string label = graphData.DocNodeLabels[i]; if (step != 0) { label = string.Format(Resources.RTReplicateGraphPane_UpdateGraph_Step__0__, step); } BarItem curveItem; if (HiLowMiddleErrorBarItem.IsHiLoMiddleErrorList(pointPairList)) { curveItem = new HiLowMiddleErrorBarItem(label, pointPairList, color, Color.Black); } else { curveItem = new MeanErrorBarItem(label, pointPairList, color, Color.Black); } if (selectedReplicateIndex != -1 && selectedReplicateIndex < pointPairList.Count) { PointPair pointPair = pointPairList[selectedReplicateIndex]; if (!pointPair.IsInvalid) { minRetentionTime = Math.Min(minRetentionTime, pointPair.Z); maxRetentionTime = Math.Max(maxRetentionTime, pointPair.Y); } } curveItem.Bar.Border.IsVisible = false; curveItem.Bar.Fill.Brush = new SolidBrush(color); curveItem.Tag = new IdentityPath(identityPath, docNode.Id); CurveList.Add(curveItem); } } // Draw a box around the currently selected replicate if (ShowSelection && minRetentionTime != double.MaxValue) { GraphObjList.Add(new BoxObj(selectedReplicateIndex + .5, maxRetentionTime, 1, maxRetentionTime - minRetentionTime, Color.Black, Color.Empty) { IsClippedToChartRect = true, }); } // Reset the scale when the parent node changes if (_parentNode == null || !ReferenceEquals(_parentNode.Id, parentNode.Id)) { XAxis.Scale.MaxAuto = XAxis.Scale.MinAuto = true; YAxis.Scale.MaxAuto = YAxis.Scale.MinAuto = true; } _parentNode = parentNode; Legend.IsVisible = Settings.Default.ShowRetentionTimesLegend; AxisChange(); }
private static bool DisplayTypeMatches(LibraryChromGroup.ChromData chromData, DisplayTypeChrom displayType) { switch (displayType) { case DisplayTypeChrom.products: return(chromData.IonType != IonType.precursor); case DisplayTypeChrom.precursors: return(chromData.IonType == IonType.precursor); default: return(true); } }
// ReSharper disable PossibleMultipleEnumeration protected GraphData(SrmDocument document, TransitionGroupDocNode selectedGroup, PeptideGroupDocNode selectedProtein, int?iResult, DisplayTypeChrom displayType, GraphValues.IRetentionTimeTransformOp retentionTimeTransformOp, PaneKey paneKey) { RetentionTimeTransformOp = retentionTimeTransformOp; // Determine the shortest possible unique ID for each peptide or molecule var sequences = new List <Tuple <string, bool> >(); foreach (var nodePep in document.Molecules) { sequences.Add(new Tuple <string, bool>(nodePep.ModifiedTarget.DisplayName, nodePep.IsProteomic)); } var uniquePrefixGenerator = new UniquePrefixGenerator(sequences, 3); int pointListCount = 0; var dictTypeToSet = new Dictionary <IsotopeLabelType, int>(); bool onePointPerPeptide = PeptideOrder == SummaryPeptideOrder.document && null != paneKey.IsotopeLabelType; // Figure out how many point lists to create bool displayTotals = (displayType == DisplayTypeChrom.total); if (displayTotals) { foreach (var nodeGroup in document.MoleculeTransitionGroups) { if (!paneKey.IncludesTransitionGroup(nodeGroup)) { continue; } IsotopeLabelType labelType = nodeGroup.TransitionGroup.LabelType; if (!dictTypeToSet.ContainsKey(labelType)) { dictTypeToSet.Add(labelType, pointListCount++); } } } else { foreach (var nodeGroup in document.MoleculeTransitionGroups) { if (!paneKey.IncludesTransitionGroup(nodeGroup)) { continue; } pointListCount = Math.Max(pointListCount, GraphChromatogram.GetDisplayTransitions(nodeGroup, displayType).Count()); } } // Build the list of points to show. var listPoints = new List <GraphPointData>(); foreach (PeptideGroupDocNode nodeGroupPep in document.MoleculeGroups) { if (AreaGraphController.AreaScope == AreaScope.protein) { if (!ReferenceEquals(nodeGroupPep, selectedProtein)) { continue; } } foreach (PeptideDocNode nodePep in nodeGroupPep.Children) { bool addBlankPoint = onePointPerPeptide && !nodePep.TransitionGroups.Any(paneKey.IncludesTransitionGroup); foreach (TransitionGroupDocNode nodeGroup in nodePep.Children) { var path = new IdentityPath(nodeGroupPep.PeptideGroup, nodePep.Peptide, nodeGroup.TransitionGroup); var graphPointData = new GraphPointData(nodePep, nodeGroup, path); if (addBlankPoint || paneKey.IncludesTransitionGroup(nodeGroup)) { listPoints.Add(graphPointData); } if (addBlankPoint) { break; } } } } // Sort into correct order var peptideOrder = PeptideOrder; if (peptideOrder == SummaryPeptideOrder.time) { if (displayTotals) { listPoints.Sort(ComparePeptideTimes); } else { listPoints.Sort(CompareGroupTimes); } } else if (peptideOrder == SummaryPeptideOrder.area) { listPoints.Sort(CompareGroupAreas); } else if (peptideOrder == SummaryPeptideOrder.mass_error) { listPoints.Sort(CompareGroupMassErrors); } // Init calculated values var pointPairLists = new List <PointPairList>(); var labels = new List <string>(); var xscalePaths = new List <IdentityPath>(); double maxY = 0; double minY = double.MaxValue; int selectedIndex = -1; for (int i = 0; i < pointListCount; i++) { pointPairLists.Add(new PointPairList()); } // Calculate lists and values PeptideDocNode nodePepCurrent = null; int chargeCount = 0; var chargeCurrent = Adduct.EMPTY; foreach (var dataPoint in listPoints) { var nodePep = dataPoint.NodePep; var nodeGroup = dataPoint.NodeGroup; if (!ReferenceEquals(nodePep, nodePepCurrent)) { nodePepCurrent = nodePep; chargeCount = GetChargeCount(nodePep); chargeCurrent = Adduct.EMPTY; } bool addLabel = !displayTotals; if (displayTotals && !Equals(nodeGroup.TransitionGroup.PrecursorAdduct, chargeCurrent)) { LevelPointPairLists(pointPairLists); addLabel = true; } chargeCurrent = nodeGroup.TransitionGroup.PrecursorAdduct; var transitionGroup = nodeGroup.TransitionGroup; int iGroup = labels.Count; if (addLabel) { string label = uniquePrefixGenerator.GetUniquePrefix(nodePep.ModifiedTarget.DisplayName, nodePep.IsProteomic) + (chargeCount > 1 ? Transition.GetChargeIndicator(transitionGroup.PrecursorAdduct) : string.Empty); if (!displayTotals && null == paneKey.IsotopeLabelType) { label += transitionGroup.LabelTypeText; } if (peptideOrder == SummaryPeptideOrder.time) { label += string.Format(@" ({0:F01})", displayTotals ? dataPoint.TimePepCharge : dataPoint.TimeGroup); } labels.Add(label); xscalePaths.Add(dataPoint.IdentityPath); } double groupMaxY = 0; double groupMinY = double.MaxValue; // ReSharper disable DoNotCallOverridableMethodsInConstructor int?resultIndex = iResult.HasValue && iResult >= 0 ? iResult : null; if (RTLinearRegressionGraphPane.ShowReplicate == ReplicateDisplay.best && nodePep != null) { resultIndex = null; int iBest = nodePep.BestResult; if (iBest != -1) { resultIndex = iBest; } } if (displayTotals) { var labelType = nodeGroup.TransitionGroup.LabelType; if (dictTypeToSet.ContainsKey(labelType)) { if (paneKey.IncludesTransitionGroup(nodeGroup)) { pointPairLists[dictTypeToSet[labelType]].Add(CreatePointPair(iGroup, nodeGroup, ref groupMaxY, ref groupMinY, resultIndex)); } else { pointPairLists[dictTypeToSet[labelType]].Add(PointPairMissing(iGroup)); } } } else { if (paneKey.IncludesTransitionGroup(nodeGroup)) { var nodeTrans = GraphChromatogram.GetDisplayTransitions(nodeGroup, displayType).ToArray(); for (int i = 0; i < pointListCount; i++) { var pointPairList = pointPairLists[i]; pointPairList.Add(i >= nodeTrans.Length ? CreatePointPairMissing(iGroup) : CreatePointPair(iGroup, nodeTrans[i], ref groupMaxY, ref groupMinY, resultIndex)); } } else { for (int i = 0; i < pointListCount; i++) { pointPairLists[i].Add(CreatePointPairMissing(iGroup)); } } } // ReSharper restore DoNotCallOverridableMethodsInConstructor // Save the selected index and its y extent if (ReferenceEquals(selectedGroup, nodeGroup)) { selectedIndex = labels.Count - 1; SelectedMaxY = groupMaxY; SelectedMinY = groupMinY; } // If multiple groups in the selection, make sure y extent is max of them else if (selectedIndex == labels.Count - 1) { SelectedMaxY = Math.Max(groupMaxY, SelectedMaxY); SelectedMinY = Math.Min(groupMinY, SelectedMinY); } maxY = Math.Max(maxY, groupMaxY); minY = Math.Min(minY, groupMinY); } PointPairLists = pointPairLists; Labels = labels.ToArray(); XScalePaths = xscalePaths.ToArray(); SelectedIndex = selectedIndex; MaxY = maxY; if (minY != double.MaxValue) { MinY = minY; } }
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)); } }
protected override GraphData CreateGraphData(SrmDocument document, PeptideGroupDocNode selectedProtein, TransitionGroupDocNode selectedGroup, DisplayTypeChrom displayType) { int?result = null; if (RTLinearRegressionGraphPane.ShowReplicate == ReplicateDisplay.single) { result = GraphSummary.ResultsIndex; } return(new AreaGraphData(document, selectedGroup, selectedProtein, result, displayType, PaneKey)); }
public static IEnumerable<TransitionDocNode> GetDisplayTransitions(TransitionGroupDocNode nodeGroup, DisplayTypeChrom displayType) { switch (displayType) { case DisplayTypeChrom.precursors: // Return transitions that would be filtered from MS1 return nodeGroup.GetMsTransitions(true); case DisplayTypeChrom.products: // Return transitions that would not be filtered in MS1 return nodeGroup.GetMsMsTransitions(true); default: return nodeGroup.Transitions; } }
public void SetDisplayTypeChrom(DisplayTypeChrom displayType) { Settings.Default.ShowTransitionGraphs = displayType.ToString(); UpdateChromGraphs(); UpdateSpectrumGraph(false); UpdateRetentionTimeGraph(); UpdatePeakAreaGraph(); }
protected GraphData(SrmDocument document, IdentityPath identityPath, DisplayTypeChrom displayType, ReplicateGroupOp replicateGroupOp, PaneKey paneKey) : this(document, new[] { identityPath }, displayType, replicateGroupOp, paneKey) { }
protected override GraphData CreateGraphData(SrmDocument document, PeptideGroupDocNode selectedProtein, TransitionGroupDocNode selectedGroup, DisplayTypeChrom displayType) { int?result = null; if (RTLinearRegressionGraphPane.ShowReplicate == ReplicateDisplay.single) { result = GraphSummary.ResultsIndex; } return(new RTGraphData(document, selectedGroup, selectedProtein, result, displayType, GraphSummary.StateProvider.GetRetentionTimeTransformOperation())); }
private List <PointPairList> MakePointPairLists <TChromInfoData>( DisplayTypeChrom displayType, IList <ICollection <TChromInfoData> > chromInfoResults, Func <TChromInfoData, bool> isMissingValue, Func <int, ICollection <TChromInfoData>, PointPair> createPointPair) where TChromInfoData : ChromInfoData { var pointPairLists = new List <PointPairList>(); if (null == chromInfoResults) { pointPairLists.Add(new PointPairList()); return(pointPairLists); } int maxSteps = 1; bool allowSteps = (displayType == DisplayTypeChrom.single); if (allowSteps) { foreach (var result in chromInfoResults) { maxSteps = Math.Max(maxSteps, GetCountSteps(result)); } } for (int i = 0; i < maxSteps; i++) { pointPairLists.Add(new PointPairList()); } int numSteps = maxSteps / 2; IList <ReplicateGroup> replicateGroups = _replicateGroups; for (int iGroup = 0; iGroup < replicateGroups.Count; iGroup++) { // Fill everything with missing data until filled for real foreach (PointPairList pairList in pointPairLists) { pairList.Add(PointPairMissing(iGroup)); } var replicateGroup = replicateGroups[iGroup]; var chromInfoLists = new List <ICollection <TChromInfoData> >(); foreach (var replicateIndex in replicateGroup.ReplicateIndexes) { if (replicateIndex < 0 || replicateIndex >= chromInfoResults.Count) { continue; } chromInfoLists.Add(chromInfoResults[replicateIndex]); } if (0 == chromInfoLists.Count) { continue; } var optimizationSteps = chromInfoLists .SelectMany(chromInfoList => from chromInfoData in chromInfoList where chromInfoData.ChromInfo != null select chromInfoData.OptimizationStep) .Distinct() .ToArray(); foreach (int step in optimizationSteps) { int iStep = step + numSteps; if (0 > iStep || iStep >= pointPairLists.Count) { continue; } var chromInfoDatasForStep = new List <TChromInfoData>(); foreach (var chromInfoDatas in chromInfoLists) { var chromInfosForStep = new List <TChromInfoData>(); if (replicateGroup.FileInfo != null) { var info = chromInfoDatas.FirstOrDefault(chromInfoData => chromInfoData != null && chromInfoData.ChromFileInfo.Equals(replicateGroup.FileInfo) && step == chromInfoData.OptimizationStep); chromInfosForStep.Add(info); } else { var step1 = step; var chromInfos = chromInfoDatas.Where( chromInfoData => chromInfoData != null && step1 == chromInfoData.OptimizationStep); chromInfosForStep.AddRange(chromInfos); } chromInfoDatasForStep.AddRange(chromInfosForStep.Where(c => c != null && !isMissingValue(c))); } var pointPairList = pointPairLists[iStep]; pointPairList[pointPairList.Count - 1] = createPointPair(iGroup, chromInfoDatasForStep); } } return(pointPairLists); }
public RTGraphData(SrmDocument document, TransitionGroupDocNode selectedGroup, PeptideGroupDocNode selectedProtein, int? result, DisplayTypeChrom displayType, GraphValues.IRetentionTimeTransformOp retentionTimeTransformOp ) : base(document, selectedGroup, selectedProtein, result, displayType, retentionTimeTransformOp, PaneKey.DEFAULT) { }