예제 #1
0
        public void enter_directory_of_files_updated_with_presets()
        {
            string[]      folder    = new string[] { Path.Combine(TestContext.CurrentContext.TestDirectory, "test_directory") };
            List <string> extension = new List <string> {
                ".xlsx"
            };
            List <Purpose> purpose = new List <Purpose> {
                Purpose.Identification
            };
            List <InputFile> destination = new List <InputFile>();
            InputFile        mock        = new InputFile(Path.Combine(TestContext.CurrentContext.TestDirectory, "test_directory", "one.xlsx"), Purpose.Identification);

            Sweet.change_file(mock, mock.lt_condition, nameof(mock.lt_condition), mock.lt_condition, "Normal");
            Sweet.change_file(mock, mock.hv_condition, nameof(mock.hv_condition), mock.hv_condition, "Stress");
            Sweet.change_file(mock, mock.biological_replicate, nameof(mock.biological_replicate), mock.biological_replicate.ToString(), "2");
            using (StreamWriter file = new StreamWriter(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml")))
                file.WriteLine(Sweet.save_method());
            Sweet.open_method(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"), string.Join(Environment.NewLine, File.ReadAllLines(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"))), true, out string warning);
            Sweet.lollipop.enter_input_files(folder, extension, purpose, destination, true);
            Assert.AreEqual(2, destination.Count);
            Assert.True(destination.All(f => f.extension == extension[0]));
            Assert.True(destination.All(f => f.purpose == purpose[0]));
            Assert.True(destination.Where(f => f.filename.StartsWith("one")).All(f => f.lt_condition == "Normal"));
            Assert.True(destination.Where(f => f.filename.StartsWith("one")).All(f => f.hv_condition == "Stress"));
            Assert.True(destination.Where(f => f.filename.StartsWith("one")).All(f => f.biological_replicate == "2"));
        }
예제 #2
0
        public void other_method_file_issue()
        {
            //have a name other than setting or action
            using (StreamWriter file = new StreamWriter(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml")))
                file.WriteLine(Sweet.save_method());
            Assert.IsTrue(Sweet.open_method(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"), string.Join(Environment.NewLine, File.ReadAllLines(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"))), true, out string warning1));
            string[] edit = File.ReadAllLines(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"));
            edit[2] = "  <badname field_type=\"System.Boolean\" field_name=\"badfieldname\" field_value=\"True\" />";

            File.WriteAllLines(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"), edit);
            Assert.IsFalse(Sweet.open_method(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"), string.Join(Environment.NewLine, File.ReadAllLines(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"))), true, out string warning2));

            using (StreamWriter file = new StreamWriter(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml")))
                file.WriteLine(Sweet.save_method());
            edit = File.ReadAllLines(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"));
            string[] new_edit = new string[edit.Length + 1];
            new_edit[0] = edit[0];
            new_edit[1] = edit[1];
            new_edit[2] = "  <setting field_type=\"System.Boolean\" field_name=\"badfieldname\" field_value=\"True\" />";
            for (int i = 3; i < edit.Length + 1; i++)
            {
                new_edit[i] = edit[i - 1];
            }
            string message;

            File.WriteAllLines(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"), new_edit);
            Assert.IsTrue(Sweet.open_method(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"), string.Join(Environment.NewLine, File.ReadAllLines(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"))), true, out message));
            Assert.AreEqual("Setting badfieldname has changed, and it was not changed to preset System.Boolean True in the current run\r\n", message);

            using (StreamWriter file = new StreamWriter(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml")))
                file.WriteLine(Sweet.save_method());
            edit        = File.ReadAllLines(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"));
            new_edit    = new string[edit.Length - 1];
            new_edit[0] = edit[0];
            new_edit[1] = edit[1];
            for (int i = 2; i < edit.Length - 1; i++)
            {
                new_edit[i] = edit[i + 1];
            }
            File.WriteAllLines(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"), new_edit);
            Assert.IsTrue(Sweet.open_method(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"), string.Join(Environment.NewLine, File.ReadAllLines(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"))), true, out message));
            Assert.AreEqual("The following parameters did not have a setting specified: neucode_labeled\r\n", message);

            Sweet.add_file_action(new InputFile(Path.Combine(TestContext.CurrentContext.TestDirectory, "test_td_hits_file.xlsx"), Purpose.TopDown));
            using (StreamWriter file = new StreamWriter(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml")))
                file.WriteLine(Sweet.save_method());
            edit     = File.ReadAllLines(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"));
            edit[81] = "  <action action=\"badaction file filepath with purpose TopDown\" />";
            File.WriteAllLines(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"), edit);
            Assert.IsFalse(Sweet.open_method(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"), string.Join(Environment.NewLine, File.ReadAllLines(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"))), true, out message));
        }
        public bool open_method(string methodFilePath, string[] lines, bool add_files)
        {
            bool method_file_success = Sweet.open_method(methodFilePath, String.Join(Environment.NewLine, lines), add_files, out string warning);

            if (warning.Length > 0 && MessageBox.Show("WARNING" + Environment.NewLine + Environment.NewLine + warning, "Open Method", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
            {
                return(false);
            }
            foreach (ISweetForm form in forms)
            {
                form.InitializeParameterSet();
            }
            return(method_file_success);
        }
예제 #4
0
        public void test_load_and_run()
        {
            //set parameters -- change some parameters to other than the current defaults...
            Sweet.lollipop.max_intensity_ratio      = 3.5m;
            Sweet.lollipop.min_intensity_ratio      = 1.5m;
            Sweet.lollipop.max_lysine_ct            = 21m;
            Sweet.lollipop.min_lysine_ct            = 3m;
            Sweet.lollipop.retention_time_tolerance = 1;
            Sweet.lollipop.maximum_missed_monos     = 0;
            Sweet.lollipop.mass_tolerance           = 10;
            Sweet.lollipop.maximum_missed_lysines   = 0;
            Sweet.lollipop.min_num_CS                      = 0;
            Sweet.lollipop.max_ptms                        = 0;
            Sweet.lollipop.peak_width_base_ee              = 0.001;
            Sweet.lollipop.ee_max_mass_difference          = 100;
            Sweet.lollipop.ee_max_RetentionTime_difference = 10;

            //save method
            string saved_method = Sweet.save_method().ToString();

            //change parameters back to defaults
            Sweet.lollipop.min_intensity_ratio             = 1.4m;
            Sweet.lollipop.max_intensity_ratio             = 6m;
            Sweet.lollipop.min_lysine_ct                   = 1.5m;
            Sweet.lollipop.max_lysine_ct                   = 26.2m;
            Sweet.lollipop.min_num_CS                      = 1;
            Sweet.lollipop.max_ptms                        = 3;
            Sweet.lollipop.ee_max_mass_difference          = 250;
            Sweet.lollipop.ee_max_RetentionTime_difference = 2.5;
            Sweet.lollipop.peak_width_base_ee              = 0.015;
            //load method --> should switch parametetrs to saved
            Sweet.open_method(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"), saved_method, false, out string warning);

            //tests that the method settings properly a) saved b)loaded up above
            Assert.AreEqual(3, Sweet.lollipop.min_lysine_ct);
            Assert.AreEqual(21, Sweet.lollipop.max_lysine_ct);
            Assert.AreEqual(1.5m, Sweet.lollipop.min_intensity_ratio);
            Assert.AreEqual(3.5m, Sweet.lollipop.max_intensity_ratio);
            Assert.AreEqual(10, Sweet.lollipop.mass_tolerance);
            Assert.AreEqual(1, Sweet.lollipop.retention_time_tolerance);
            Assert.AreEqual(0, Sweet.lollipop.maximum_missed_monos);
            Assert.AreEqual(0, Sweet.lollipop.maximum_missed_lysines);
            Assert.AreEqual(0, Sweet.lollipop.min_num_CS);
            Assert.AreEqual(0, Sweet.lollipop.max_ptms);
            Assert.AreEqual(100, Sweet.lollipop.ee_max_mass_difference);
            Assert.AreEqual(0.001, Sweet.lollipop.peak_width_base_ee);
            Assert.AreEqual(10, Sweet.lollipop.ee_max_RetentionTime_difference);
        }
예제 #5
0
        public void add_file_from_presets()
        {
            List <InputFile> destination = new List <InputFile>();
            InputFile        mock        = new InputFile(Path.Combine(TestContext.CurrentContext.TestDirectory, "test_directory", "one.xlsx"), Purpose.Identification);

            Sweet.add_file_action(mock);
            Sweet.change_file(mock, mock.lt_condition, nameof(mock.lt_condition), mock.lt_condition, "Normal");
            Sweet.change_file(mock, mock.hv_condition, nameof(mock.hv_condition), mock.hv_condition, "Stress");
            Sweet.change_file(mock, mock.biological_replicate, nameof(mock.biological_replicate), mock.biological_replicate.ToString(), "2");
            using (StreamWriter file = new StreamWriter(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml")))
                file.WriteLine(Sweet.save_method());
            Sweet.open_method(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"), string.Join(Environment.NewLine, File.ReadAllLines(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"))), true, out string warning);
            Sweet.add_files_from_presets(destination);
            Assert.AreEqual(1, destination.Count);
            Assert.True(destination[0].lt_condition == "Normal");
            Assert.True(destination[0].hv_condition == "Stress");
            Assert.True(destination[0].biological_replicate == "2");
        }
예제 #6
0
        public void shift_et_peak_neucode_from_actions()
        {
            Sweet.lollipop = new Lollipop();
            ProteoformCommunity test_community = new ProteoformCommunity();

            Sweet.lollipop.target_proteoform_community = test_community;

            //Make a few experimental proteoforms
            List <IAggregatable>   n1  = TestExperimentalProteoform.generate_neucode_components(100);
            List <IAggregatable>   n2  = TestExperimentalProteoform.generate_neucode_components(100);
            List <IAggregatable>   n3  = TestExperimentalProteoform.generate_neucode_components(200);
            List <IAggregatable>   n4  = TestExperimentalProteoform.generate_neucode_components(200);
            ExperimentalProteoform pf1 = ConstructorsForTesting.ExperimentalProteoform("E1");

            pf1.aggregated = n1;
            ExperimentalProteoform pf2 = ConstructorsForTesting.ExperimentalProteoform("E2");

            pf2.aggregated = n2;
            ExperimentalProteoform pf3 = ConstructorsForTesting.ExperimentalProteoform("E3");

            pf3.aggregated = n3;
            ExperimentalProteoform pf4 = ConstructorsForTesting.ExperimentalProteoform("E4");

            pf4.aggregated = n4;

            Sweet.lollipop.target_proteoform_community.experimental_proteoforms = new List <ExperimentalProteoform> {
                pf1, pf2, pf3, pf4
            }.ToArray();

            //Connect them to theoreticals to form two peaks
            ProteoformComparison      comparison14 = ProteoformComparison.ExperimentalTheoretical;
            ProteoformComparison      comparison25 = ProteoformComparison.ExperimentalTheoretical;
            ProteoformComparison      comparison36 = ProteoformComparison.ExperimentalTheoretical;
            ProteoformComparison      comparison47 = ProteoformComparison.ExperimentalTheoretical;
            TheoreticalProteoform     pf5          = ConstructorsForTesting.make_a_theoretical();
            TheoreticalProteoform     pf6          = ConstructorsForTesting.make_a_theoretical();
            TheoreticalProteoform     pf7          = ConstructorsForTesting.make_a_theoretical();
            TheoreticalProteoform     pf8          = ConstructorsForTesting.make_a_theoretical();
            ProteoformRelation        pr1          = new ProteoformRelation(pf1, pf5, comparison14, 0, TestContext.CurrentContext.TestDirectory);
            ProteoformRelation        pr2          = new ProteoformRelation(pf2, pf6, comparison25, 0, TestContext.CurrentContext.TestDirectory);
            ProteoformRelation        pr3          = new ProteoformRelation(pf3, pf7, comparison36, 1, TestContext.CurrentContext.TestDirectory);
            ProteoformRelation        pr4          = new ProteoformRelation(pf4, pf8, comparison47, 1, TestContext.CurrentContext.TestDirectory);
            List <ProteoformRelation> prs          = new List <ProteoformRelation> {
                pr1, pr2, pr3, pr4
            };

            foreach (ProteoformRelation pr in prs)
            {
                pr.set_nearby_group(prs, prs.Select(r => r.InstanceId).ToList());
            }
            test_community.accept_deltaMass_peaks(prs, new List <ProteoformRelation>());
            Assert.AreEqual(2, Sweet.lollipop.et_peaks.Count);

            //Shift the peaks, which shifts all of the proteoforms
            DeltaMassPeak d2 = Sweet.lollipop.et_peaks[1];

            d2.mass_shifter = "-1";
            Sweet.shift_peak_action(d2);
            d2.mass_shifter = null;
            using (StreamWriter file = new StreamWriter(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml")))
                file.WriteLine(Sweet.save_method());
            Sweet.open_method(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"), string.Join(Environment.NewLine, File.ReadAllLines(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"))), true, out string warning);
            Sweet.mass_shifts_from_presets();
            d2.shift_experimental_masses(Convert.ToInt32(d2.mass_shifter), true);

            foreach (Component c in
                     n3.OfType <NeuCodePair>().Select(n => n.neuCodeLight).
                     Concat(n4.OfType <NeuCodePair>().Select(n => n.neuCodeLight)))
            {
                Assert.AreEqual(-1.0 * Lollipop.MONOISOTOPIC_UNIT_MASS, c.manual_mass_shift);
                Assert.AreEqual(200 - 1.0 * Lollipop.MONOISOTOPIC_UNIT_MASS, c.weighted_monoisotopic_mass);
            }

            foreach (Component c in
                     n3.OfType <NeuCodePair>().Select(n => n.neuCodeHeavy).
                     Concat(n4.OfType <NeuCodePair>().Select(n => n.neuCodeHeavy)))
            {
                Assert.AreEqual(-1.0 * Lollipop.MONOISOTOPIC_UNIT_MASS, c.manual_mass_shift);
                Assert.AreEqual(200 + TestExperimentalProteoform.starter_lysine_count * Lollipop.NEUCODE_LYSINE_MASS_SHIFT - 1.0 * Lollipop.MONOISOTOPIC_UNIT_MASS, c.weighted_monoisotopic_mass);
            }
        }
예제 #7
0
        public void test_accept_from_presets()
        {
            Sweet.lollipop = new Lollipop();
            ProteoformCommunity test_community = new ProteoformCommunity();

            Sweet.lollipop.target_proteoform_community = test_community;

            Sweet.lollipop.theoretical_database.uniprotModifications = new Dictionary <string, List <Modification> >
            {
                { "unmodified", new List <Modification>()
                  {
                      ConstructorsForTesting.get_modWithMass("unmodified", 0)
                  } }
            };

            //Testing the acceptance of peaks. The FDR is tested above, so I'm not going to work with that here.
            //Four proteoforms, three relations (linear), middle one isn't accepted; should give 2 families
            Sweet.lollipop.min_peak_count_ee = 2;
            ExperimentalProteoform pf3 = ConstructorsForTesting.ExperimentalProteoform("E1");
            ExperimentalProteoform pf4 = ConstructorsForTesting.ExperimentalProteoform("E2");
            ExperimentalProteoform pf5 = ConstructorsForTesting.ExperimentalProteoform("E3");
            ExperimentalProteoform pf6 = ConstructorsForTesting.ExperimentalProteoform("E4");

            ProteoformComparison comparison34 = ProteoformComparison.ExperimentalExperimental;
            ProteoformComparison comparison45 = ProteoformComparison.ExperimentalExperimental;
            ProteoformComparison comparison56 = ProteoformComparison.ExperimentalExperimental;
            ProteoformRelation   pr2          = new ProteoformRelation(pf3, pf4, comparison34, 0, TestContext.CurrentContext.TestDirectory);
            ProteoformRelation   pr3          = new ProteoformRelation(pf4, pf5, comparison45, 0, TestContext.CurrentContext.TestDirectory);
            ProteoformRelation   pr4          = new ProteoformRelation(pf5, pf6, comparison56, 0, TestContext.CurrentContext.TestDirectory);

            //Test display strings
            Assert.AreEqual("E1", pr2.connected_proteoforms[0].accession);
            Assert.AreEqual("E2", pr2.connected_proteoforms[1].accession);

            List <ProteoformRelation> prs2 = new List <ProteoformRelation> {
                pr2, pr3, pr4
            };

            foreach (ProteoformRelation pr in prs2)
            {
                pr.set_nearby_group(prs2, prs2.Select(r => r.InstanceId).ToList());
            }
            Assert.AreEqual(3, pr2.nearby_relations_count);
            Assert.AreEqual(3, pr3.nearby_relations_count);
            Assert.AreEqual(3, pr4.nearby_relations_count);

            Sweet.lollipop.theoretical_database.all_possible_ptmsets = new List <PtmSet> {
                new PtmSet(new List <Ptm> {
                    new Ptm(-1, ConstructorsForTesting.get_modWithMass("unmodified", 0))
                })
            };
            Sweet.lollipop.theoretical_database.possible_ptmset_dictionary = Sweet.lollipop.theoretical_database.make_ptmset_dictionary();
            Sweet.unaccept_peak_action(pr2);
            using (StreamWriter file = new StreamWriter(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml")))
                file.WriteLine(Sweet.save_method());
            Sweet.open_method(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"), string.Join(Environment.NewLine, File.ReadAllLines(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"))), true, out string warning);
            Sweet.lollipop.ee_peaks = test_community.accept_deltaMass_peaks(prs2, new List <ProteoformRelation>());
            Assert.AreEqual(1, Sweet.lollipop.ee_peaks.Count);
            DeltaMassPeak peak = Sweet.lollipop.ee_peaks[0];

            Assert.IsFalse(peak.Accepted); // <-- even though it's above the threshold
            Assert.AreEqual(3, peak.grouped_relations.Count);
            Assert.AreEqual(3, pr2.peak.peak_relation_group_count);
            Assert.AreEqual(0, pr2.peak.DeltaMass);
            Assert.AreEqual("[unmodified]", peak.possiblePeakAssignments_string);

            //Test that the relations in the peak are added to each of the proteoforms referenced in the peak
            Assert.True(pf3.relationships.Contains(pr2));
            Assert.True(pf4.relationships.Contains(pr2) && pf4.relationships.Contains(pr3));
            Assert.True(pf5.relationships.Contains(pr3) && pf5.relationships.Contains(pr4));
        }
예제 #8
0
        public void restore_lollipop_settings()
        {
            Lollipop      defaults = new Lollipop();
            StringBuilder builder  = Sweet.save_method();

            foreach (PropertyInfo property in typeof(Lollipop).GetProperties())
            {
                if (property.PropertyType == typeof(int))
                {
                    property.SetValue(null, Convert.ToInt32(property.GetValue(null)) + 1);
                    Assert.AreEqual(Convert.ToInt32(property.GetValue(defaults)) + 1, Convert.ToInt32(property.GetValue(null))); //the int values were changed in the current program
                }
                else if (property.PropertyType == typeof(double))
                {
                    property.SetValue(null, Convert.ToDouble(property.GetValue(null)) + 1);
                    Assert.AreEqual(Convert.ToDouble(property.GetValue(defaults)) + 1, Convert.ToDouble(property.GetValue(null))); //the double values were changed in the current program
                }
                else if (property.PropertyType == typeof(string))
                {
                    property.SetValue(null, property.GetValue(null).ToString() + "hello");
                    Assert.AreEqual(property.GetValue(defaults).ToString() + "hello", Convert.ToDouble(property.GetValue(null)).ToString()); //the string values were changed in the current program
                }
                else if (property.PropertyType == typeof(decimal))
                {
                    property.SetValue(null, Convert.ToDecimal(property.GetValue(null)) + 1);
                    Assert.AreEqual(Convert.ToDecimal(property.GetValue(defaults)) + 1, Convert.ToDecimal(property.GetValue(null))); //the decimal value were changed in the current program
                }
                else if (property.PropertyType == typeof(bool))
                {
                    property.SetValue(null, !Convert.ToBoolean(property.GetValue(null)));
                    Assert.AreEqual(!Convert.ToBoolean(property.GetValue(defaults)), Convert.ToBoolean(property.GetValue(null))); //the bool value were changed in the current program
                }
                else
                {
                    continue;
                }
            }

            Sweet.open_method("", builder.ToString(), false, out string warning);
            foreach (PropertyInfo property in typeof(Lollipop).GetProperties())
            {
                if (property.PropertyType == typeof(int))
                {
                    Assert.AreEqual(Convert.ToInt32(property.GetValue(defaults)), Convert.ToInt32(property.GetValue(null))); //the int values were changed back
                }
                else if (property.PropertyType == typeof(double))
                {
                    Assert.AreEqual(Convert.ToDouble(property.GetValue(defaults)), Convert.ToDouble(property.GetValue(null))); //the double values were changed back
                }
                else if (property.PropertyType == typeof(string))
                {
                    Assert.AreEqual(property.GetValue(defaults).ToString(), Convert.ToDouble(property.GetValue(null)).ToString()); //the string values were changed back
                }
                else if (property.PropertyType == typeof(decimal))
                {
                    Assert.AreEqual(Convert.ToDecimal(property.GetValue(defaults)), Convert.ToDecimal(property.GetValue(null))); //the decimal value were changed back
                }
                else if (property.PropertyType == typeof(bool))
                {
                    Assert.AreEqual(Convert.ToBoolean(property.GetValue(defaults)), Convert.ToBoolean(property.GetValue(null))); //the bool value were changed back
                }
                else
                {
                    continue;
                }
            }
        }