private void btnOK_Click(object sender, EventArgs e) { string dbname = txtDBName.Text.Trim(); if (AppConfigHelper.seqdbConfig.seqDBs.ContainsKey(dbname)) // This can only be checked after we know the name of the db. { if (MessageBox.Show("There is already a database named " + dbname + ". Do you want to replace it?", "Replace database?", MessageBoxButtons.OKCancel) != DialogResult.OK) { return; } SeqDB db = AppConfigHelper.seqdbConfig.seqDBs[dbname]; if (db != null && db.DBPath == txtDBPath.Text + "/" + dbname) { if (MessageBox.Show("The database path " + db.DBPath + " already exists. Do you want to replace it?", "Overwrite database?", MessageBoxButtons.OKCancel) != DialogResult.OK) { return; } } } // Update config to reflect selection. AppConfigHelper.NewDatabase(dbname, txtDBPath.Text.Trim(), chkImportFasta.Checked, txtInputPath.Text.Trim(), txtStandardReferenceGenome.Text.Trim()); }
// Build a new database. Treat the new database as the selected database if all goes well and update config. // If there is already a database by the specified name, prompt to overwrite. public BioSeqNewDB() { InitializeComponent(); btnOK.Enabled = false; string dbPath = AppConfigHelper.NewDBPath; if (string.IsNullOrEmpty(dbPath)) { SeqDB db = AppConfigHelper.seqdbConfigGlobal.Current(); if (db != null) // Default the new database path to the same as the current db. { txtDBPath.Text = AppConfigHelper.GetDirectoryName(AppConfigHelper.NormalizePathToWindows(DirectoryHelper.UnCleanPath(db.DBPath))); txtDBPath.Text = AppConfigHelper.NormalizePathToLinux(AppConfigHelper.GetDirectoryName(txtDBPath.Text)); // DB path much be on the server. if (!txtDBPath.Text.StartsWith("[")) { txtDBPath.Text = "[S]" + txtDBPath.Text; } } } else { txtDBPath.Text = dbPath; } txtDBName.Text = AppConfigHelper.NewDBName; chkImportFasta.Checked = AppConfigHelper.NewDBImportFasta; txtInputPath.Text = AppConfigHelper.NewDBInputPath; txtStandardReferenceGenome.Text = AppConfigHelper.NewDBReference; EnableOK(); }
private void RefreshVersionInformation(SeqDB db) { if (!VersionsBusyFlag) { VersionsBusyFlag = true; backgroundWorker_Versions.RunWorkerAsync(db); } }
private void backgroundWorker_Versions_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) { // Get version info. Version information comes from the global config. Cursor.Current = Cursors.WaitCursor; VersionsBusyFlag = false; txtVersions.Text = (string)e.Result; lblKipper.Visible = false; if (txtVersions.Text.Trim().Length > 0) { SeqDB db = AppConfigHelper.seqdbConfigGlobal.seqDBs[AppConfigHelper.seqdbConfig.LastDBSelected]; lblKipper.Text = "This backup is stored at " + db.KipperPath + db.KipperFilenamePrefix + "."; lblKipper.Visible = true; } btnRestore.Enabled = txtVersions.Text.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries).Length > 2; // Must have at least two backups before restore is meaningful. Cursor.Current = Cursors.Default; }
internal static int DeleteDB() { SeqDB db = AppConfigHelper.seqdbConfig.Current(); string filename = AppConfigHelper.NormalizePathToWindows(db.DBPath); if (File.Exists(filename)) { string path = AppConfigHelper.GetDirectoryName(filename); Directory.Delete(path, true); AppConfigHelper.seqdbConfig.seqDBs.Remove(AppConfigHelper.seqdbConfig.LastDBSelected); // Remove all traces of this database. AppConfigHelper.SaveConfig(); string dbName = AppConfigHelper.seqdbConfig.LastDBSelected; AppConfigHelper.seqdbConfig.LastDBSelected = AppConfigHelper.CurrentDBName(); // Also update the global config to remove the database. db = AppConfigHelper.seqdbConfigGlobal.seqDBs[dbName]; AppConfigHelper.seqdbConfigGlobal.seqDBs.Remove(dbName); // Remove all traces of this database. AppConfigHelper.seqdbConfigGlobal.LastDBSelected = AppConfigHelper.seqdbConfig.LastDBSelected; if (db.KipperPath != null) // This should be done first because these files might be in the same folder as the one being deleted below. { if (Directory.Exists(AppConfigHelper.NormalizePathToWindows(db.KipperPath))) // it could have been deleted if it was already in the same folder as the database itself. { DirectoryInfo dir = new DirectoryInfo(AppConfigHelper.NormalizePathToWindows(db.KipperPath)); foreach (FileInfo file in dir.EnumerateFiles(db.KipperFilenamePrefix + "*.*")) { if (File.Exists(file.FullName)) // it could have been deleted if it was already in the same folder as the database itself. { file.Delete(); } } } } AppConfigHelper.SaveConfigGlobal(); } return(0); }
public static WSLProxyResponse Build_DB(SeqDB db) { // eg. ~/seqdb/seqdb build_db -i /data/amrDBinput/organism -o /data/amrDB/hpsuis/hpsuis.fasta if (db.BuildTreeWildReference.Length > 0) { // Also copy the wild to the database folder so it can be used in the future. if (File.Exists(db.BuildTreeWildReference)) { db.BuildTreeDomesticReference = AppConfigHelper.GetDirectoryName(AppConfigHelper.NormalizePathToWindows(db.DBPath)) + "\\" + Path.GetFileName(AppConfigHelper.NormalizePathToWindows(db.BuildTreeWildReference)); File.Copy(db.BuildTreeWildReference, db.BuildTreeDomesticReference, true); db.BuildTreeWildReference = string.Empty; // No longer need to overload it, now available for its intended purpose. } } if (!Directory.Exists(db.DBPath)) { Directory.CreateDirectory(db.DBPath); } AppConfigHelper.LastCommand = AppConfigHelper.PathToSeqDB() + " build_db -i " + AppConfigHelper.NormalizePathToLinux(db.Build_DBInput) + " -o " + AppConfigHelper.NormalizePathToLinux(db.DBPath); return(StandardCallToWSL()); }
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)); }
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); } } }