private void RunUnsupervisedLearner()
 {
     UnsupervisedLearner UL = new UnsupervisedLearner();
     ResultGroups = UL.run(DeconData);
 }
        //This function draws the ROC curve by the TP and FP rates calculated from the score.
        private void scoreBasedGraph()
        {
            CompositionHypothesisTabbedForm comp = new CompositionHypothesisTabbedForm();
            SupervisedLearner SL = new SupervisedLearner();
            Feature Fea = readFeature(oFDAddFeatureFiles.FileName);
            //Create the list of random composition hypotesis for testing FDR.
            //ObtainTrue Position data.
            List<CompositionHypothesisEntry> CH = comp.getCompHypo(oFDCompositionTest.FileName);
            List<ResultsGroup>[] TrueDATA = SL.EvaluateFeature(oFDTest, CH, Fea);

            this.drawGraph(TrueDATA, " Loaded Features");

            //Checkbox1 is default features.####################################
            List<ResultsGroup>[] DefaultFeature = new List<ResultsGroup>[oFDTest.FileNames.Count()];
            String path = Application.StartupPath + "\\FeatureDefault.fea";
            Feature DeFea = readFeature(path);
            if (checkBox1.Checked == true)
            {
                List<ResultsGroup>[] TrueDATADefault = SL.EvaluateFeature(oFDTest, CH, DeFea);

                this.drawGraph(TrueDATADefault, " Default Features");
            }

            //################################################
            //Checkbox2 is unsupervised Learning. It is a bit different from supervised learning, so it is hard-coded here.

            if (checkBox2.Checked == true)
            {
                UnsupervisedLearner UL = new UnsupervisedLearner();
                List<ResultsGroup>[] USLTrueDATA = UL.evaluate(oFDTest, Fea);
                //ROC curve needs match to perform, so we will use the match list from Supervised learning and apply them to USLDATA.
                for (int i = 0; i < oFDTest.FileNames.Count(); i++)
                {
                    USLTrueDATA[i] = USLTrueDATA[i].OrderByDescending(b => b.DeconRow.MonoisotopicMassWeight).ToList();
                    int USllasttruematch = 0;
                    for (int j = 0; j < TrueDATA[i].Count; j++)
                    {
                        if (TrueDATA[i][j].Match == true)
                        {
                            for (int k = USllasttruematch; k < USLTrueDATA[i].Count; k++)
                            {
                                if (USLTrueDATA[i][k].DeconRow.MonoisotopicMassWeight < TrueDATA[i][j].DeconRow.MonoisotopicMassWeight)
                                {
                                    USllasttruematch = k;
                                    break;
                                }
                                if (USLTrueDATA[i][k].DeconRow.MonoisotopicMassWeight == TrueDATA[i][j].DeconRow.MonoisotopicMassWeight)
                                {
                                    USLTrueDATA[i][k].Match = true;
                                    USLTrueDATA[i][k].PredictedComposition = TrueDATA[i][j].PredictedComposition;
                                    USllasttruematch = k + 1;
                                    break;
                                }
                                if (USLTrueDATA[i][k].DeconRow.MonoisotopicMassWeight > TrueDATA[i][j].DeconRow.MonoisotopicMassWeight)
                                {
                                    USLTrueDATA[i][k].Match = false;
                                }
                            }
                        }
                    }
                }

                //Now that both of the data got their matchs, draw the graph
                this.drawGraph(USLTrueDATA, " Unsupervised Learning + Loaded Features");
            }
            //#############################unsupervised learning part ends#################

            //Finally populate the Resulting datagridview and the combobox1

            comboBox1.Invoke(new MethodInvoker(delegate
            {
                for (int i = 0; i < TF.Count; i++)
                {
                    comboBox1.Items.Add(TF[i].TableName);
                }
                comboBox1.SelectedIndex = 0;
            }));
            dataGridView1.Invoke(new MethodInvoker(delegate
            {
                dataGridView1.DataSource = TF[0];
            }));
        }
        //This function draws the ROC curve by the TP and FP rates calculated from the false data set
        private void DecoyDataROC()
        {
            CompositionHypothesisTabbedForm comp = new CompositionHypothesisTabbedForm();
            SupervisedLearner SL = new SupervisedLearner();
            Features featuresMenu = new Features();
            String currentpath = Application.StartupPath + "\\FeatureCurrent.fea";
            Feature currentFeatures = featuresMenu.readFeature(currentpath);
            //Create the list of random composition hypotesis for testing FDR.
            //ObtainTrue Position data.

            falseDataset fD = new falseDataset();
            List<CompositionHypothesisEntry> falseCH = fD.genFalse(oFDcposTest.FileName, CompositionHypothesisList, oFDPPMSD);
            List<ResultsGroup>[] decoyData = SL.EvaluateFeature(DeconData, falseCH, currentFeatures);

            this.drawGraph(decoyData, " ", 0);

            //Checkbox1 is default features.####################################
            List<ResultsGroup>[] DefaultFeature = new List<ResultsGroup>[DeconData.FileNames.Count()];
            String path = Application.StartupPath + "\\FeatureDefault.fea";
            Feature DeFea = featuresMenu.readFeature(path);
            if (checkBox1.Checked == true)
            {
                List<ResultsGroup>[] decoyDataDefault = SL.EvaluateFeature(DeconData, falseCH, DeFea);
                this.drawGraph(decoyDataDefault, " Default Features", 0);
            }

            //################################################
            //Checkbox2 is unsupervised Learning. It is a bit different from supervised learning, so it is hard-coded here.
            UnsupervisedLearner UL = new UnsupervisedLearner();
            if (checkBox2.Checked == true)
            {
                List<ResultsGroup>[] USLFalseDATA = UL.evaluate(DeconData, currentFeatures);
                //ROC curve needs match to perform, so we will use the match list from Supervised learning and apply them to USLDATA.
                for (int i = 0; i < DeconData.FileNames.Count(); i++)
                {
                    decoyData[i] = decoyData[i].OrderByDescending(a => a.DeconRow.MonoisotopicMassWeight).ToList();
                    USLFalseDATA[i] = USLFalseDATA[i].OrderByDescending(b => b.DeconRow.MonoisotopicMassWeight).ToList();
                    int USllasttruematch = 0;
                    for (int j = 0; j < decoyData[i].Count; j++)
                    {
                        if (decoyData[i][j].Match == true)
                        {
                            for (int k = USllasttruematch; k < USLFalseDATA[i].Count; k++)
                            {
                                if (USLFalseDATA[i][k].DeconRow.MonoisotopicMassWeight < decoyData[i][j].DeconRow.MonoisotopicMassWeight)
                                {
                                    USllasttruematch = k;
                                    break;
                                }
                                if (USLFalseDATA[i][k].DeconRow.MonoisotopicMassWeight == decoyData[i][j].DeconRow.MonoisotopicMassWeight)
                                {
                                    USLFalseDATA[i][k].Match = true;
                                    USLFalseDATA[i][k].PredictedComposition = decoyData[i][j].PredictedComposition;
                                    USllasttruematch = k + 1;
                                    break;
                                }
                                if (USLFalseDATA[i][k].DeconRow.MonoisotopicMassWeight > decoyData[i][j].DeconRow.MonoisotopicMassWeight)
                                {
                                    USLFalseDATA[i][k].Match = false;
                                }
                            }
                        }
                    }
                }

                //Now that both of the data got their matchs, draw the graph
                this.drawGraph(USLFalseDATA, " Unsupervised Learning", 0);
            }
            //#############################unsupervised learning part ends#################

            //Finally populate the Resulting datagridview and the combobox1

            comboBox2.Invoke(new MethodInvoker(delegate
            {
                for (int i = 0; i < TF.Count; i++)
                {
                    comboBox2.Items.Add(TF[i].TableName);
                }
                comboBox2.SelectedIndex = 0;
            }));
            dataGridView2.Invoke(new MethodInvoker(delegate
            {
                dataGridView2.DataSource = TF[0];
            }));
        }