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();
 }
Пример #4
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);
        }