public void results_summary_doesnt_crash_without_initializing()
 {
     Sweet.lollipop = new Lollipop();
     Assert.True(ResultsSummaryGenerator.generate_full_report().Length > 0);
     Assert.True(ResultsSummaryGenerator.datatable_tostring(ResultsSummaryGenerator.experimental_results_dataframe(Sweet.lollipop.target_proteoform_community, new TusherAnalysis1())).Length > 0);
     Assert.True(ResultsSummaryGenerator.datatable_tostring(ResultsSummaryGenerator.topdown_results_dataframe()).Length > 0);
     Assert.True(ResultsSummaryGenerator.datatable_tostring(ResultsSummaryGenerator.experimental_intensities_dataframe()).Length > 0);
 }
        public void biorepintensitytableLog2Fold()
        {
            Sweet.lollipop = new Lollipop();
            Dictionary <string, List <string> > conditionsBioReps = new Dictionary <string, List <string> >
            {
                { "n", new List <string> {
                      1.ToString(), 2.ToString(), 3.ToString()
                  } },
                { "s", new List <string> {
                      1.ToString(), 2.ToString(), 3.ToString()
                  } },
            };

            Sweet.lollipop.Log2FoldChangeAnalysis.conditionBiorepIntensitySums = conditionsBioReps.SelectMany(kv => kv.Value.Select(v => new Tuple <string, string>(kv.Key, v))).ToDictionary(t => t, t => 1d);
            List <InputFile> input_files = new List <InputFile>
            {
                ConstructorsForTesting.InputFile("fake.txt", Labeling.NeuCode, Purpose.Quantification, "n", "s", "1", "1", "1"), //0
                ConstructorsForTesting.InputFile("fake.txt", Labeling.NeuCode, Purpose.Quantification, "n", "s", "1", "2", "1"), //1
                ConstructorsForTesting.InputFile("fake.txt", Labeling.NeuCode, Purpose.Quantification, "n", "s", "2", "1", "1"), //2
                ConstructorsForTesting.InputFile("fake.txt", Labeling.NeuCode, Purpose.Quantification, "n", "s", "2", "2", "1"), //3
                ConstructorsForTesting.InputFile("fake.txt", Labeling.NeuCode, Purpose.Quantification, "n", "s", "3", "1", "1"), //4
                ConstructorsForTesting.InputFile("fake.txt", Labeling.NeuCode, Purpose.Quantification, "n", "s", "3", "2", "1"), //5
            };
            ExperimentalProteoform e = ConstructorsForTesting.ExperimentalProteoform("asdf");

            e.quant.Log2FoldChangeValues.allIntensities = new Dictionary <Tuple <string, string>, BiorepIntensity>
            {
                { new Tuple <string, string>("n", 1.ToString()), new BiorepIntensity(false, 1.ToString(), "n", 1) },
                { new Tuple <string, string>("n", 2.ToString()), new BiorepIntensity(true, 2.ToString(), "n", 1) },
                { new Tuple <string, string>("n", 3.ToString()), new BiorepIntensity(false, 3.ToString(), "n", 1) },
                { new Tuple <string, string>("s", 1.ToString()), new BiorepIntensity(false, 1.ToString(), "s", 1) },
                { new Tuple <string, string>("s", 2.ToString()), new BiorepIntensity(false, 2.ToString(), "s", 1) },
                { new Tuple <string, string>("s", 3.ToString()), new BiorepIntensity(false, 3.ToString(), "s", 1) },
            };
            // With imputation uses processed values
            Assert.False(ResultsSummaryGenerator.datatable_tostring(ResultsSummaryGenerator.biological_replicate_intensities(Sweet.lollipop.Log2FoldChangeAnalysis, new List <ExperimentalProteoform> {
                e
            }, input_files, conditionsBioReps, true, true)).Contains("NaN"));

            // Without imputation uses raw values
            e.biorepIntensityList = e.quant.Log2FoldChangeValues.allIntensities.Values.Where(x => !x.imputed).ToList();
            Assert.True(ResultsSummaryGenerator.datatable_tostring(ResultsSummaryGenerator.biological_replicate_intensities(Sweet.lollipop.Log2FoldChangeAnalysis, new List <ExperimentalProteoform> {
                e
            }, input_files, conditionsBioReps, false, true)).Contains("\t0\t"));

            // Headers should be condition_biorep_fraction_techrep
            string[] header = ResultsSummaryGenerator.datatable_tostring(ResultsSummaryGenerator.biological_replicate_intensities(Sweet.lollipop.Log2FoldChangeAnalysis, new List <ExperimentalProteoform> {
                e
            }, input_files, conditionsBioReps, false, true)).Split('\n')[0].Split('\t');
            Assert.True(header[1] == "n_1" && header[2] == "n_2" && header[3] == "n_3" && header[4] == "s_1" && header[5] == "s_2" && header[6] == "s_3");
            string[] line = ResultsSummaryGenerator.datatable_tostring(ResultsSummaryGenerator.biological_replicate_intensities(Sweet.lollipop.Log2FoldChangeAnalysis, new List <ExperimentalProteoform> {
                e
            }, input_files, conditionsBioReps, false, true)).Split('\n')[1].Split('\t');
            Assert.True(line.First() == e.accession);
            Assert.True(line[1] == "1" && line[2] == "0" && line[3] == "1" && line[4] == "1" && line[5] == "1" && line[6] == "1"); // all "n" condition is imputed
        }
        public void results_dataframe_with_something()
        {
            Sweet.lollipop = new Lollipop();
            Sweet.lollipop.input_files.Add(ConstructorsForTesting.InputFile("fake.txt", Labeling.NeuCode, Purpose.Identification, "n", "s", "1", "1", "1")); //0
            ExperimentalProteoform e = ConstructorsForTesting.ExperimentalProteoform("E1");

            e.linked_proteoform_references = new List <Proteoform>(new List <Proteoform> {
                ConstructorsForTesting.make_a_theoretical()
            });
            e.ptm_set = e.linked_proteoform_references.Last().ptm_set;
            ProteoformFamily f = new ProteoformFamily(e);

            f.construct_family();
            Sweet.lollipop.target_proteoform_community.families = new List <ProteoformFamily> {
                f
            };
            string[] lines = ResultsSummaryGenerator.datatable_tostring(ResultsSummaryGenerator.experimental_results_dataframe(Sweet.lollipop.target_proteoform_community, Sweet.lollipop.TusherAnalysis1)).Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            Assert.True(lines.Count() == 3);
            Assert.True(lines.Any(a => a.Contains("E1")));
            TopDownProteoform td = ConstructorsForTesting.TopDownProteoform("TD1", 1000, 10);

            td.linked_proteoform_references = new List <Proteoform>(new List <Proteoform> {
                ConstructorsForTesting.make_a_theoretical()
            });
            td.ptm_set = e.linked_proteoform_references.Last().ptm_set;
            ProteoformFamily f2 = new ProteoformFamily(td);

            f2.construct_family();
            Sweet.lollipop.target_proteoform_community.families = new List <ProteoformFamily> {
                f2
            };
            Sweet.lollipop.topdown_proteoforms = new List <TopDownProteoform>()
            {
                td
            };
            lines = ResultsSummaryGenerator.datatable_tostring(ResultsSummaryGenerator.experimental_results_dataframe(Sweet.lollipop.target_proteoform_community, Sweet.lollipop.TusherAnalysis1)).Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            Assert.True(lines.Count() == 3);
            lines = ResultsSummaryGenerator.datatable_tostring(ResultsSummaryGenerator.topdown_results_dataframe()).Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            Assert.True(lines.Count() == 3);
            Assert.True(lines.Any(a => a.Contains("TD1")));
            Sweet.lollipop.target_proteoform_community.families = new List <ProteoformFamily> {
                f, f2
            };
            lines = ResultsSummaryGenerator.datatable_tostring(ResultsSummaryGenerator.experimental_intensities_dataframe()).Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            Assert.AreEqual(lines.Count(), 4);
            Assert.True(lines.Any(a => a.Contains("E1")));
            Assert.True(lines.Any(a => a.Contains("TD1")));
        }