Пример #1
0
        private void mnuRemove_Click(object sender, EventArgs e)
        {
            BioSeqRemove frm = new BioSeqRemove();
            DialogResult rc  = frm.ShowDialog();

            if (rc == DialogResult.OK) // then the config has the specs
            {
                Cursor.Current = Cursors.WaitCursor;
                //int ret = SeqDBHelper.RemoveSample(); // Parameters are in appsettings.
                WSLProxyResponse WSLResponse = ServiceCallHelper.RemoveSample(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig()); // Parameters are in appsettings.
                ServiceCallHelper.LoadConfig(AppConfigHelper.LoggedOnUser);                                                                // To retrieve StandardOutput and LastError.
                Cursor.Current = Cursors.Default;
                if (WSLResponse.ExitCode == 0)
                {
                    MessageBox.Show(AppConfigHelper.RemoveSampleID() + " successfully removed.", "Success", MessageBoxButtons.OK);
                    AppConfigHelper.RemoveSample(string.Empty); // So we don't prompt for it again.
                    ReloadSampleIDs();                          // Reload list without sample ID.
                }
                else
                {
                    MessageBox.Show("Remove completed with error code " + WSLResponse.ExitCode.ToString() + "." + Environment.NewLine + Environment.NewLine +
                                    AppConfigHelper.StandardOutput + Environment.NewLine + AppConfigHelper.LastError, "Error", MessageBoxButtons.OK);
                }
            }
        }
Пример #2
0
        private string LIMSListKey;                       // Current LIMSList selection.

        public BioSeqLIMSEdit()
        {
            InitializeComponent();

            btnOK.Enabled    = false;
            btnApply.Enabled = false;

            Cursor.Current = Cursors.WaitCursor;
            LIMSBaseList   = ServiceCallHelper.ReadLIMSData(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig());
            LIMSList       = new Dictionary <string, string>();
            foreach (string key in LIMSBaseList.Keys)
            {
                LIMSList.Add(LIMSBaseList[key], key);
            }

            lstSampleIDs.Items.Clear();
            lstSampleIDs.Items.AddRange(ServiceCallHelper.SampleIDs(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig()).ToArray());
            if (lstSampleIDs.Items.Count > 0)
            {
                lstSampleIDs.SetSelected(0, true);

                lstSampleIDs.ItemCheck -= lstSampleIDs_ItemCheck;
                for (int i = 0; i < lstSampleIDs.Items.Count; i++)
                {
                    lstSampleIDs.SetItemChecked(i, LIMSList.ContainsKey(lstSampleIDs.Items[i].ToString()));
                }
                lstSampleIDs.ItemCheck += lstSampleIDs_ItemCheck;
            }
            Cursor.Current = Cursors.Default;
        }
Пример #3
0
        private bool ValidFastqFiles(string path, bool IsServerPath)
        {
            int fCount = ServiceCallHelper.TraverseTree(path, IsServerPath, "fastq");

            if (fCount == 0)
            {
                MessageBox.Show("There are no *.fastq files in the " + path + " folder.", "Wrong folder", MessageBoxButtons.OK);
                return(false);
            }

            // Make sure it is not already in the list.
            List <string> querySamples = new List <string>();

            for (int i = 0; i < lstSamples.Items.Count; i++)
            {
                querySamples.Add(lstSamples.Items[i].ToString());
            }
            if (querySamples.Contains(path))
            {
                MessageBox.Show(path + " has already been selected.", "Duplicate selection", MessageBoxButtons.OK);
                return(false);
            }

            lstSamples.SetItemChecked(lstSamples.Items.Add(path), true);
            EnableOK();
            return(true);
        }
Пример #4
0
        private int ValidFastaFiles(string root, bool IsServerPath)
        {
            if (!DirectoryHelper.DirectoryExists(root))
            {
                MessageBox.Show("The " + root + " folder does not exist.", "Wrong folder", MessageBoxButtons.OK);
                return(0);
            }

            string[] subDirs = DirectoryHelper.GetDirectories(root);
            int      fCount  = 0;

            foreach (string subfolderName in subDirs)
            {
                fCount += ServiceCallHelper.TraverseTree(subfolderName, IsServerPath, "fasta");
            }

            if (fCount == 0)
            {
                MessageBox.Show("There are no *.fasta files in the sub-folders of the " + root + " folder.", "Wrong folder", MessageBoxButtons.OK);
                return(fCount);
            }

            EnableOK();
            return(fCount);
        }
Пример #5
0
        private void backgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            BioSeqTask       task        = AppConfigHelper.TaskOfID(AppConfigHelper.LastTaskID);
            WSLProxyResponse WSLResponse = null;

            switch (task.TaskType)
            {
            case "Centrifuge":
                WSLResponse = ServiceCallHelper.Centrifuge(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig());
                break;

            case "Salmonella":
                WSLResponse = ServiceCallHelper.Salmonella(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig());
                break;

            case "VFabricate":
                WSLResponse = ServiceCallHelper.VFabricate(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig());
                break;

            case "Search":
                WSLResponse = ServiceCallHelper.SearchSample(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig());
                break;

            case "Kraken2":
                WSLResponse = ServiceCallHelper.Kraken2(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig());
                break;

            case "Quast":
                WSLResponse = ServiceCallHelper.Quast(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig());
                break;

            case "BBMap":
                WSLResponse = ServiceCallHelper.BBMap(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig());
                break;

            case "BuildTree":
                WSLResponse = ServiceCallHelper.BuildTree(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig());
                break;

            case "Assemble":
                WSLResponse = ServiceCallHelper.Assemble(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig(), AppConfigHelper.QuerySampleConfig());
                break;

            case "InfluenzaA":
                WSLResponse = ServiceCallHelper.InfluenzaA(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig());
                break;

            case "Nextstrain":
                WSLResponse = ServiceCallHelper.Nextstrain(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig());
                break;
            }

            task.LastError      = WSLResponse.StandardError;
            task.StandardOutput = WSLResponse.StandardOutput;
            e.Result            = new List <object>()
            {
                WSLResponse.ExitCode, task
            };
        }
Пример #6
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            // Copy LIMSList to LIMSBaseList and write to <dbname>_LIMS.fasta.
            //LIMSBaseList = LIMSList.ToDictionary(entry => entry.Key, entry => entry.Value);

            LIMSBaseList = new Dictionary <string, string>();
            foreach (string key in LIMSList.Keys)
            {
                LIMSBaseList.Add(LIMSList[key], key);
            }
            ServiceCallHelper.WriteLIMSData(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig(), LIMSBaseList);
            btnApply.Enabled        = btnOK.Enabled = AnyChanges(); // There should not be any.
            lstSampleIDs.ItemCheck -= lstSampleIDs_ItemCheck;
            lstSampleIDs.SetItemChecked(lstSampleIDs.SelectedIndex, true);
            lstSampleIDs.ItemCheck += lstSampleIDs_ItemCheck;
        }
        private string GetCentrifugeDBName()
        {
            string lblCentrifugeDBName = "Centrifuge database name: ";

            if (!string.IsNullOrEmpty(txtCentrifugePath.Text.Trim()))
            {
                string centrifugeDBName = ServiceCallHelper.CentrifugeDatabaseName(txtCentrifugePath.Text);
                if (!string.IsNullOrEmpty(centrifugeDBName))
                {
                    lblCentrifugeDBName += centrifugeDBName;
                }
                else
                {
                    lblCentrifugeDBName = txtCentrifugePath.Text + " is not a valid Centrifuge database path.";
                }
            }
            return(lblCentrifugeDBName);
        }
Пример #8
0
        private void mnuInsert_Click(object sender, EventArgs e)
        {
            BioSeqInsert frm = new BioSeqInsert(lstSampleIDs.Items);
            DialogResult rc  = frm.ShowDialog();

            if (rc == DialogResult.OK) // then the config has the specs
            {
                Cursor.Current = Cursors.WaitCursor;
                int    ret;
                string function = "Replace";

                // If the InsertInputPath is local, copy it to UserFolder on the server.
                if (AppConfigHelper.InsertInputPath().StartsWith("[L]"))
                {
                    DirectoryHelper.FileCopy(AppConfigHelper.InsertInputPath(), "[S]" + AppConfigHelper.UserFolder(), true);
                }

                WSLProxyResponse WSLResponse;
                if (AppConfigHelper.InsertSampleReplace)
                {
                    WSLResponse = ServiceCallHelper.ReplaceSample(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig()); // Parameters are in appsettings.
                }
                else // Go ahead without prompting.
                {
                    function    = "Insert";
                    WSLResponse = ServiceCallHelper.InsertSample(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig()); // Parameters are in appsettings.
                }
                ServiceCallHelper.LoadConfig(AppConfigHelper.LoggedOnUser);                                                   // To retrieve StandardOutput and LastError.
                Cursor.Current = Cursors.Default;
                if (WSLResponse.ExitCode == 0)
                {
                    MessageBox.Show(AppConfigHelper.StandardOutput + Environment.NewLine + function + " completed successfully.", "Success", MessageBoxButtons.OK);
                    ReloadSampleIDs(); // Reload list with new sample ID.
                }
                else
                {
                    MessageBox.Show(function + " completed with error code " + WSLResponse.ExitCode.ToString() + "." + Environment.NewLine + Environment.NewLine +
                                    AppConfigHelper.StandardOutput + Environment.NewLine + AppConfigHelper.LastError, "Error", MessageBoxButtons.OK);
                }
            }
        }
Пример #9
0
        private static void InitConfig()
        {
            ServiceCallHelper.LoadConfig(string.Empty); // Loads the global appsettings.json.

            //// Start by copying the local copy of <loggedOnUser>_appsettings.json to the server.
            //DirectoryHelper.FileCopy("[L]" + AppConfigHelper.executablePath + "\\" + AppConfigHelper.LoggedOnUser + "_appsettings.json",
            //                                                                      "[S]" + AppConfigHelper.PathToServerAppsettings, true);
            if (!IsServiceClass.IsService)
            {
                if (!File.Exists(DirectoryHelper.CleanPath(AppConfigHelper.NormalizePathToWindows(AppConfigHelper.PathToWSL()))))
                {
                    // Learned that wsl.exe cannot run from \Windows\System32 (file not found).
                    MessageBox.Show(DirectoryHelper.CleanPath(AppConfigHelper.PathToWSL()) + " (" +
                                    DirectoryHelper.CleanPath(AppConfigHelper.NormalizePathToWindows(AppConfigHelper.PathToWSL())) +
                                    ") does not exist. Correct PathToWSL in appsettings.json before continuing.", "ERROR", MessageBoxButtons.OK);
                }

                string path = DirectoryHelper.CleanPath(AppConfigHelper.NormalizePathToWindows(AppConfigHelper.PathToSeqDB()));
                if (!File.Exists(path))
                {
                    // Learned that although Ubuntu prefix is \\wsl on my machine, it is \\wsl$ on WIMMER.
                    MessageBox.Show(DirectoryHelper.CleanPath(AppConfigHelper.PathToSeqDB()) + " (" +
                                    DirectoryHelper.CleanPath(AppConfigHelper.NormalizePathToWindows(AppConfigHelper.PathToSeqDB())) +
                                    ") does not exist. " + Environment.NewLine + "Correct PathToSeqDB in appsettings.json before continuing, or" +
                                    Environment.NewLine + "issue 'wsl --shutdown' in PowerShell.", "ERROR", MessageBoxButtons.OK);
                }
            }
            else // IsService
            {
                try
                {
                    AppConfigHelper.seqdbConfigGlobal.ServerDriveList = ServiceCallHelper.DriveList();
                    ServiceCallHelper.SaveConfigGlobal();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to obtain the drive list from the server." + Environment.NewLine + ex.ToString(), "ERROR", MessageBoxButtons.OK);
                }
            }
        }
Пример #10
0
        private void mnuRestore_Click(object sender, EventArgs e)
        {
            BioSeqRestore frm = new BioSeqRestore(txtVersions.Text.Trim());
            DialogResult  rc  = frm.ShowDialog();

            if (rc == DialogResult.OK) // then the config has the specs
            {
                Cursor.Current = Cursors.WaitCursor;
                WSLProxyResponse WSLResponse = ServiceCallHelper.RestoreDatabase(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig()); // Parameters are in appsettings.
                ServiceCallHelper.LoadConfig(AppConfigHelper.LoggedOnUser);                                                                   // To retrieve StandardOutput and LastError.
                Cursor.Current = Cursors.Default;
                if (WSLResponse.ExitCode == 0)
                {
                    ReloadSampleIDs(); // Reload list without sample ID.
                    MessageBox.Show(AppConfigHelper.StandardOutput + Environment.NewLine + "Restore successfully completed.", "Success", MessageBoxButtons.OK);
                }
                else
                {
                    MessageBox.Show("Restore completed with error code " + WSLResponse.ExitCode.ToString() + "." + Environment.NewLine + Environment.NewLine +
                                    AppConfigHelper.StandardOutput + Environment.NewLine + AppConfigHelper.LastError, "Error", MessageBoxButtons.OK);
                }
            }
        }
Пример #11
0
        private void btnDeleteDB_Click(object sender, EventArgs e)
        {
            // Delete the currently selected database and associated archive database.
            ConfirmDBDelete.MainInstruction = "You are about to completely delete " + txtDB.Text + " in " + txtPath.Text;
            if (txtVersions.Text.Length > 0)
            {
                ConfirmDBDelete.MainInstruction = ConfirmDBDelete.MainInstruction + ", as well as the associated archival database";
            }
            ConfirmDBDelete.MainInstruction = ConfirmDBDelete.MainInstruction + ". Do you want to continue?";

            TaskDialogButton button = ConfirmDBDelete.ShowDialog(this);

            if (button == btnDeleteDBNo)
            {
                return;
            }

            Cursor.Current = Cursors.WaitCursor;
            int rc = ServiceCallHelper.DeleteDB(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig());

            if (rc == 0)
            {
                MessageBox.Show("Database successfully deleted.", "Success", MessageBoxButtons.OK);
            }
            else
            {
                MessageBox.Show("Failed to delete database. Error code " + rc.ToString(), "ERROR", MessageBoxButtons.OK);
            }

            cmbUser.SelectedIndexChanged -= cmbUser_SelectedIndexChanged;
            ServiceCallHelper.LoadConfig(string.Empty);
            ServiceCallHelper.LoadConfig(AppConfigHelper.LoggedOnUser);
            AppConfigHelper.seqdbConfig.LastDBSelected = string.Empty;
            Initialize();
            cmbUser.SelectedIndexChanged += cmbUser_SelectedIndexChanged;
            Cursor.Current = Cursors.Default;
        }
Пример #12
0
        private void mnuExtract_Click(object sender, EventArgs e)
        {
            BioSeqExtract frm = new BioSeqExtract();
            DialogResult  rc  = frm.ShowDialog();

            if (rc == DialogResult.OK) // then the config has the specs
            {
                Cursor.Current = Cursors.WaitCursor;
                // Parameters are in appsettings.
                WSLProxyResponse WSLResponse = ServiceCallHelper.Extract(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig()); // Parameters are in appsettings.
                ServiceCallHelper.LoadConfig(AppConfigHelper.LoggedOnUser);                                                           // To retrieve StandardOutput and LastError.
                Cursor.Current = Cursors.Default;
                if (WSLResponse.ExitCode == 0)
                {
                    MessageBox.Show(AppConfigHelper.StandardOutput + Environment.NewLine + "Extract completed successfully. Result is in " +
                                    AppConfigHelper.ExtractOutputPath() + "\\" + AppConfigHelper.ExtractSampleID() + ".fasta", "Success", MessageBoxButtons.OK);
                }
                else
                {
                    MessageBox.Show("Extract completed with error code " + WSLResponse.ExitCode.ToString() + "." + Environment.NewLine + Environment.NewLine +
                                    AppConfigHelper.StandardOutput + Environment.NewLine + AppConfigHelper.LastError, "Error", MessageBoxButtons.OK);
                }
            }
        }
Пример #13
0
        private void mnuBackup_Click(object sender, EventArgs e)
        {
            BioSeqBackup frm = new BioSeqBackup();
            DialogResult rc  = frm.ShowDialog();

            if (rc == DialogResult.OK) // then the config has the specs
            {
                Cursor.Current = Cursors.WaitCursor;
                WSLProxyResponse WSLResponse = ServiceCallHelper.BackupDatabase(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig()); // Parameters are in appsettings.
                ServiceCallHelper.LoadConfig(AppConfigHelper.LoggedOnUser);                                                                  // To retrieve StandardOutput and LastError.
                Cursor.Current = Cursors.Default;
                if (WSLResponse.ExitCode == 0)
                {
                    RefreshVersionInformation(AppConfigHelper.seqdbConfig.seqDBs[AppConfigHelper.seqdbConfig.LastDBSelected]);
                    MessageBox.Show(AppConfigHelper.StandardOutput + Environment.NewLine + "Backup successfully completed.", "Success", MessageBoxButtons.OK);
                    // Refresh backup version display.
                }
                else
                {
                    MessageBox.Show("Backup completed with error code " + WSLResponse.ExitCode.ToString() + "." + Environment.NewLine + Environment.NewLine +
                                    AppConfigHelper.StandardOutput + Environment.NewLine + AppConfigHelper.LastError, "Error", MessageBoxButtons.OK);
                }
            }
        }
Пример #14
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            // TODO: Should check the validity of the paths here.
            AppConfigHelper.OutputPath(analysis, txtOutputPath.Text.Trim());
            AppConfigHelper.SampleChecked(analysis, radSample.Checked);
            AppConfigHelper.TaskMemo = txtMemo.Text.Trim();

            if (analysis == "Kraken2")
            {
                AppConfigHelper.Kraken2UseFastq = radUseFastq.Checked;
                if (radUseFastq.Checked)
                {
                    AppConfigHelper.Kraken2FastqPath = txtInputPath.Text.Trim();
                }
            }

            if (analysis == "BBMap")
            {
                AppConfigHelper.BBMapFastqPath(analysis, txtFastqPath.Text.Trim());
                string fastqPath = txtFastqPath.Text.Trim();
                if (IsServiceClass.IsService)
                {
                    if (fastqPath.StartsWith("[L]")) // Not extract sample ID
                    {
                        ServiceCallHelper.ResetFastqFolder(AppConfigHelper.LoggedOnUser);
                        string[] files = Directory.GetFiles(DirectoryHelper.CleanPath(fastqPath), "*.fastq", SearchOption.TopDirectoryOnly);
                        foreach (string file in files)
                        {
                            DirectoryHelper.FileCopy("[L]" + file, "[S]" + AppConfigHelper.UserFolder() + "FastqFiles", true);
                        }
                    }
                }
            }

            if (analysis == "VFabricate")
            {
                AppConfigHelper.VFabricateGeneXref = txtFastqPath.Text.Trim();
            }

            if (analysis == "Search")
            {
                if (!float.TryParse(txtCutoff.Text, out float cutoff))
                {
                    MessageBox.Show("A cutoff number between 0 and 1 is required.", "Missing cutoff", MessageBoxButtons.OK);
                    txtCutoff.Focus();
                    DialogResult = DialogResult.None;
                    return;
                }

                if (cutoff < 0.0 || cutoff > 1.0)
                {
                    MessageBox.Show("A cutoff number between 0 and 1 is required.", "Invalid cutoff", MessageBoxButtons.OK);
                    txtCutoff.Focus();
                    DialogResult = DialogResult.None;
                    return;
                }

                if (radContig.Checked && !DirectoryHelper.FileExists(AppConfigHelper.NormalizePathToWindows(txtInputPath.Text)))
                {
                    MessageBox.Show(txtInputPath.Text + " does not exist. Choose a valid input file.", "Invalid input file", MessageBoxButtons.OK);
                    txtInputPath.Focus();
                    DialogResult = DialogResult.None;
                    return;
                }

                if (!DirectoryHelper.DirectoryExists(AppConfigHelper.NormalizePathToWindows(txtOutputPath.Text)))
                {
                    MessageBox.Show(txtOutputPath.Text + " does not exist. Choose a valid output path.", "Invalid output path", MessageBoxButtons.OK);
                    txtOutputPath.Focus();
                    DialogResult = DialogResult.None;
                    return;
                }

                // Update config to reflect selection.
                AppConfigHelper.SearchSample(txtOutputSampleName.Text, txtOutputPath.Text, txtInputPath.Text.Trim(), txtCutoff.Text, txtThreads.Text);
            }

            if (radSample.Checked)
            {
                if (lstSampleIDs.SelectedIndex == -1)
                {
                    MessageBox.Show("Select a sample from the sample list", "ERROR", MessageBoxButtons.OK);
                    return;
                }

                AppConfigHelper.SampleID(analysis, lstSampleIDs.SelectedItem.ToString().Trim());
            }
            else // If the txtInputPath is local, send it to the UserFolder() on the server.
            {
                string inputPath = txtInputPath.Text.Trim();
                if (!radSample.Checked && IsServiceClass.IsService)
                {
                    if (inputPath.StartsWith("[L]")) // Not extract sample ID
                    {
                        DirectoryHelper.FileCopy(inputPath, AppConfigHelper.UserFolder(), true);
                    }
                }

                AppConfigHelper.InputPath(analysis, inputPath);
            }
        }
Пример #15
0
 private void backgroundWorker_SampleIDs_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
 {
     e.Result = ServiceCallHelper.SampleIDs(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig()).ToArray();
 }
Пример #16
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            s_Mutex = new Mutex(true, "BioSeqDB");

            if (!s_Mutex.WaitOne(0, false))
            {
                return;
            }

            Cursor.Current = Cursors.WaitCursor;
            Logger.Initialize(logger);

            UserProfileHelper.GetUserProfile(); // From C:\Temp\Remember.json.

            Properties.Settings.Default.ModelServer = UserProfileHelper.userProfile.ServerIPAddress;
            //MessageBox.Show("ServerIPAddress: " + Properties.Settings.Default.ModelServer, "ERROR", MessageBoxButtons.OK);
            Properties.Settings.Default.Save();

            // Check if BioSeqService is listening.
            string IsClientOnServer = string.Empty;

            try
            {
                IsClientOnServer = ServiceCallHelper.HelloBioSeqDBService();
            }
            catch (Exception ex)
            {
                MessageBox.Show("It appears that the BioSeqDB service is not running on the '" + Properties.Settings.Default.ModelServer +
                                "' server.  Check VPN if running remotely?", "ERROR", MessageBoxButtons.OK);
                return;
            }

            // Check if WSLProxy is listening.
            try
            {
                string message = BioSeqDBModel.Instance.WSLVersion();
            }
            catch (Exception ex)
            {
                MessageBox.Show("It appears that the WSLProxy service is not running on the '" + Properties.Settings.Default.ModelServer +
                                "' server.", "ERROR", MessageBoxButtons.OK);
                Logger.Log.Debug("It appears that the WSLProxy service is not running on the server. Exception\n" + ex.ToString());
                return;
            }

            try
            {
                BioSeqDBLogin frmLogin = new BioSeqDBLogin(IsClientOnServer);
                if (frmLogin.ShowDialog() == DialogResult.OK)
                {
                    Application.Run(new BioSeqUI());
                }
            }
            catch (Exception ex)
            {
                Logger.Log.Debug("Fatal error: " + ex.ToString());
                MessageBox.Show(ex.ToString(), "ERROR", MessageBoxButtons.OK);
            }
        }
Пример #17
0
        private void cmbSeqDB_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbSeqDB.SelectedIndex == 0) // empty = none = reset
            {
                menuStrip1.Enabled  = false;
                btnDeleteDB.Enabled = false;
                txtDB.Text          = txtPath.Text = txtVersions.Text = AppConfigHelper.seqdbConfig.LastDBSelected = string.Empty;
                lblKipper.Visible   = false;
                lstSampleIDs.Items.Clear();
                chkDetailSamples.Enabled = false;
                lstSampleIDs.Enabled     = false;
                AppConfigHelper.SaveConfig();
            }
            else if (cmbSeqDB.SelectedIndex == 1) // New
            {
                BioSeqNewDB  frmNewDB = new BioSeqNewDB();
                DialogResult rc       = frmNewDB.ShowDialog();
                if (rc == DialogResult.OK) // then the config has the specs for the new db to select.
                {
                    Cursor.Current = Cursors.WaitCursor;

                    // If necessary, copy local files to server.
                    string fastaPath = AppConfigHelper.Build_DBInput();
                    if (IsServiceClass.IsService && !string.IsNullOrEmpty(fastaPath))
                    {
                        if (fastaPath.StartsWith("[L]") || !fastaPath.StartsWith("["))
                        {
                            ServiceCallHelper.ResetFastaFolder(AppConfigHelper.LoggedOnUser);
                            string[] folders = Directory.GetDirectories(DirectoryHelper.CleanPath(fastaPath));
                            foreach (string folder in folders)
                            {
                                string[] files = Directory.GetFiles(folder, "*.fasta", SearchOption.TopDirectoryOnly);
                                foreach (string file in files)
                                {
                                    DirectoryHelper.FileCopy("[L]" + file, "[S]" + AppConfigHelper.UserFolder() + "FastaFiles", true);
                                }
                                files = Directory.GetFiles(folder, "*.fna", SearchOption.TopDirectoryOnly);
                                foreach (string file in files)
                                {
                                    DirectoryHelper.FileCopy("[L]" + file, "[S]" + AppConfigHelper.UserFolder() + "FastaFiles", true);
                                }
                                files = Directory.GetFiles(folder, "*.fa", SearchOption.TopDirectoryOnly);
                                foreach (string file in files)
                                {
                                    DirectoryHelper.FileCopy("[L]" + file, "[S]" + AppConfigHelper.UserFolder() + "FastaFiles", true);
                                }
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(AppConfigHelper.BuildTreeWildReference())) // This is the standard genome for the new database.
                    {
                        // Wherever it is, store it temporarily in the UserFolder.
                        DirectoryHelper.FileCopy(AppConfigHelper.BuildTreeWildReference(), "[S]" + AppConfigHelper.UserFolder(), true);
                    }

                    /////////// Call Build_DB in SeqDB.
                    try
                    {
                        ServiceCallHelper.Build_DB(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig());
                    }
                    catch (Exception ex)
                    {
                        Cursor.Current = Cursors.Default;
                        MessageBox.Show("Error: " + ex.ToString(), "ERROR", MessageBoxButtons.OK);
                        return;
                    }

                    if (AppConfigHelper.LastError.Length > 0)
                    {
                        Cursor.Current = Cursors.Default;
                        MessageBox.Show("Error: " + AppConfigHelper.LastError, "ERROR", MessageBoxButtons.OK);
                        return;
                    }

                    if (string.IsNullOrEmpty(AppConfigHelper.BuildTreeDomesticReference))
                    {
                        AppConfigHelper.BuildTreeDomesticReference = AppConfigHelper.BuildTreeWildReference();
                        AppConfigHelper.SaveConfig();
                    }
                    ServiceCallHelper.LoadConfig(AppConfigHelper.LoggedOnUser);
                    PopulateDBDropdownAndSelect();
                    Cursor.Current = Cursors.Default;
                }
            }
            else // a database is selected.
            {
                Cursor.Current = Cursors.WaitCursor;
                AppConfigHelper.seqdbConfig.LastDBSelected = cmbSeqDB.SelectedItem.ToString();
                AppConfigHelper.SaveConfig();

                menuStrip1.Enabled       = true;
                btnDeleteDB.Enabled      = true;
                chkDetailSamples.Enabled = true;
                lstSampleIDs.Enabled     = true;
                txtVersions.Text         = string.Empty;
                lstSampleIDs.Items.Clear();

                SeqDB db = AppConfigHelper.seqdbConfig.seqDBs[AppConfigHelper.seqdbConfig.LastDBSelected];
                txtDB.Text   = db.DBName;
                txtPath.Text = db.DBPath;
                AppConfigHelper.LastError = string.Empty;

                if (SampleIDsBusyFlag || VersionsBusyFlag)
                {
                    MessageBox.Show("Version information and sample IDs are being loaded for previous database. Please select " +
                                    db.DBName + " again.", "Warning", MessageBoxButtons.OK);
                    return;
                }

                // Version information comes from the global config.
                RefreshVersionInformation(AppConfigHelper.seqdbConfigGlobal.seqDBs[AppConfigHelper.seqdbConfig.LastDBSelected]);

                // Also get sample IDs into listbox.
                ReloadSampleIDs();
                Cursor.Current = Cursors.Default;
                if (AppConfigHelper.LastError.Length > 0)
                {
                    MessageBox.Show("Error: " + AppConfigHelper.LastError, "ERROR", MessageBoxButtons.OK);
                }
            }
        }
Пример #18
0
        private void btnFindInputPath_Click(object sender, EventArgs e)
        {
            DialogResult  result;
            string        samplePath = string.Empty;
            List <string> folderList = new List <string>();

            items = new Dictionary <string, string>(); // Start from square one with items in this batch.

            if (IsServiceClass.IsService)
            {
                string path = IsSalmonella ? AppConfigHelper.NormalizePathToWindows(AppConfigHelper.SalmonellaSamplesPath) :
                              AppConfigHelper.NormalizePathToWindows(AppConfigHelper.InfluenzaASamplesPath);

                // We want an actual file, so don't append "\\".
                // Jan-8-2021 No, we want a folder with fastq files in it.
                path += "\\";
                Explorer.frmExplorer = new Explorer(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig(), "Input path to folder containing sample fastq files",
                                                    DirectoryHelper.IsServerPath(path), DirectoryHelper.CleanPath(path),
                                                    "Fastq files (*.fastq)|*.fastq|All files (*.*)|*.*", folderList, AppConfigHelper.UbuntuPrefix());
                Explorer.frmExplorer.ServerOnly = true;
                result = Explorer.frmExplorer.ShowDialog();
                if (result != DialogResult.Cancel)
                {
                    folderList = Explorer.FileNames;
                    samplePath = Explorer.PresentServerPath + Explorer.PresentLocalPath; // One of these is empty.
                }
            }
            else
            {
                VistaOpenFileDialog ofn = new VistaOpenFileDialog();
                if (IsSalmonella ? Directory.Exists(AppConfigHelper.SalmonellaSamplesPath) : Directory.Exists(AppConfigHelper.InfluenzaASamplesPath))
                {
                    ofn.InitialDirectory = ofn.FileName = IsSalmonella ? AppConfigHelper.FileExists(AppConfigHelper.SalmonellaSamplesPath) :
                                                          AppConfigHelper.FileExists(AppConfigHelper.InfluenzaASamplesPath);
                }
                ofn.Title           = "Input path to folder containing sample fastq files";
                ofn.CheckFileExists = true;
                ofn.Multiselect     = false;
                ofn.Filter          = "Fastq files (*.fastq)|*.fastq|All files (*.*)|*.*";

                result     = ofn.ShowDialog();
                samplePath = ofn.FileName;
            }

            if (result != DialogResult.Cancel)
            {
                samplePath = samplePath.Substring(0, samplePath.LastIndexOf("\\") + 1);

                // If the selection already exists, boot it out.
                string msg        = "Folders already selected or having no .fastq files (will be ignored): " + Environment.NewLine;
                bool   isSelected = false;
                if (folderList.Count == 0)
                {
                    foreach (string key in alreadySelected.Keys)
                    {
                        if (alreadySelected[key].Substring(1) == samplePath)
                        {
                            isSelected = true;
                            msg       += samplePath + Environment.NewLine;
                            break;
                        }
                    }

                    if (!isSelected)
                    {
                        int fCount = ServiceCallHelper.TraverseTree(DirectoryHelper.CleanPath(samplePath), true, "fastq");
                        if (fCount == 0)
                        {
                            isSelected = true;
                            msg       += samplePath + Environment.NewLine;
                        }
                    }

                    if (!isSelected)
                    {
                        string path = samplePath.Substring(0, samplePath.Length - 1);
                        path = path.Substring(path.LastIndexOf("\\") + 1);
                        //samplePath = samplePath.Substring(0, samplePath.Length - 1 - path.Length); // Chop off last folder name.
                        currentSampleSelection = path;
                        items.Add(path, samplePath);
                    }
                }
                else
                {
                    foreach (string folder in folderList)
                    {
                        isSelected = false;
                        foreach (string key in alreadySelected.Keys)
                        {
                            if (Path.GetDirectoryName(alreadySelected[key].Substring(1)) == Path.GetDirectoryName(samplePath + folder + "\\"))
                            {
                                isSelected = true;
                                msg       += samplePath + folder + Environment.NewLine;
                                break;
                            }
                        }

                        if (!isSelected)
                        {
                            int fCount = ServiceCallHelper.TraverseTree(DirectoryHelper.CleanPath(samplePath + folder), true, "fastq");
                            if (fCount == 0)
                            {
                                isSelected = true;
                                msg       += samplePath + folder + Environment.NewLine;
                            }
                        }

                        if (!isSelected)
                        {
                            currentSampleSelection = folder;
                            items.Add(folder, samplePath + folder);
                        }
                    }
                }

                if (msg.Length > 72)
                {
                    MessageBox.Show(msg, "WARNING", MessageBoxButtons.OK);
                }
                ReloadSampleList();

                if (IsSalmonella)
                {
                    AppConfigHelper.SalmonellaSamplesPath = samplePath;
                }
                else if (IsInfluenzaA)
                {
                    AppConfigHelper.InfluenzaASamplesPath = samplePath;
                }
            }
        }
Пример #19
0
        private void backgroundWorker_Versions_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            SeqDB db = (SeqDB)e.Argument;

            e.Result = ServiceCallHelper.GetVersions(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig(), DirectoryHelper.CleanPath(db.DBPath));
        }
Пример #20
0
        private void btnPushTask_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            BioSeqTask task = AppConfigHelper.TaskOfIndex(lstTasks.SelectedIndex);

            Cursor.Current = Cursors.Default;

            if (task == null || task.LastExitCode == -999)
            {
                MessageBox.Show("Task output is no longer available but may have completed.", "Warning", MessageBoxButtons.OK);
                return;
            }

            AppConfigHelper.LastCommand = task.TaskCommand;
            switch (task.TaskType)
            {
            case "VFabricate":
                TaskCompletion(task, "VFabricate", "VFabricate completed.");

                Cursor.Current = Cursors.Default;
                if (task.LastExitCode == 0)
                {
                    string sampleName = string.Empty;
                    if (AppConfigHelper.SampleChecked("VFabricate"))
                    {
                        sampleName = AppConfigHelper.SampleID("VFabricate");
                    }

                    string destination = AppConfigHelper.CopyResultFromServer(AppConfigHelper.OutputPath("VFabricate"),
                                                                              new string[] { sampleName + ".VFList.tsv" });
                    MessageBox.Show(task.StandardOutput + Environment.NewLine + "VFabricate completed successfully. Result is in " +
                                    destination + "\\" + sampleName + ".VFList.tsv", "Success", MessageBoxButtons.OK);

                    destination = DirectoryHelper.CleanPath(destination);
                    Process.Start(destination + "\\" + sampleName + ".VFList.tsv");
                }
                break;

            case "Quast":
                TaskCompletion(task, "Quast", "Quast completed.");

                Cursor.Current = Cursors.Default;
                if (task.LastExitCode == 0)
                {
                    string sampleName = string.Empty;
                    if (AppConfigHelper.SampleChecked("Quast"))
                    {
                        sampleName = AppConfigHelper.SampleID("Quast");
                    }

                    string destination = AppConfigHelper.CopyResultFromServer(AppConfigHelper.OutputPath("Quast"), new string[] { "\\Quast" + sampleName }, false); // folder copy

                    //destination = DirectoryHelper.CleanPath(destination);

                    MessageBox.Show(task.StandardOutput + Environment.NewLine + "Quast completed successfully. Result is in the " +
                                    destination + " folder.", "Success", MessageBoxButtons.OK);
                }
                break;

            case "Kraken2":
                TaskCompletion(task, "Kraken2", "Kraken2 completed.");

                Cursor.Current = Cursors.Default;
                if (task.LastExitCode == 0)
                {
                    MessageBox.Show(task.StandardOutput + Environment.NewLine + "Kraken2 completed successfully. Result is in " +
                                    AppConfigHelper.OutputPath("Kraken2") + ".", "Success", MessageBoxButtons.OK);
                    if (AppConfigHelper.OutputPath("Kraken2").StartsWith("[L]"))
                    {
                        string destination = DirectoryHelper.CleanPath(AppConfigHelper.OutputPath("Kraken2")) + "\\";
                        if (File.Exists(destination + "kraken.aggregates.txt"))
                        {
                            File.Delete(destination + "kraken.aggregates.txt");
                        }
                        if (File.Exists(destination + "kraken.txt"))
                        {
                            File.Delete(destination + "kraken.txt");
                        }
                        if (File.Exists(destination + "RefseqIdent.txt"))
                        {
                            File.Delete(destination + "RefseqIdent.txt");
                        }
                        AppConfigHelper.CopyResultFromServer(AppConfigHelper.OutputPath("Kraken2"),
                                                             new string[] { "kraken.aggregates.txt", "kraken.txt", "RefseqIdent.txt" });
                        if (File.Exists(destination + "kraken.aggregates.txt"))
                        {
                            Process.Start(destination + "kraken.aggregates.txt");
                        }
                        if (File.Exists(destination + "kraken.txt"))
                        {
                            Process.Start(destination + "kraken.txt");
                        }
                        if (File.Exists(destination + "RefseqIdent.txt"))
                        {
                            Process.Start(destination + "RefseqIdent.txt");
                        }
                    }
                }
                break;

            case "BBMap":
                TaskCompletion(task, "BBMap", "BBMap completed.");

                if (task.LastExitCode == 0)
                {
                    string destination = AppConfigHelper.CopyResultFromServer(AppConfigHelper.OutputPath("BBMap"),
                                                                              new string[] { "covhist.txt", "covstats.txt", "bincov.txt", "basecov.txt", "RefseqIdent.txt" });

                    destination = DirectoryHelper.CleanPath(destination);
                    MessageBox.Show(task.StandardOutput + Environment.NewLine + "BBMap completed successfully. Result is in " +
                                    destination + ".", "Success", MessageBoxButtons.OK);
                    if (File.Exists(destination + "covhist.txt"))
                    {
                        Process.Start(destination + "covhist.txt");
                    }
                    if (File.Exists(destination + "covstats.txt"))
                    {
                        Process.Start(destination + "covstats.txt");
                    }
                    if (File.Exists(destination + "bincov.txt"))
                    {
                        Process.Start(destination + "bincov.txt");
                    }
                    if (File.Exists(destination + "basecov.txt"))
                    {
                        Process.Start(destination + "basecov.txt");
                    }
                    if (File.Exists(destination + "RefseqIdent.txt"))
                    {
                        Process.Start(destination + "RefseqIdent.txt");
                    }
                }
                break;

            case "Search":
                TaskCompletion(task, "Search", "Search completed.");

                Cursor.Current = Cursors.WaitCursor;
                ServiceCallHelper.LoadConfig(AppConfigHelper.LoggedOnUser); // To retrieve StandardOutput and LastError.
                Cursor.Current = Cursors.Default;
                if (task.LastExitCode == 0)
                {
                    string filename = AppConfigHelper.OutputPath("Search") + "\\" + AppConfigHelper.SearchOutputSampleName() + ".txt";
                    MessageBox.Show(task.StandardOutput + Environment.NewLine +
                                    "Search completed successfully. Close this dialog to open the result file in " + filename + ".", "Success", MessageBoxButtons.OK);

                    // If the output path is on the server, we need to copy it to the local Temp folder to display the results.
                    // If the output path is on the local machine, we need to copy from the user folder on the server to the local destination.

                    string destination = AppConfigHelper.CopyResultFromServer(AppConfigHelper.OutputPath("Search"),
                                                                              new string[] { AppConfigHelper.SearchOutputSampleName() + ".txt" });
                    Process.Start(DirectoryHelper.CleanPath(destination) + AppConfigHelper.SearchOutputSampleName() + ".txt");
                }
                break;

            case "Assemble":
                TaskCompletion(task, "Assembly", "Assembly completed. If there are no errors, the results including the contig files are in the E:/data/staging folder on the server.");
                break;

            case "InfluenzaA":
                TaskCompletion(task, "InfluenzaA", "InfluenzaA completed.");

                Cursor.Current = Cursors.Default;
                if (task.LastExitCode == 0)
                {
                    //MessageBox.Show(task.StandardOutput + Environment.NewLine + "InfluenzaA completed successfully. Result is in the " +
                    //                AppConfigHelper.InfluenzaAOutputPath + " folder.", "Success", MessageBoxButtons.OK);
                    if (IsServiceClass.IsService)
                    {
                        if (AppConfigHelper.InfluenzaAOutputPath.StartsWith("[L]")) // Output was created on server, to be stored on client.  [L]
                        {
                            // For each sample that was processed, there is a subfolder in the UserFolder on the server named after the sample name.
                            // That subfolder needs to be copied to the local output folder. Note that we only copy the <sample>\consensus contents.
                            foreach (string sampleName in AppConfigHelper.InfluenzaASamplesList.Keys)
                            {
                                if (AppConfigHelper.InfluenzaASamplesList[sampleName].Substring(0, 1) == "1")
                                {
                                    string sourceFolderName = "[S]" + AppConfigHelper.UserFolder() + sampleName + "\\consensus\\";
                                    Directory.CreateDirectory(DirectoryHelper.CleanPath(AppConfigHelper.InfluenzaAOutputPath) + "\\" + sampleName + "\\");
                                    //Logger.Log.Debug("Copy from " + sourceFolderName + " to " + AppConfigHelper.InfluenzaAOutputPath + "\\");
                                    DirectoryHelper.FolderCopy(sourceFolderName, AppConfigHelper.InfluenzaAOutputPath + "\\" + sampleName + "\\");
                                }
                            }
                        }
                        MessageBox.Show(task.StandardOutput + Environment.NewLine + "Influenza A pipeline completed successfully. Results copied to " +
                                        AppConfigHelper.InfluenzaAOutputPath + "\\, including consensus fasta files in sample name subfolder[s].",
                                        "Files copied", MessageBoxButtons.OK);
                    }
                }
                break;

            case "Centrifuge":
                TaskCompletion(task, "Centrifuge", "Centrifuge completed.");

                Cursor.Current = Cursors.Default;
                if (task.LastExitCode == 0)
                {
                    if (IsServiceClass.IsService)
                    {
                        if (AppConfigHelper.CentrifugeOutputPath.StartsWith("[L]")) // Output was created on server, to be stored on client.  [L]
                        {
                            if (AppConfigHelper.CentrifugeOutputPath.StartsWith("[L]"))
                            {
                                string destination = DirectoryHelper.CleanPath(AppConfigHelper.CentrifugeOutputPath) + "\\";
                                if (File.Exists(destination + "centrifuge_res.tsv"))
                                {
                                    File.Delete(destination + "centrifuge_res.tsv");
                                }
                                if (File.Exists(destination + "centrifuge_report.tsv"))
                                {
                                    File.Delete(destination + "centrifuge_report.tsv");
                                }
                                AppConfigHelper.CopyResultFromServer(AppConfigHelper.CentrifugeOutputPath, new string[] { "centrifuge_res.tsv", "centrifuge_report.tsv" });

                                if (File.Exists(destination + "centrifuge_report.tsv"))
                                {
                                    Process.Start(destination + "centrifuge_report.tsv");
                                }
                            }
                        }
                        MessageBox.Show(task.StandardOutput + Environment.NewLine + "Centrifuge pipeline completed successfully. Results copied to " +
                                        AppConfigHelper.CentrifugeOutputPath + ".", "Files copied", MessageBoxButtons.OK);
                    }
                }
                break;

            case "Salmonella":
                TaskCompletion(task, "Salmonella", "Salmonella serotyping completed.");

                Cursor.Current = Cursors.Default;
                if (task.LastExitCode == 0)
                {
                    MessageBox.Show(task.StandardOutput + Environment.NewLine + "Salmonella serotyping completed successfully. Result is in " +
                                    AppConfigHelper.SalmonellaOutputPath, "Success", MessageBoxButtons.OK);
                    if (IsServiceClass.IsService)
                    {
                        if (AppConfigHelper.SalmonellaOutputPath.StartsWith("[L]")) // Output was created on server, to be stored on client.  [L]
                        {
                            string sourceFolderName      = "[S]" + AppConfigHelper.UserFolder() + "\\sistr_res_aggregate.csv";
                            string destinationFolderName = AppConfigHelper.SalmonellaOutputPath;
                            DirectoryHelper.FileCopy(sourceFolderName, destinationFolderName, true);
                            File.Move(DirectoryHelper.CleanPath(destinationFolderName) + "\\sistr_res_aggregate.csv",
                                      DirectoryHelper.CleanPath(destinationFolderName) + "\\sistr_res_aggregate" + DateTime.Now.ToString("yyMMddHHmmss") + ".csv"); // Rename
                            Process.Start(DirectoryHelper.CleanPath(destinationFolderName) + "\\sistr_res_aggregate" + DateTime.Now.ToString("yyMMddHHmmss") + ".csv");
                        }
                        else // Rename on server.
                        {
                            DirectoryHelper.FileMove(AppConfigHelper.SalmonellaOutputPath + "\\sistr_res_aggregate.csv",
                                                     AppConfigHelper.SalmonellaOutputPath + "\\sistr_res_aggregate" + DateTime.Now.ToString("yyMMddHHmmss") + ".csv");
                        }
                    }
                }
                break;

            case "Nextstrain":
                TaskCompletion(task, "Nextstrain", "Nextstrain phylogenetic processing completed.");

                Cursor.Current = Cursors.Default;
                if (task.LastExitCode == 0)
                {
                    //NextstrainProfile nextstrainProfile = AppConfigHelper.GetNextstrainProfile(); // for current database.
                    MessageBox.Show(task.StandardOutput + Environment.NewLine + "Nextstrain completed successfully.", "Success", MessageBoxButtons.OK);
                    if (IsServiceClass.IsService)
                    {
                        //string browser = string.Empty;
                        //RegistryKey key = null;
                        //try
                        //{
                        //  key = Registry.ClassesRoot.OpenSubKey(@"HTTP\shell\open\command");
                        //  if (key != null)
                        //  {
                        //    // Get default Browser
                        //    browser = key.GetValue(null).ToString().ToLower().Trim(new[] { '"' });
                        //  }
                        //  if (!browser.EndsWith("exe"))
                        //  {
                        //    //Remove all after the ".exe"
                        //    browser = browser.Substring(0, browser.LastIndexOf(".exe", StringComparison.InvariantCultureIgnoreCase) + 4);
                        //  }
                        //}
                        //finally
                        //{
                        //  if (key != null)
                        //  {
                        //    key.Close();
                        //  }
                        //}

                        // Open the browser.
                        // See documentation for this approach:
                        // https://docs.nextstrain.org/en/latest/guides/share/community-builds.html
                        // The GitHub repository file structure must be:
                        // nextstrain/auspice/nextstrain.json

                        // The BioSeqDB service will have already pushed the updated files to Github.

                        Process proc = Process.Start("https://nextstrain.org/community/ArnieBerg/nextstrain@main");

                        //if (nextstrainProfile.OuputPath.StartsWith("[L]")) // Output was created on server, to be stored on client.  [L]
                        //{
                        //  string sourceFolderName = "[S]" + AppConfigHelper.UserFolder() + "\\ncov_global.json";
                        //  string destinationFolderName = nextstrainProfile.OuputPath;
                        //  DirectoryHelper.FileCopy(sourceFolderName, destinationFolderName, true);
                        //  File.Move(DirectoryHelper.CleanPath(destinationFolderName) + "\\ncov_global.json",
                        //            DirectoryHelper.CleanPath(destinationFolderName) + "\\sistr_res_aggregate" + DateTime.Now.ToString("yyMMddHHmmss") + ".csv");  // Rename
                        //  Process.Start(DirectoryHelper.CleanPath(destinationFolderName) + "\\sistr_res_aggregate" + DateTime.Now.ToString("yyMMddHHmmss") + ".csv");
                        //}
                        //else // Rename on server.
                        //{
                        //  DirectoryHelper.FileMove(nextstrainProfile.OuputPath + "\\sistr_res_aggregate.csv",
                        //                           nextstrainProfile.OuputPath + "\\sistr_res_aggregate" + DateTime.Now.ToString("yyMMddHHmmss") + ".csv");
                        //}
                    }
                }
                break;

            case "BuildTree":
                TaskCompletion(task, "BuildTree", "BuildTree completed. Close this dialog to open the result file.");

                //Logger.Log.Debug("ExitCode=" + task.LastExitCode.ToString() + @" Write to c:\temp\commandline.txt: open file='" +
                //                                    AppConfigHelper.BuildTreeOutputPath() + "\\tree.nwk';" + Environment.NewLine);
                if (!Directory.Exists("C:\\Temp"))
                {
                    Directory.CreateDirectory("C:\\Temp");
                }

                string dendroscopePath = @"C:\Temp\";
                if (IsServiceClass.IsService)
                {
                    // For service, copy the tree.nwk from wherever it was stored to C:\Temp. If it is on the server, call the service to copy it.
                    // If it is on the local machine, do a File.Copy.
                    string sourceFolderName      = "[S]" + AppConfigHelper.UserFolder();
                    string destinationFolderName = AppConfigHelper.BuildTreeOutputPath() + "\\";

                    Logger.Log.Debug("btnPushTask: FileCopy " + sourceFolderName + "tree.nwk to " + destinationFolderName);
                    Logger.Log.Debug("btnPushTask: DirectoryHelper destination: " +
                                     AppConfigHelper.GetDirectoryName(DirectoryHelper.CleanPath(destinationFolderName + "\\")) + "\\" +
                                     Path.GetFileName(DirectoryHelper.CleanPath(sourceFolderName)) + "tree.nwk");

                    if (destinationFolderName.StartsWith("[L]")) // Buildtree output was created on server, to be stored on client.  [L]
                    {
                        DirectoryHelper.FileCopy(sourceFolderName + "tree.nwk", destinationFolderName, true);
                        DirectoryHelper.FileCopy(sourceFolderName + "metadata_microreact.csv", destinationFolderName, true);
                        dendroscopePath = DirectoryHelper.CleanPath(destinationFolderName);
                        Logger.Log.Debug("btnPushTask: dendroscopePath: " + dendroscopePath);
                    }
                    else // Buildtree output was created on server, to be stored on server.  [S]
                    {
                        DirectoryHelper.FileCopy(sourceFolderName + "tree.nwk", destinationFolderName, true);
                        DirectoryHelper.FileCopy(sourceFolderName + "metadata_microreact.csv", destinationFolderName, true);

                        // Also copy to local Temp folder for Dendroscope to pick up.
                        DirectoryHelper.FileCopy(sourceFolderName + "tree.nwk", @"[L]C:\Temp\", true);
                        DirectoryHelper.FileCopy(sourceFolderName + "metadata_microreact.csv", @"[L]C:\Temp\", true);
                    }
                }
                else
                {
                    if (DirectoryHelper.CleanPath(AppConfigHelper.BuildTreeOutputPath()) != @"C:\Temp")
                    {
                        if (File.Exists(@"C:\Temp\tree.nwk"))
                        {
                            File.Delete(@"C:\Temp\tree.nwk");
                        }
                        File.Copy(DirectoryHelper.CleanPath(AppConfigHelper.BuildTreeOutputPath() + "\\tree.nwk"), @"C:\Temp\tree.nwk", true);
                    }
                    if (File.Exists(@"C:\Temp\metadata_microreact.csv"))
                    {
                        File.Delete(@"C:\Temp\metadata_microreact.csv");
                    }
                    File.Copy(DirectoryHelper.CleanPath(AppConfigHelper.BuildTreeOutputPath() + "\\metadata_microreact.csv"), @"C:\Temp\metadata_microreact.csv", true);
                }

                File.WriteAllText("C:\\Temp\\commandline.txt", @"open file='" + dendroscopePath + "tree.nwk';" + Environment.NewLine);

                if (task.LastExitCode == 0)
                {
                    // Invoke Dendroscope to visualize tree.  c:\\Temp\\commandine.txt contains the line:
                    // open file='C:\Temp\Save\tree.nwk';
                    try
                    {
                        Cursor.Current = Cursors.WaitCursor;
                        Process.Start(AppConfigHelper.PathToDendroscope(), "-g -c c:\\Temp\\commandline.txt");
                        Cursor.Current = Cursors.Default;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Dendroscope needs to be installed to view the result. Check path " + AppConfigHelper.PathToDendroscope() +
                                        Environment.NewLine + Environment.NewLine + ex.ToString(), "INSTALL DENDROSCOPE", MessageBoxButtons.OK);
                    }
                }
                break;
            }
            UIThreadRefresh(sender, e);
        }