Esempio n. 1
0
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                double pValue     = double.Parse(dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString());
                double foldChange = double.Parse(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString());

                BelaGraph.PointCav pc = new BelaGraph.PointCav();
                pc.Y = Math.Log(foldChange, 2);
                pc.X = Math.Log(pValue, 2) * (-1);
                pc.ExtraParamNumeric = pValue;

                //Clipping
                if (pValue < (double)numericUpDownPValueLowerClip.Value)
                {
                    pc.X = Math.Log((double)numericUpDownPValueLowerClip.Value, 2) * (-1);
                }

                double correctedFold = foldChange;
                if (correctedFold < 1)
                {
                    correctedFold = ((1 / foldChange) * (-1));
                }

                if (Math.Abs(correctedFold) >= (double)numericUpDownUpperYScale.Value)
                {
                    if (correctedFold < 0)
                    {
                        pc.Y = Math.Log((double)numericUpDownUpperYScale.Value, 2) * -1;
                    }
                    else
                    {
                        pc.Y = Math.Log((double)numericUpDownUpperYScale.Value, 2);
                    }
                }

                //-------------------------------------------


                pc = belaGraphControl1.MapPoint(pc);

                BelaGraph.DataVector dv = new BelaGraph.DataVector(BelaGraph.GraphStyle.Bubble, "ClickedProtein");
                dv.AddPoint(pc);
                dv.MyBrush         = new SolidColorBrush(Colors.Azure);
                dv.MyBrush.Opacity = 0.5;

                belaGraphControl1.PlotBubble(dv, 30);
                MessageBox.Show("This protein was circled in the graph");
            }
        }
Esempio n. 2
0
        private void PlotQuants()
        {
            //------------------------------------


            BelaGraphPeptideDistribution.ClearDataBuffer();
            BelaGraphPeptideDistribution.XLabel = "-log(p-value)";
            BelaGraphPeptideDistribution.YLabel = "log(fold)";
            BelaGraphPeptideDistribution.XRound = 4;
            BelaGraphPeptideDistribution.YRound = 4;


            SolidColorBrush redBrush = Brushes.Red.Clone();

            redBrush.Opacity = 0.5;

            SolidColorBrush greenBrush = Brushes.Green.Clone();

            greenBrush.Opacity = 0.5;

            SolidColorBrush grayBrush = Brushes.LightGray.Clone();

            grayBrush.Opacity = 0.4;

            BelaGraph.DataVector greenVectorPep = new BelaGraph.DataVector(BelaGraph.GraphStyle.Bubble, "Green dots", greenBrush);
            BelaGraph.DataVector redVectorPep   = new BelaGraph.DataVector(BelaGraph.GraphStyle.Bubble, "Red dots", redBrush);
            BelaGraph.DataVector grayVectorPep  = new BelaGraph.DataVector(BelaGraph.GraphStyle.Bubble, "Gray dots", grayBrush);

            foreach (PepQuant pq in MyPeptides)
            {
                //Skip Quants composed mainly of zeros or quants that have exactly 0.5 as a p-value
                if (pq.TTest == 0.5)
                {
                    continue;
                }

                double avgLogFold = pq.AVGLogFold;
                double pValue     = pq.TTest;

                if (avgLogFold < -3)
                {
                    avgLogFold = -3;
                }
                if (avgLogFold > 3)
                {
                    avgLogFold = 3;
                }

                BelaGraph.PointCav dp = new BelaGraph.PointCav();
                dp.Y          = avgLogFold;
                dp.X          = Math.Round(1 - pValue, 4);
                dp.ExtraParam = dp.Y.ToString();

                dp.MouseOverTip = "Sequence: " + pq.Sequence + "\nQuants: " + pq.MyQuants.Count + "\nAvg Log Fold: " + avgLogFold + "\nTtest: " + pValue;

                if (myPeptidesTMP.Exists(a => a.Sequence.Equals(pq.Sequence)))
                {
                    if (dp.Y > 0)
                    {
                        greenVectorPep.AddPoint(dp);
                    }
                    else
                    {
                        redVectorPep.AddPoint(dp);
                    }
                }
                else
                {
                    if ((bool)CheckBoxPlotFilteredPeptides.IsChecked)
                    {
                        grayVectorPep.AddPoint(dp);
                    }
                }
            }

            grayVectorPep.ThePoints.Sort((a, b) => b.X.CompareTo(a.X));
            redVectorPep.ThePoints.Sort((a, b) => b.X.CompareTo(a.X));
            greenVectorPep.ThePoints.Sort((a, b) => b.X.CompareTo(a.X));

            BelaGraphPeptideDistribution.AddDataVector(grayVectorPep);
            BelaGraphPeptideDistribution.AddDataVector(redVectorPep);
            BelaGraphPeptideDistribution.AddDataVector(greenVectorPep);


            BelaGraphPeptideDistribution.Plot(BelaGraph.BackgroundOption.YellowXGradient, true, true, new System.Drawing.Font("Courier New", 14));
        }
Esempio n. 3
0
        private void PerformPairWiseAnalysis()
        {
            if (folds.Count == 0)
            {
                MessageBox.Show("No proteins detected.  Make sure you use the TFold test on an experiment that has replicates and that at least one protein is detected in the number of replicates specified in the Min Replicates parameter.");
                return;
            }

            double overallFoldChange = folds.Average();


            //Now plot for BelaGraph
            //BelaGraph
            belaGraphControl1.ClearDataBuffer();
            belaGraphControl1.XLabel = "-Log2(p)";
            belaGraphControl1.YLabel = "Log2(Fold)";
            belaGraphControl1.XRound = 2;
            belaGraphControl1.YRound = 2;


            SolidColorBrush bluebrush   = System.Windows.Media.Brushes.Blue.Clone(); bluebrush.Opacity = 0.55;
            SolidColorBrush greenbrush  = System.Windows.Media.Brushes.Green.Clone(); greenbrush.Opacity = 0.55;
            SolidColorBrush orangebrush = System.Windows.Media.Brushes.Orange.Clone(); orangebrush.Opacity = 0.55;
            SolidColorBrush redbrush    = System.Windows.Media.Brushes.Red.Clone(); redbrush.Opacity = 0.55;


            BelaGraph.DataVector blueDV   = new BelaGraph.DataVector(BelaGraph.GraphStyle.Bubble, "Blue Dots", bluebrush);
            BelaGraph.DataVector orangeDV = new BelaGraph.DataVector(BelaGraph.GraphStyle.Bubble, "Orange Dots", orangebrush);
            BelaGraph.DataVector greenDV  = new BelaGraph.DataVector(BelaGraph.GraphStyle.Bubble, "Green Dots", greenbrush);
            BelaGraph.DataVector redDV    = new BelaGraph.DataVector(BelaGraph.GraphStyle.Bubble, "Red Dots", redbrush);

            int           noLabels       = plp.MySparseMatrix.ExtractLabels().Count;
            int           pointsExcluded = 0;
            List <double> allPValues     = theData.Select(a => a.pValue).OrderBy(a => a).ToList();

            double userQvalue          = (double)numericUpDownQValue.Value;
            double quantitationCuttoff = GetQuantitationCuttoff();

            theData.Sort((a, b) => a.pValue.CompareTo(b.pValue));
            double qValueFractionCounter = 0;

            List <XFoldStruct> greenOrBlue = theData.FindAll(a => GetPointColorVFold(a, allPValues[1], (double)numericUpDownA.Value, userQvalue, 1, quantitationCuttoff) <= 2).OrderBy(a => a.pValue).ThenBy(a => a.GPI).ToList();
            List <XFoldStruct> orange      = greenOrBlue.FindAll(a => a.QuantitationNegativeClass < quantitationCuttoff && a.QuantitationPositiveClass < quantitationCuttoff);

            greenOrBlue = greenOrBlue.Except(orange).ToList();

            theData.Sort((a, b) => a.pValue.CompareTo(b.pValue));

            foreach (XFoldStruct dataPoint in theData)
            {
                //We need to find the denominator; ie, all items that are green or blue
                if (!orange.Contains(dataPoint))
                {
                    qValueFractionCounter += 1 / (double)greenOrBlue.Count;
                }

                List <double> signalPos = plp.MySparseMatrix.ExtractDimValues(dataPoint.GPI, 1, false);
                List <double> signalNeg = plp.MySparseMatrix.ExtractDimValues(dataPoint.GPI, -1, false);

                dataPoint.QuantitationPositiveClass = pTools.Average(signalPos);
                dataPoint.QuantitationNegativeClass = pTools.Average(signalNeg);


                BelaGraph.PointCav pc = new BelaGraph.PointCav();
                pc.Y = Math.Log(dataPoint.FoldChange, 2);
                pc.X = Math.Log(dataPoint.pValue, 2) * (-1);
                pc.ExtraParamNumeric = dataPoint.pValue;


                double correctedFoldChange = dataPoint.CorrectedFold();

                double theAbsFold = Math.Abs(dataPoint.CorrectedFold());
                string tip        = "";
                if (plp.MySparseMatrix.ClassDescriptionDictionary.ContainsKey(1) && plp.MySparseMatrix.ClassDescriptionDictionary.ContainsKey(-1))
                {
                    tip += "PositiveClass: " + Regex.Replace(plp.MySparseMatrix.ClassDescriptionDictionary[1], "\n", "") + "\n";
                    tip += "NegativeClass: " + Regex.Replace(plp.MySparseMatrix.ClassDescriptionDictionary[-1], "\n", "") + "\n";
                }

                tip += "p-value = " + Math.Round(dataPoint.pValue, 5) + "\nFoldChange = " + correctedFoldChange + "\nIndex = " + dataPoint.GPI + "\nLocus = " + plp.MyIndex.GetName(dataPoint.GPI) + "\nMeanSignal(+) = " + Math.Round(dataPoint.QuantitationPositiveClass, 6) + "\nMeanSignal(-) = " + Math.Round(dataPoint.QuantitationNegativeClass, 5);


                tip += "\nSignalPos :";
                foreach (double s in signalPos)
                {
                    tip += " " + Math.Round(s, 6).ToString();
                }
                tip += "\n";
                tip += "SignalNeg :";
                foreach (double s in signalNeg)
                {
                    tip += " " + Math.Round(s, 6).ToString();
                }
                tip += "\nDescription = " + plp.MyIndex.GetDescription(dataPoint.GPI);

                pc.MouseOverTip = tip;


                //Perform the clipping
                if (dataPoint.pValue < (double)numericUpDownPValueLowerClip.Value)
                {
                    pc.X = Math.Log((double)numericUpDownPValueLowerClip.Value, 2) * (-1);
                }

                if (theAbsFold >= (double)numericUpDownUpperYScale.Value)
                {
                    if (dataPoint.CorrectedFold() < 0)
                    {
                        pc.Y = Math.Log((double)numericUpDownUpperYScale.Value, 2) * -1;
                    }
                    else
                    {
                        pc.Y = Math.Log((double)numericUpDownUpperYScale.Value, 2);
                    }
                }


                if (pc.X.Equals(double.NegativeInfinity))
                {
                    pointsExcluded++;
                    continue;
                }


                int theColor = GetPointColorVFold(dataPoint, allPValues[1], (double)numericUpDownA.Value, userQvalue, qValueFractionCounter, quantitationCuttoff);


                if (theColor == 0)
                {
                    blueDV.AddPoint(pc);
                }
                else if (theColor == 1)
                {
                    orangeDV.AddPoint(pc);
                }
                else if (theColor == 2)
                {
                    greenDV.AddPoint(pc);
                }
                else if (theColor == 3)
                {
                    redDV.AddPoint(pc);
                }

                dataPoint.Color = theColor;
            }

            belaGraphControl1.AddDataVector(blueDV);
            belaGraphControl1.AddDataVector(orangeDV);
            belaGraphControl1.AddDataVector(greenDV);
            belaGraphControl1.AddDataVector(redDV);



            belaGraphControl1.Plot(BelaGraph.BackgroundOption.YellowXGradient, true, true, new System.Drawing.Font("Courier New", 12));

            //Lets  add some labels

            if (plp.MySparseMatrix.ClassDescriptionDictionary.ContainsKey(1) && plp.MySparseMatrix.ClassDescriptionDictionary.ContainsKey(-1))
            {
                string descTop    = plp.MySparseMatrix.ClassDescriptionDictionary[-1];
                string descBottom = plp.MySparseMatrix.ClassDescriptionDictionary[1];


                System.Windows.Controls.Label TopLabel = new System.Windows.Controls.Label();
                TopLabel.Content = descTop;

                System.Windows.Controls.Label BottomLabel = new System.Windows.Controls.Label();
                BottomLabel.Content = descBottom;


                belaGraphControl1.MyCanvas.Children.Add(TopLabel);

                belaGraphControl1.MyCanvas.Children.Add(BottomLabel);
                belaGraphControl1.SetBottom(BottomLabel, 0);
            }
            //


            //Update the dot lables
            double totalDots = greenDV.ThePoints.Count + blueDV.ThePoints.Count + redDV.ThePoints.Count + orangeDV.ThePoints.Count;

            this.labelGreenDots.Text   = greenDV.ThePoints.Count + " (" + Math.Round(((double)greenDV.ThePoints.Count / (double)totalDots) * 100, 1) + "%)";
            this.labelBlueDots.Text    = blueDV.ThePoints.Count + " (" + Math.Round(((double)blueDV.ThePoints.Count / (double)totalDots) * 100, 1) + "%)";
            this.labelOrangeDots.Text  = orangeDV.ThePoints.Count + " (" + Math.Round(((double)orangeDV.ThePoints.Count / (double)totalDots) * 100, 1) + "%)";
            this.labelRedDots.Text     = redDV.ThePoints.Count + " (" + Math.Round(((double)redDV.ThePoints.Count / (double)totalDots) * 100, 1) + "%)";
            this.labelTotalNumber.Text = totalDots.ToString();
            this.labelLCuttoff.Text    = quantitationCuttoff.ToString();
            this.labelAvgFold.Text     = Math.Round(overallFoldChange, 2).ToString();
        }