Exemplo n.º 1
0
        public CurveItem AddChromatogram(PaneKey paneKey, ChromGraphItem chromGraphItem)
        {
            var chromDisplayState = (ChromDisplayState)_displayState;

            chromDisplayState.ChromGraphItems.Add(new KeyValuePair <PaneKey, ChromGraphItem>(paneKey, chromGraphItem));
            return(GraphControl.AddGraphItem(chromDisplayState.GetOrCreateGraphPane(GraphControl, paneKey), chromGraphItem, false));
        }
Exemplo n.º 2
0
            public MSGraphPane GetOrCreateGraphPane(MSGraphControl graphControl, PaneKey graphPaneKey)
            {
                var pane = GetGraphPane(graphControl, graphPaneKey);

                if (null != pane)
                {
                    return(pane);
                }
                if (GraphPaneKeys.Count == 0)
                {
                    GraphPaneKeys.Add(graphPaneKey);
                    pane = graphControl.GraphPane;
                    ApplySettingsToGraphPane(pane);
                    return(pane);
                }
                int index     = GraphPaneKeys.BinarySearch(graphPaneKey);
                int iInsert   = ~index;
                var graphPane = InsertMsGraphPane(graphControl, iInsert);

                GraphPaneKeys.Insert(iInsert, graphPaneKey);
                using (var graphics = graphControl.CreateGraphics())
                {
                    graphControl.MasterPane.SetLayout(graphics, PaneLayout.SingleColumn);
                }
                return(graphPane);
            }
Exemplo n.º 3
0
 public MassErrorGraphData(SrmDocument document,
                           IdentityPath identityPath,
                           DisplayTypeChrom displayType,
                           ReplicateGroupOp replicateGroupOp,
                           PaneKey paneKey)
     : base(document, identityPath, displayType, replicateGroupOp, paneKey)
 {
 }
 protected GraphData(SrmDocument document, DocNode docNode, DisplayTypeChrom displayType, GraphValues.ReplicateGroupOp replicateGroupOp, PaneKey paneKey)
 {
     _document        = document;
     _docNode         = docNode;
     _displayType     = displayType;
     ReplicateGroupOp = replicateGroupOp;
     _paneKey         = paneKey;
 }
Exemplo n.º 5
0
 public AreaGraphData(SrmDocument document,
                      TransitionGroupDocNode selectedGroup,
                      PeptideGroupDocNode selectedProtein,
                      int?result,
                      DisplayTypeChrom displayType,
                      PaneKey paneKey)
     : base(document, selectedGroup, selectedProtein, result, displayType, null, paneKey)
 {
 }
Exemplo n.º 6
0
 public AreaGraphData(SrmDocument document,
     TransitionGroupDocNode selectedGroup,
     PeptideGroupDocNode selectedProtein,
     int? result,
     DisplayTypeChrom displayType,
     PaneKey paneKey)
     : base(document, selectedGroup, selectedProtein, result, displayType, null, paneKey)
 {
 }
Exemplo n.º 7
0
 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 static void ClickChromatogram(double x, double y, PaneKey? paneKey = null)
 {
     var graphChromatogram = SkylineWindow.GraphChromatograms.First();
     RunUI(() =>
     {
         graphChromatogram.TestMouseMove(x, y, paneKey);
         graphChromatogram.TestMouseDown(x, y, paneKey);
     });
     WaitForGraphs();
     CheckFullScanSelection(x, y, paneKey);
 }
 protected SummaryPeptideGraphPane(GraphSummary graphSummary, PaneKey paneKey)
     : base(graphSummary)
 {
     PaneKey = paneKey;
     string xAxisTitle = Resources.SummaryPeptideGraphPane_SummaryPeptideGraphPane_Peptide;
     if (null != paneKey.IsotopeLabelType && !paneKey.IsotopeLabelType.IsLight)
     {
         xAxisTitle += " (" + paneKey.IsotopeLabelType + ")"; // Not L10N
     }
     XAxis.Title.Text = xAxisTitle;
     XAxis.Type = AxisType.Text;
 }
Exemplo n.º 10
0
        protected SummaryPeptideGraphPane(GraphSummary graphSummary, PaneKey paneKey)
            : base(graphSummary)
        {
            PaneKey = paneKey;
            string xAxisTitle = Resources.SummaryPeptideGraphPane_SummaryPeptideGraphPane_Peptide;

            if (null != paneKey.IsotopeLabelType && !paneKey.IsotopeLabelType.IsLight)
            {
                xAxisTitle += @" (" + paneKey.IsotopeLabelType + @")";
            }
            XAxis.Title.Text = xAxisTitle;
            XAxis.Type       = AxisType.Text;
        }
Exemplo n.º 11
0
            public MSGraphPane GetGraphPane(MSGraphControl graphControl, PaneKey graphPaneKey)
            {
                if (!AllowSplitPanes)
                {
                    return(graphControl.GraphPane);
                }
                int index = GraphPaneKeys.BinarySearch(graphPaneKey);

                if (index >= 0)
                {
                    return((MSGraphPane)graphControl.MasterPane.PaneList[index]);
                }
                return(null);
            }
Exemplo n.º 12
0
        protected SummaryPeptideGraphPane(GraphSummary graphSummary, PaneKey paneKey)
            : base(graphSummary)
        {
            PaneKey = paneKey;
            string xAxisTitle =
                Helpers.PeptideToMoleculeTextMapper.Translate(Resources.SummaryPeptideGraphPane_SummaryPeptideGraphPane_Peptide,
                                                              graphSummary.DocumentUIContainer.DocumentUI.DocumentType);

            if (null != paneKey.IsotopeLabelType && !paneKey.IsotopeLabelType.IsLight)
            {
                xAxisTitle += @" (" + paneKey.IsotopeLabelType + @")";
            }
            XAxis.Title.Text = xAxisTitle;
            XAxis.Type       = AxisType.Text;
        }
Exemplo n.º 13
0
 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;
 }
Exemplo n.º 14
0
 public MSGraphPane GetGraphPane(PaneKey paneKey)
 {
     return(_displayState.GetGraphPane(GraphControl, paneKey));
 }
Exemplo n.º 15
0
 public static void CheckFullScanSelection(double x, double y, PaneKey? paneKey = null)
 {
     var graphChromatogram = SkylineWindow.GraphChromatograms.First();
     WaitForConditionUI(() => SkylineWindow.GraphFullScan != null && SkylineWindow.GraphFullScan.IsLoaded);
     Assert.IsTrue(graphChromatogram.TestFullScanSelection(x, y, paneKey));
 }
Exemplo n.º 16
0
 public AreaReplicateGraphPane(GraphSummary graphSummary, PaneKey paneKey)
     : base(graphSummary)
 {
     PaneKey = paneKey;
 }
Exemplo n.º 17
0
            // 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;
                }
            }
Exemplo n.º 18
0
 public AreaPeptideGraphPane(GraphSummary graphSummary, PaneKey paneKey)
     : base(graphSummary, paneKey)
 {
 }
Exemplo n.º 19
0
 public AreaReplicateGraphPane(GraphSummary graphSummary, PaneKey paneKey)
     : base(graphSummary)
 {
     PaneKey = paneKey;
 }
Exemplo n.º 20
0
 protected GraphData(SrmDocument document, IdentityPath identityPath, DisplayTypeChrom displayType, ReplicateGroupOp replicateGroupOp, PaneKey paneKey)
     : this(document, new[] { identityPath }, displayType, replicateGroupOp, paneKey)
 {
 }
Exemplo n.º 21
0
 public SummaryGraphPane CreateReplicatePane(PaneKey key)
 {
     return(new AreaReplicateGraphPane(GraphSummary, key));
 }
Exemplo n.º 22
0
 public PointF TransformCoordinates(double x, double y, PaneKey? paneKey, CoordType coordType = CoordType.AxisXYScale)
 {
     var graphPane = _graphHelper.GetGraphPane(paneKey ?? PaneKey.DEFAULT);
     return graphPane.GeneralTransform(new PointF((float)x, (float)y), coordType);
 }
Exemplo n.º 23
0
 public void TestMouseMove(double x, double y, PaneKey? paneKey)
 {
     var mouse = TransformCoordinates(x, y, paneKey);
     HandleMouseMove(new MouseEventArgs(MouseButtons.None, 0, (int)mouse.X, (int)mouse.Y, 0));
 }
Exemplo n.º 24
0
 public void TestMouseDown(double x, double y, PaneKey? paneKey)
 {
     var mouse = TransformCoordinates(x, y, paneKey);
     graphControl_MouseDownEvent(null, new MouseEventArgs(MouseButtons.Left, 1, (int)mouse.X, (int)mouse.Y, 0));
 }
Exemplo n.º 25
0
 public bool TestFullScanSelection(double x, double y, PaneKey? paneKey)
 {
     var graphPane = _graphHelper.GetGraphPane(paneKey ?? PaneKey.DEFAULT);
     var selectionDot = graphPane.CurveList[FULLSCAN_SELECTED_INDEX];
     var mouse = TransformCoordinates(x, y, paneKey);
     var dot = TransformCoordinates(selectionDot[0].X, selectionDot[0].Y, paneKey);
     if (!selectionDot.IsVisible)
         return false;
     const int pixelTolerance = 10;
     if (Math.Abs(mouse.X - dot.X) > pixelTolerance || Math.Abs(mouse.Y - dot.Y) > pixelTolerance)
         return false;
     return true;
 }
Exemplo n.º 26
0
 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;
 }
Exemplo n.º 27
0
 public MSGraphPane GetOrCreateGraphPane(MSGraphControl graphControl, PaneKey graphPaneKey)
 {
     var pane = GetGraphPane(graphControl, graphPaneKey);
     if (null != pane)
     {
         return pane;
     }
     if (GraphPaneKeys.Count == 0)
     {
         GraphPaneKeys.Add(graphPaneKey);
         pane = graphControl.GraphPane;
         ApplySettingsToGraphPane(pane);
         return pane;
     }
     int index = GraphPaneKeys.BinarySearch(graphPaneKey);
     int iInsert = ~index;
     var graphPane = InsertMsGraphPane(graphControl, iInsert);
     GraphPaneKeys.Insert(iInsert, graphPaneKey);
     using (var graphics = graphControl.CreateGraphics())
     {
         graphControl.MasterPane.SetLayout(graphics, PaneLayout.SingleColumn);
     }
     return graphPane;
 }
Exemplo n.º 28
0
 public MSGraphPane GetGraphPane(PaneKey paneKey)
 {
     return _displayState.GetGraphPane(GraphControl, paneKey);
 }
Exemplo n.º 29
0
 public MassErrorPeptideGraphPane(GraphSummary graphSummary, PaneKey paneKey)
     : base(graphSummary, paneKey)
 {
 }
Exemplo n.º 30
0
 public AreaPeptideGraphPane(GraphSummary graphSummary, PaneKey paneKey)
     : base(graphSummary, paneKey)
 {
 }
Exemplo n.º 31
0
 public MSGraphPane GetGraphPane(MSGraphControl graphControl, PaneKey graphPaneKey)
 {
     if (!AllowSplitPanes)
     {
         return graphControl.GraphPane;
     }
     int index = GraphPaneKeys.BinarySearch(graphPaneKey);
     if (index >= 0)
     {
         return (MSGraphPane) graphControl.MasterPane.PaneList[index];
     }
     return null;
 }
Exemplo n.º 32
0
 public MassErrorReplicateGraphPane(GraphSummary graphSummary, PaneKey paneKey)
     : base(graphSummary)
 {
     PaneKey = paneKey;
 }
Exemplo n.º 33
0
        private void DisplayTotals(IRegressionFunction timeRegressionFunction,
            ChromatogramSet chromatograms,
            float mzMatchTolerance,
            int countLabelTypes,
            ref double bestStartTime,
            ref double bestEndTime)
        {
            // Construct and add graph items for all relevant transition groups.
            float fontSize = FontSize;
            int lineWidth = LineWidth;
            int iCharge = -1;
            int? charge = null;
            var chromGroupInfos = ChromGroupInfos;
            for (int i = 0; i < _nodeGroups.Length; i++)
            {
                var nodeGroup = _nodeGroups[i];
                var chromGroupInfo = chromGroupInfos[i];
                if (chromGroupInfo == null)
                    continue;

                ChromFileInfoId fileId = chromatograms.FindFile(chromGroupInfo);

                // Collect the chromatogram info for the transition children
                // of this transition group.
                ChromatogramInfo infoPrimary = null;
                TransitionChromInfo tranPeakInfo = null;
                float maxPeakHeight = float.MinValue;
                var listChromInfo = new List<ChromatogramInfo>();
                foreach (TransitionDocNode nodeTran in nodeGroup.Children)
                {
                    var info = chromGroupInfo.GetTransitionInfo((float)nodeTran.Mz, mzMatchTolerance);
                    if (info == null)
                        continue;

                    listChromInfo.Add(info);

                    // 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;
                        tranPeakInfo = transitionChromInfo;
                        infoPrimary = info;
                    }

                    // Adjust best peak window used to zoom the graph to the best peak
                    AddBestPeakTimes(transitionChromInfo, ref bestStartTime, ref bestEndTime);
                }

                // If any transitions are present for this group, add a graph item to
                // the graph for it.
                if (listChromInfo.Count > 0)
                {
                    if (infoPrimary == null)
                        infoPrimary = listChromInfo[0];

                    // Sum the intensities of all transitions into the first chromatogram
                    infoPrimary.SumIntensities(listChromInfo);

                    // Apply any transform the user has chosen
                    infoPrimary.Transform(Transform);

                    int iColor = GetColorIndex(nodeGroup, countLabelTypes, ref charge, ref iCharge);
                    Color color = COLORS_GROUPS[iColor % COLORS_GROUPS.Length];

                    bool[] annotateAll = new bool[infoPrimary.NumPeaks];
                    for (int j = 0; j < annotateAll.Length; j++)
                    {
                        var peak = infoPrimary.GetPeak(j);
                        if (peak.IsForcedIntegration)
                            continue;

                        // Exclude any peaks between the boundaries of the chosen peak.
                        if (tranPeakInfo != null &&
                            tranPeakInfo.StartRetentionTime < peak.RetentionTime &&
                            peak.RetentionTime < tranPeakInfo.EndRetentionTime)
                            continue;
                        annotateAll[j] = true;
                    }
                    var graphItem = new ChromGraphItem(nodeGroup,
                                                       null,
                                                       infoPrimary,
                                                       tranPeakInfo,
                                                       timeRegressionFunction,
                                                       annotateAll,
                                                       null,
                                                       0,
                                                       false,
                                                       false,
                                                       0,
                                                       color,
                                                       fontSize,
                                                       lineWidth);
                    var graphPaneKey = new PaneKey(nodeGroup);
                    _graphHelper.AddChromatogram(graphPaneKey, graphItem);
                }
            }
        }
Exemplo n.º 34
0
            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;
            }
Exemplo n.º 35
0
 public SummaryGraphPane CreatePeptidePane(PaneKey key)
 {
     return(new AreaPeptideGraphPane(GraphSummary, key));
 }
Exemplo n.º 36
0
        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));
            }
        }
Exemplo n.º 37
0
        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));
            }
        }
Exemplo n.º 38
0
 public CurveItem AddChromatogram(PaneKey paneKey, ChromGraphItem chromGraphItem)
 {
     var chromDisplayState = (ChromDisplayState) _displayState;
     chromDisplayState.ChromGraphItems.Add(new KeyValuePair<PaneKey, ChromGraphItem>(paneKey, chromGraphItem));
     return GraphControl.AddGraphItem(chromDisplayState.GetOrCreateGraphPane(GraphControl, paneKey), chromGraphItem, false);
 }