public void load_save_unlocalized()
        {
            Lollipop.enter_uniprot_ptmlist(TestContext.CurrentContext.TestDirectory);
            string uniprotPtmlist = Sweet.lollipop.input_files.FirstOrDefault(f => f.purpose == Purpose.PtmList).complete_path;

            TheoreticalProteoformDatabase tpd = new TheoreticalProteoformDatabase();

            tpd.ready_to_make_database(TestContext.CurrentContext.TestDirectory);
            List <Modification> mods = PtmListLoader.ReadModsFromFile(uniprotPtmlist, out List <(Modification, string)> filteredModificationsWithWarnings).ToList();

            foreach (Modification m in mods)
            {
                if (!Sweet.lollipop.modification_ranks.TryGetValue((double)m.MonoisotopicMass, out int x))
                {
                    Sweet.lollipop.modification_ranks.Add((double)m.MonoisotopicMass, -1);
                }
            }
            tpd.unlocalized_lookup = tpd.make_unlocalized_lookup(mods);
            tpd.load_unlocalized_names(Path.Combine(TestContext.CurrentContext.TestDirectory, "Mods", "stored_mods.modnames"));
            tpd.save_unlocalized_names(Path.Combine(TestContext.CurrentContext.TestDirectory, "Mods", "fake_stored_mods.modnames"));
            Modification firstAcetyl = mods.FirstOrDefault(x => x.OriginalId.StartsWith("N-acetyl"));

            Assert.AreNotEqual(firstAcetyl.OriginalId, tpd.unlocalized_lookup[firstAcetyl].id);

            //Test amending
            mods.AddRange(PtmListLoader.ReadModsFromFile(Path.Combine(TestContext.CurrentContext.TestDirectory, "Mods", "intact_mods.txt"), out filteredModificationsWithWarnings).OfType <Modification>());
            Sweet.lollipop.modification_ranks = mods.DistinctBy(m => m.MonoisotopicMass).ToDictionary(m => (double)m.MonoisotopicMass, m => - 1);
            tpd.unlocalized_lookup            = tpd.make_unlocalized_lookup(mods.OfType <Modification>());
            tpd.amend_unlocalized_names(Path.Combine(TestContext.CurrentContext.TestDirectory, "Mods", "fake_stored_mods.modnames"));
        }
 public void load_uniprot_ptmlist()
 {
     Sweet.lollipop = new Lollipop();
     Lollipop.enter_uniprot_ptmlist(TestContext.CurrentContext.TestDirectory);
     Assert.IsTrue(Sweet.lollipop.input_files.Any(f => f.purpose == Purpose.PtmList));
     Sweet.lollipop = new Lollipop();
 }
 private void btn_downloadUniProtPtmList_Click(object sender, EventArgs e)
 {
     Lollipop.enter_uniprot_ptmlist(Environment.CurrentDirectory);
     DisplayUtility.FillDataGridView(dgv_loadFiles, Sweet.lollipop.get_files(Sweet.lollipop.input_files, Lollipop.file_types[cmb_loadTable.SelectedIndex]).Select(f => new DisplayInputFile(f)));
     DisplayInputFile.FormatInputFileTable(dgv_loadFiles, Lollipop.file_types[cmb_loadTable.SelectedIndex]);
     btn_downloadUniProtPtmList.IsEnabled = false;
     SetMakeDatabaseButton();
 }
        public void testProcessRawComponents()
        {
            Lollipop.correctionFactors = null;
            Lollipop.raw_experimental_components.Clear(); //for if neucode test is run first
            Func <string, IEnumerable <Component> > componentReader = c => new ExcelReader().read_components_from_xlsx(c, Lollipop.correctionFactors);

            Lollipop.deconResultsFileNames = new System.ComponentModel.BindingList <string>();
            Lollipop.deconResultsFileNames.Add("UnitTestFiles\\noisy.xlsx");
            Lollipop.neucode_labeled = true;
            Lollipop.process_raw_components(componentReader);

            Assert.AreEqual(224, Lollipop.raw_experimental_components.Count);
        }
Beispiel #5
0
        public static void Main(string[] args)
        {
            Candy     candy     = new Candy(2.2, "ya", 7.4);
            Lollipop  lollipop  = new Lollipop(2.2, "me", 5.5, 1.1, "good");
            Chocolate chocolate = new Chocolate(2.1, "opl", 0.11, "milk", true, "quad");
            //Gift gift = new Gift(new Candy[]{new Candy(1.1,"roflyan",2.1),new Lollipop(2,"asd",2.3,4.3,"der"), });
            Gift gift = new Gift();

            gift.Add(candy);
            gift.Add(lollipop);
            gift.Add(chocolate);
            Sort.Bubble(gift);
            Console.WriteLine(gift);
        }
        public void restore_lollipop_settings()
        {
            Lollipop      defaults = new Lollipop();
            StringBuilder builder  = SaveState.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;
                }
            }

            SaveState.open_method(builder.ToString());
            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;
                }
            }
        }
Beispiel #7
0
        public Stopwatch full_run()
        {
            forms[1].ClearListsTablesFigures(true); // clear forms following load deconvolution results

            MessageBoxResult d3 = MessageBox.Show("Use presets for this Full Run?", "Full Run", MessageBoxButton.YesNoCancel);

            if (d3 == MessageBoxResult.Yes)
            {
                bool?dr = methodFileOpen.ShowDialog();
                if (dr == true)
                {
                    string           filepath = methodFileOpen.FileName;
                    MessageBoxResult d4       = MessageBox.Show("Add files at the listed paths if they still exist?", "Full Run", MessageBoxButton.YesNoCancel);
                    if (d4 == MessageBoxResult.Cancel)
                    {
                        return(null);
                    }

                    if (!open_method(filepath, File.ReadAllLines(filepath), d4 == MessageBoxResult.Yes))
                    {
                        return(null);
                    }
                    ;
                }
                else if (dr == false)
                {
                    return(null);
                }
            }
            else if (d3 == MessageBoxResult.Cancel)
            {
                return(null);
            }

            loadResults.FillTablesAndCharts(); // updates the filelists in form

            // Check that there are input files
            if (Sweet.lollipop.input_files.Count == 0)
            {
                MessageBox.Show("Please load in deconvolution result files in order to use load and run.", "Full Run");
                return(null);
            }

            // Check that theoretical database(s) are present
            if (!Sweet.lollipop.theoretical_database.ready_to_make_database(Environment.CurrentDirectory))
            {
                if (Sweet.lollipop.get_files(Sweet.lollipop.input_files, Purpose.ProteinDatabase).Count() <= 0)
                {
                    MessageBox.Show("Please list at least one protein database.", "Full Run");
                    return(null);
                }
                else
                {
                    MessageBoxResult d1 = MessageBox.Show("No PTM list is listed.\n\nWill now download the default PTM list from UniProt and use it for the Full Run.", "Full Run", MessageBoxButton.OKCancel);
                    if (d1 == MessageBoxResult.OK)
                    {
                        Lollipop.enter_uniprot_ptmlist(Environment.CurrentDirectory);
                        if (loadResults.ReadyToRunTheGamut())
                        {
                            loadResults.RunTheGamut(true); // updates the dgvs
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            // Option to choose a result folder
            if (Sweet.lollipop.results_folder == "")
            {
                MessageBoxResult d2 = MessageBox.Show("Choose a results folder for this Full Run?", "Full Run", MessageBoxButton.YesNoCancel);
                if (d2 == MessageBoxResult.Yes)
                {
                    System.Windows.Forms.FolderBrowserDialog folderBrowser = new System.Windows.Forms.FolderBrowserDialog();
                    System.Windows.Forms.DialogResult        dr            = folderBrowser.ShowDialog();
                    if (dr == System.Windows.Forms.DialogResult.OK)
                    {
                        string temp_folder_path = folderBrowser.SelectedPath;
                        Sweet.lollipop.results_folder = temp_folder_path;
                        loadResults.InitializeParameterSet(); // updates the textbox
                    }
                    else if (dr == System.Windows.Forms.DialogResult.Cancel)
                    {
                        return(null);
                    }
                }
                else if (d2 == MessageBoxResult.Cancel)
                {
                    return(null);
                }
            }
            else
            {
                MessageBoxResult d2 = MessageBox.Show("Would you like to save results of this Full Run to " + Sweet.lollipop.results_folder + "?", "Full Run", MessageBoxButton.YesNoCancel);
                if (d2 == MessageBoxResult.No)
                {
                    Sweet.lollipop.results_folder = "";
                }
                else if (d2 == MessageBoxResult.Cancel)
                {
                    return(null);
                }
            }

            // Run the program
            Mouse.OverrideCursor = Cursors.Wait;
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            foreach (ISweetForm sweet in forms)
            {
                if (sweet.ReadyToRunTheGamut())
                {
                    sweet.RunTheGamut(true);
                }
            }

            // Save the results
            resultsSummary.InitializeParameterSet();
            if (Sweet.lollipop.results_folder != "")
            {
                string timestamp = Sweet.time_stamp();
                ResultsSummaryGenerator.save_all(Sweet.lollipop.results_folder, timestamp, resultsSummary.get_go_analysis(), resultsSummary.get_tusher_analysis());
                //save_all_plots(Sweet.lollipop.results_folder, timestamp);
                using (StreamWriter file = new StreamWriter(Path.Combine(Sweet.lollipop.results_folder, "presets_" + timestamp + ".xml")))
                    file.WriteLine(Sweet.save_method());
            }
            List <string> warning_methods = new List <string>()
            {
                "Warning:"
            };

            if (BottomUpReader.bottom_up_PTMs_not_in_dictionary.Count() > 0)
            {
                warning_methods.Add("The following PTMs in the .mzid file were not matched with any PTMs in the theoretical database: ");
                warning_methods.Add(string.Join(", ", BottomUpReader.bottom_up_PTMs_not_in_dictionary.Distinct()));
            }
            if (Sweet.lollipop.topdownReader.bad_topdown_ptms.Count > 0)
            {
                warning_methods.Add("Top-down proteoforms with the following modifications were not matched to a modification in the theoretical PTM list: ");
                warning_methods.Add(string.Join(", ", Sweet.lollipop.topdownReader.bad_topdown_ptms.Distinct()));
            }
            if (Sweet.lollipop.topdown_proteoforms.Count(t => !t.accepted) > 0)
            {
                warning_methods.Add("Top-down proteoforms with the following accessions were not matched to a theoretical proteoform in the theoretical database: ");
                warning_methods.Add(string.Join(", ", Sweet.lollipop.topdown_proteoforms.Where(t => !t.accepted).Select(t => t.accession.Split('_')[0]).Distinct()));
            }
            if (warning_methods.Count > 1)
            {
                MessageBox.Show(string.Join("\n\n", warning_methods));
            }
            //Program ran successfully
            stopwatch.Stop();
            Mouse.OverrideCursor = null;
            return(stopwatch);
        }