コード例 #1
0
ファイル: Venn.xaml.cs プロジェクト: pcarvalho75/patternlab
        private void Plot2()
        {
            belaGraphControl2.ClearDataBuffer();

            Font myFont = new Font(ComboBoxFonts.SelectedValue.ToString(), (float)DoubleUpDownFontSize.Value);

            belaGraphControl2.Plot(BelaGraph.BackgroundOption.None, false, true, myFont);

            //Lets clone our sparse matrix
            SparseMatrix vennSparseMatrixCache = PatternTools.ObjectCopier.Clone(plp.MySparseMatrix);


            List <IntersectionResultAnalysis> VennProbabilityDictionary = new List <IntersectionResultAnalysis>();

            //Qaulity filterS
            if ((bool)RadioButtonMinNoReplicates.IsChecked)
            {
                //BY NUMBER OF REPLICATES
                vennSparseMatrixCache.EliminateIDsThatAreNotPresentAtLeastInXReplicates((int)IntegerUpDownMinNoReplicates.Value, (bool)RadioButtonAllClasses.IsChecked);
            }
            else
            {
                //by Probability
                PatternTools.VennProbability.VennProbabilityCalculator vpc = new PatternTools.VennProbability.VennProbabilityCalculator(plp.MySparseMatrix);
                VennProbabilityDictionary = vpc.GenerateProbabilisticDictionary(4);

                string report = PatternTools.VennProbability.ResultPrinter.PrintReport(VennProbabilityDictionary, new List <string> {
                    "Low", "Medium", "High", "Very High"
                });
                RichTextBoxLog.Document.Blocks.Clear();
                RichTextBoxLog.AppendText(report);
            }

            venn = new BelaGraph.VennManager(vennSparseMatrixCache);

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


            //If we are working with probabilities, we should apply a correction
            //The venn diagram with probability only works for two classes

            if ((bool)RadioButtonFilteringProbability.IsChecked)
            {
                //We need to find the ones unique for class 1 and the ones unique for class 2.
                //If they are below the probability scores, we need to include them in the other class
                //this needs to be done using the dvs

                //Step 1, the uniques from each group
                List <List <int> > inLabel = new List <List <int> >();
                inLabel.Add(new List <int>());
                inLabel.Add(new List <int>());

                inLabel[0].AddRange(venn.VennDic[1]);
                inLabel[1].AddRange(venn.VennDic[2]);


                List <int> intersection = inLabel[0].Intersect(inLabel[1]).ToList();
                inLabel[0].RemoveAll(a => intersection.Contains(a));
                inLabel[1].RemoveAll(a => intersection.Contains(a));


                //Find the ones that fail the probability

                for (int i = 1; i <= 2; i++)
                {
                    List <int> newIntersectionClass = new List <int>();   //We will put all the new unique guys in here
                    foreach (int dim in inLabel[i - 1])
                    {
                        if (!checkConfidence(dim, i, (double)DoubleUpDownProbability.Value, VennProbabilityDictionary))
                        {
                            newIntersectionClass.Add(dim);
                        }
                    }

                    foreach (int k in newIntersectionClass)
                    {
                        venn.VennDic[i].Remove(k);
                        vennSparseMatrixCache.eliminateDim(k, 0, true);
                    }
                }
            }

            //This is where we find the unique proteins
            List <BelaGraph.DataVector> dvs = venn.GetDataVectors();


            //Plot
            ButtonPlot.Content = "Please wait...";

            belaGraphControl2.ClearDataBuffer();

            //Lets save this matrix so we can do reports latter
            belaGraphControl2.vennSparseMatrixCache = vennSparseMatrixCache;

            belaGraphControl2.Title = TextBoxTitle.Text;
            belaGraphControl2.VennRadiusOfLargestCircleCorrectionFactor = (double)DoubleUpDownScaleFactor.Value;

            if (lables.Count <= 3)
            {
                for (int i = 0; i < dvs.Count; i++)
                {
                    System.Windows.Media.Color c1 = new System.Windows.Media.Color();

                    if (i == 0)
                    {
                        c1 = Colors.Green;
                    }
                    else if (i == 1)
                    {
                        c1 = Colors.Yellow;
                    }
                    else if (i == 2)
                    {
                        c1 = Colors.Blue;
                    }
                    System.Windows.Media.Color           c2 = System.Windows.Media.Color.FromArgb(c1.A, c1.R, c1.G, c1.B);
                    System.Windows.Media.SolidColorBrush sb = new System.Windows.Media.SolidColorBrush(c2);
                    sb.Opacity     = double.Parse(DoubleUpDownTransparency.Value.ToString());
                    dvs[i].MyBrush = sb;
                    belaGraphControl2.AddDataVector(dvs[i]);
                }
                BelaGraph.BackgroundOption bg = BelaGraph.BackgroundOption.None;
                belaGraphControl2.Plot(bg, false, true, myFont);
            }

            //Fill out our table;
            DataGridPairWise.Columns.Clear();

            DataTable dt = new DataTable();

            //Add the columns

            //Add the info


            for (int i = 0; i < dvs.Count; i++)
            {
                dt.Columns.Add(plp.MySparseMatrix.ClassDescriptionDictionary[int.Parse(dvs[i].Name)]);
            }

            for (int i = 0; i < dvs.Count; i++)
            {
                dt.Rows.Add(dvs[i].ThePoints.Select(a => a.Y.ToString()).ToArray());
            }

            DataGridPairWise.ItemsSource = dt.DefaultView;

            if ((bool)CheckBoxPlotLabels.IsChecked && lables.Count <= 3)
            {
                try
                {
                    belaGraphControl2.PlotVennLabels(venn.VennDic, TextBoxC1Name.Text, TextBoxC2Name.Text, TextBoxC3Name.Text, true, (bool)CheckBoxDetailed.IsChecked, plp.MyIndex, myFont);
                }
                catch (Exception e2)
                {
                    MessageBox.Show("Make sure your sparse matrix file is labeled correctly.  It should contain class 1, 2, and, 3" + "\n" + e2.Message);
                }
            }

            ButtonPlot.Content = "Plot";
        }
コード例 #2
0
        private void buttonPlot_Click(object sender, EventArgs e)
        {
            belaGraphControl2.ClearDataBuffer();
            belaGraphControl2.Plot(BelaGraph.BackgroundOption.None, false, true, myFont);

            //Lets clone our sparse matrix
            SparseMatrix vennSparseMatrixCache = PatternTools.ObjectCopier.Clone(plp.MySparseMatrix);


            List <IntersectionResultAnalysis> VennProbabilityDictionary = new List <IntersectionResultAnalysis>();

            //Qaulity filterS
            if (radioButtonFilteringMinNumberOfReplicates.Checked)
            {
                //BY NUMBER OF REPLICATES
                vennSparseMatrixCache.EliminateIDsThatAreNotPresentAtLeastInXReplicates((int)numericUpDownMinimumNumberOfReplicates.Value, radioButtonAllClasses.Checked);
            }
            else
            {
                //by Probability
                PatternTools.VennProbability.VennProbabilityCalculator vpc = new PatternTools.VennProbability.VennProbabilityCalculator(plp.MySparseMatrix);
                VennProbabilityDictionary = vpc.GenerateProbabilisticDictionary(4);

                string report = PatternTools.VennProbability.ResultPrinter.PrintReport(VennProbabilityDictionary, new List <string> {
                    "Low", "Medium", "High", "Very High"
                });
                richTextBoxLog.Clear();
                richTextBoxLog.AppendText(report);
            }

            venn = new BelaGraph.VennManager(vennSparseMatrixCache);

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


            //If we are working with probabilities, we should apply a correction
            //The venn diagram with probability only works for two classes

            if (radioButtonFilteringProbability.Checked)
            {
                //We need to find the ones unique for class 1 and the ones unique for class 2.
                //If they are below the probability scores, we need to include them in the other class
                //this needs to be done using the dvs

                //Step 1, the uniques from each group
                List <List <int> > inLabel = new List <List <int> >();
                inLabel.Add(new List <int>());
                inLabel.Add(new List <int>());

                inLabel[0].AddRange(venn.VennDic[1]);
                inLabel[1].AddRange(venn.VennDic[2]);


                List <int> intersection = inLabel[0].Intersect(inLabel[1]).ToList();
                inLabel[0].RemoveAll(a => intersection.Contains(a));
                inLabel[1].RemoveAll(a => intersection.Contains(a));


                //Find the ones that fail the probability

                for (int i = 1; i <= 2; i++)
                {
                    List <int> newIntersectionClass = new List <int>(); //We will put all the new unique guys in here
                    foreach (int dim in inLabel[i - 1])
                    {
                        if (!checkConfidence(dim, i, (double)numericUpDownFilteringProbability.Value, VennProbabilityDictionary))
                        {
                            newIntersectionClass.Add(dim);
                        }
                    }

                    foreach (int k in newIntersectionClass)
                    {
                        venn.VennDic[i].Remove(k);
                        vennSparseMatrixCache.eliminateDim(k, 0, true);
                    }
                }
            }



            //This is where we find the unique proteins
            List <BelaGraph.DataVector> dvs = venn.GetDataVectors();


            //Plot
            buttonPlot.Text = "Please wait...";
            this.Update();

            belaGraphControl2.ClearDataBuffer();

            //Lets save this matrix so we can do reports latter
            belaGraphControl2.vennSparseMatrixCache = vennSparseMatrixCache;

            belaGraphControl2.Title = textBoxTitle.Text;
            belaGraphControl2.VennRadiusOfLargestCircleCorrectionFactor = (double)numericUpDownScaleFactor.Value;

            if (lables.Count <= 3)
            {
                for (int i = 0; i < dvs.Count; i++)
                {
                    System.Drawing.Color c1 = new Color();

                    if (i == 0)
                    {
                        c1 = Color.Green;
                    }
                    else if (i == 1)
                    {
                        c1 = Color.Yellow;
                    }
                    else if (i == 2)
                    {
                        c1 = Color.Blue;
                    }
                    System.Windows.Media.Color           c2 = System.Windows.Media.Color.FromArgb(c1.A, c1.R, c1.G, c1.B);
                    System.Windows.Media.SolidColorBrush sb = new System.Windows.Media.SolidColorBrush(c2);
                    sb.Opacity     = double.Parse(numericUpDownOpacity.Value.ToString());
                    dvs[i].MyBrush = sb;
                    belaGraphControl2.AddDataVector(dvs[i]);
                }
                BelaGraph.BackgroundOption bg = (BelaGraph.BackgroundOption)Enum.Parse(typeof(BelaGraph.BackgroundOption), comboBoxBackground.SelectedItem.ToString());
                belaGraphControl2.Plot(bg, false, true, myFont);
            }

            //Fill out our table;
            dataGridView1.Columns.Clear();

            //Add the columns
            foreach (var r in dvs)
            {
                DataGridViewLinkColumn col = new DataGridViewLinkColumn();
                col.Name       = r.Name;
                col.HeaderText = r.Name;
                dataGridView1.Columns.Add(col);
            }

            //Add the info
            for (int i = 0; i < dvs.Count; i++)
            {
                dataGridView1.Rows.Add();
                dataGridView1.Rows[i].HeaderCell.Value = dvs[i].Name;
                for (int j = 0; j < dvs[i].ThePoints.Count; j++)
                {
                    DataGridViewLinkCell cell = new DataGridViewLinkCell();
                    cell.Value = dvs[i].ThePoints[j].Y;
                    dataGridView1.Rows[i].Cells[j] = cell;
                }
            }

            if (checkBoxPlotLabels.Checked && lables.Count <= 3)
            {
                try
                {
                    belaGraphControl2.PlotVennLabels(venn.VennDic, textBoxC1Name.Text, textBoxC2Name.Text, textBoxC3Name.Text, true, checkBoxDetailedLabel.Checked, plp.MyIndex, myFont);
                }
                catch (Exception e2)
                {
                    MessageBox.Show("Make sure your sparse matrix file is labeled correctly.  It should contain class 1, 2, and, 3" + "\n" + e2.Message);
                }
            }

            buttonPlot.Text = "Plot";
        }