Example #1
0
        public void MakeFilesLists(ComparePeakBoundaries comparer, double falsePositiveCutoff, bool observed, out PointPairList filesPoints, out List <string> filesNames)
        {
            filesPoints = new PointPairList();
            filesNames  = new List <string>();
            var matches       = comparer.Matches;
            var matchesByFile = matches.GroupBy(match => match.ReplicateName).OrderBy(group => group.Key);
            int i             = 1;

            foreach (var matchGroup in matchesByFile)
            {
                PointPairList rocPoints;
                var           matchesInGroup = matchGroup.ToList();
                if (comparer.HasNoScores)
                {
                    matchesInGroup.Sort(PeakBoundsMatch.CompareQValue);
                }
                else
                {
                    matchesInGroup.Sort(PeakBoundsMatch.CompareScore);
                }
                RocFromSortedMatches(matchesInGroup, Normalizer, out rocPoints);
                var pointThreshold = GetCurveThreshold(rocPoints, falsePositiveCutoff, observed);
                // Error is 2x the observed error rate, so that wiskers extend above and below bar item
                // by the number of observed false-positives
                filesPoints.Add(MeanErrorBarItem.MakePointPair(i++, pointThreshold.Y, pointThreshold.X * pointThreshold.Y * 2));
                filesNames.Add(matchGroup.Key);
            }
        }
Example #2
0
        private void UpdateGraph()
        {
            if (!IsHandleCreated)
            {
                return;
            }
            zedGraphControl.GraphPane.GraphObjList.Clear();
            zedGraphControl.GraphPane.CurveList.Clear();
            _barGraph = null;
            _rows     = null;
            var points = new PointPairList();
            var groupComparisonModel = FoldChangeBindingSource.GroupComparisonModel;
            var groupComparisonDef   = groupComparisonModel.GroupComparisonDef;
            var document             = groupComparisonModel.Document;
            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);
            var textLabels            = new List <string>();
            var rows = _bindingListSource.OfType <RowItem>()
                       .Select(rowItem => rowItem.Value)
                       .OfType <FoldChangeBindingSource.FoldChangeRow>()
                       .ToArray();
            bool showLabelType = rows.Select(row => row.IsotopeLabelType).Distinct().Count() > 1;
            bool showMsLevel   = rows.Select(row => row.MsLevel).Distinct().Count() > 1;
            bool showGroup     = rows.Select(row => row.Group).Distinct().Count() > 1;

            foreach (var row in rows)
            {
                var    foldChangeResult = row.FoldChangeResult;
                double error            = Math.Log(foldChangeResult.MaxFoldChange / foldChangeResult.FoldChange, 2.0);
                var    point            = MeanErrorBarItem.MakePointPair(points.Count, foldChangeResult.Log2FoldChange, error);
                points.Add(point);
                string label;
                if (null != row.Peptide)
                {
                    try
                    {
                        label = uniquePrefixGenerator.GetUniquePrefix(
                            row.Peptide.GetDocNode().ModifiedTarget.DisplayName, row.Peptide.GetDocNode().IsProteomic);
                    }
                    catch
                    {
                        // Peptide must have been deleted.
                        label = row.Peptide.GetDocNode().ModifiedTarget.DisplayName;
                    }
                }
                else
                {
                    label = ProteinMetadataManager.ProteinModalDisplayText(row.Protein.DocNode);
                }
                if (showMsLevel && row.MsLevel.HasValue)
                {
                    label += @" MS" + row.MsLevel; //;
                }
                if (showLabelType && row.IsotopeLabelType != null)
                {
                    label += @" (" + row.IsotopeLabelType.Title + @")";
                }
                if (showGroup && !Equals(row.Group, default(GroupIdentifier)))
                {
                    label += @" " + row.Group;
                }
                textLabels.Add(label);
                if (IsSelected(row))
                {
                    double y, height;
                    if (foldChangeResult.Log2FoldChange >= 0)
                    {
                        y      = foldChangeResult.Log2FoldChange + error;
                        height = y;
                    }
                    else
                    {
                        y      = 0;
                        height = error - foldChangeResult.Log2FoldChange;
                    }
                    zedGraphControl.GraphPane.GraphObjList.Add(new BoxObj(point.X + .5, y, .99, height)
                    {
                        ZOrder = ZOrder.E_BehindCurves,
                        IsClippedToChartRect = true
                    });
                }
            }
            zedGraphControl.GraphPane.XAxis.Title.Text = groupComparisonDef.PerProtein ? GroupComparisonStrings.FoldChangeBarGraph_UpdateGraph_Protein : GroupComparisonStrings.FoldChangeBarGraph_UpdateGraph_Peptide;
            zedGraphControl.GraphPane.YAxis.Title.Text = GroupComparisonStrings.FoldChangeBarGraph_UpdateGraph_Log_2_Fold_Change;
            var barGraph = new MeanErrorBarItem(null, points, Color.Black, Color.Blue);

            zedGraphControl.GraphPane.CurveList.Add(barGraph);
            zedGraphControl.GraphPane.XAxis.Scale.MinAuto     = zedGraphControl.GraphPane.XAxis.Scale.MaxAuto =
                zedGraphControl.GraphPane.YAxis.Scale.MinAuto = zedGraphControl.GraphPane.YAxis.Scale.MaxAuto = true;
            zedGraphControl.GraphPane.XAxis.Type             = AxisType.Text;
            zedGraphControl.GraphPane.XAxis.Scale.TextLabels = textLabels.ToArray();
            _axisLabelScaler.ScaleAxisLabels();
            zedGraphControl.GraphPane.AxisChange();
            zedGraphControl.Invalidate();
            _barGraph = barGraph;
            _rows     = rows;
        }
Example #3
0
        public void UpdateGraph()
        {
            var rocPane   = zedGraphRoc.GraphPane;
            var qqPane    = zedGraphQq.GraphPane;
            var filesPane = zedGraphFiles.GraphPane;

            ClearGraphPane(rocPane);
            ClearGraphPane(qqPane);
            ClearGraphPane(filesPane);
            if (!_peakBoundaryList.Any(comp => comp.IsActive))
            {
                InitializeGraphPanes();
                return;
            }
            rocPane.Title.Text = Resources.ComparePeakPickingDlg_UpdateGraph_ROC_Plot_Comparison;
            qqPane.Title.Text  = Resources.ComparePeakPickingDlg_UpdateGraph_Q_Q_Comparison;
            bool observed = checkObserved.Checked;

            filesPane.Title.Text = string.Format(observed
                ? Resources.ComparePeakPickingDlg_UpdateGraph_Replicate_Comparison__Observed_FPR____0__
                : Resources.ComparePeakPickingDlg_UpdateGraph_Replicate_Comparison__q_value____0__, textBoxFilesQCutoff.Text);
            int          i          = -1;
            const double minRocY    = 0;
            const double minRocX    = 0;
            double       maxRocY    = 0;
            double       maxRocX    = 0;
            double       maxFilesY  = 0;
            double       maxFilesX  = 0;
            double       maxQq      = 1e-6;
            double       minQq      = 1;
            var          filesNames = new List <string>();

            foreach (var comparer in _peakBoundaryList)
            {
                ++i;
                if (!comparer.IsActive)
                {
                    continue;
                }
                PointPairList rocPoints;
                MakeRocLists(comparer, Normalizer, out rocPoints);
                maxRocY = Math.Max(maxRocY, rocPoints.Select(point => point.Y).Max());
                maxRocX = _xAxisFocus ? X_AXIS_FOCUS : Math.Max(maxRocX, rocPoints.Select(point => point.X).Max());
                var rocCurve = new LineItem(comparer.Name, rocPoints, _colors[i % _colors.Count], SymbolType.None, 3);
                rocPane.CurveList.Add(rocCurve);
                if (_showFpCutoff)
                {
                    PlaceLabelAtCutoff(rocPoints, rocPane, Q_VALUE_SIG);
                }

                PointPairList filesPoints;
                MakeFilesLists(comparer, _qValueSig, observed, out filesPoints, out filesNames);
                maxFilesY = Math.Max(maxFilesY, filesPoints.Select(point => point.Y).Max());
                maxFilesX = Math.Max(maxFilesX, filesPoints.Select(point => point.X).Max());
                var bar = new MeanErrorBarItem(comparer.Name, filesPoints, _colors[i % _colors.Count], Color.Black);
                bar.Bar.Fill.Type        = FillType.Solid;
                bar.Bar.Border.IsVisible = false;
                filesPane.CurveList.Add(bar);

                if (!comparer.HasNoQValues)
                {
                    PointPairList qqPoints;
                    MakeQValueLists(comparer, out qqPoints);
                    double maxQqPoint  = qqPoints.Select(point => Math.Max(point.X, point.Y)).Max();
                    var    qqNonzeros  = qqPoints.Where(point => point.Y > 0).Select(point => point.Y).ToList();
                    double minQqYPoint = qqNonzeros.Any() ? qqNonzeros.Min() : 0.001;
                    maxQq = Math.Max(maxQq, maxQqPoint);
                    minQq = Math.Min(minQq, minQqYPoint);
                    var qqCurve = new LineItem(comparer.Name, qqPoints, _colors[i % _colors.Count], SymbolType.None, 3);
                    qqPane.CurveList.Add(qqCurve);

                    if (_showFpCutoffQ)
                    {
                        PlaceLabelAtCutoff(qqPoints, qqPane, Q_VALUE_SIG);
                    }
                }
            }
            var minQqPlot      = Math.Min(minQq * MIN_SIG_FP, Q_VALUE_SIG * 0.5);
            var maxQqPlot      = Math.Max(maxQq * MARGIN, Q_VALUE_SIG * MARGIN);
            var equalityPoints = new PointPairList {
                { minQqPlot, minQqPlot }, { 1, 1 }
            };
            var equalityCurve = new LineItem(Resources.ComparePeakPickingDlg_UpdateGraph_Equality, equalityPoints, Color.Black, SymbolType.None);

            qqPane.CurveList.Add(equalityCurve);
            if (_showFpCutoffQ)
            {
                var significancePoints = new PointPairList {
                    { Q_VALUE_SIG, minQq }, { Q_VALUE_SIG, maxQq }
                };
                var significanceCurve = new LineItem(string.Format(Resources.ComparePeakPickingDlg_UpdateGraph__0__significance_threshold, Q_VALUE_SIG), significancePoints, _colorSigLine, SymbolType.None);
                qqPane.CurveList.Add(significanceCurve);
            }
            if (_showFpCutoff)
            {
                var significancePointsRoc = new PointPairList {
                    { Q_VALUE_SIG, minRocY }, { Q_VALUE_SIG, maxRocY *MARGIN }
                };
                var significanceCurveRoc = new LineItem(string.Format(Resources.ComparePeakPickingDlg_UpdateGraph__0__observed_false_positive_rate, Q_VALUE_SIG), significancePointsRoc, _colorSigLine, SymbolType.None);
                rocPane.CurveList.Add(significanceCurveRoc);
            }

            rocPane.XAxis.Scale.Min   = minRocX;
            rocPane.XAxis.Scale.Max   = maxRocX * MARGIN;
            rocPane.YAxis.Scale.Min   = minRocY;
            rocPane.YAxis.Scale.Max   = maxRocY * MARGIN;
            qqPane.XAxis.Scale.Min    = minQqPlot;
            qqPane.XAxis.Scale.Max    = maxQqPlot;
            qqPane.YAxis.Scale.Min    = minQqPlot;
            qqPane.YAxis.Scale.Max    = maxQqPlot;
            qqPane.XAxis.Type         = AxisType.Log;
            qqPane.YAxis.Type         = AxisType.Log;
            filesPane.XAxis.Scale.Min = 0;
            filesPane.XAxis.Scale.Max = maxFilesX + 1;
            filesPane.YAxis.Scale.Min = 0;
            filesPane.YAxis.Scale.Max = maxFilesY * MARGIN;
            zedGraphRoc.AxisChange();
            zedGraphRoc.Refresh();
            zedGraphQq.AxisChange();
            zedGraphQq.Refresh();
            zedGraphFiles.AxisChange();
            zedGraphFiles.Refresh();
            filesPane.XAxis.Scale.TextLabels = filesNames.ToArray();
            filesPane.XAxis.Type             = AxisType.Text;
            _axisLabelScaler.ScaleAxisLabels();
        }