public ConfigWizard(HistoryItem hi, IList<ConfigFile> templateList, bool editMode) { InitializeComponent(); _currentJob = hi; _templateList = templateList; _editMode = editMode; if (editMode) Text = "Edit Job"; }
/// <summary> /// Dialogue used to create new job. Fields pre-filled and appearance changed to edit mode if true /// </summary> /// <param name="oldFiles">List of used HistoryItems</param> /// <param name="hi">History Item to clone from</param> /// <param name="editMode">True if form should visually appear to be an edit box</param> /// <param name="templates">List of available templates</param> public AddJobForm(HistoryItem hi, IList<ConfigFile> templates, bool editMode, Form parentForm) { InitializeComponent(); SearchTypeBox.Text = JobType.Myrimatch; SetHistoryItem(hi); if (editMode) { Text = "Edit Job"; AddJobRunButton.Text = "Save"; } _templateList = templates; _parentForm = parentForm; }
/// <summary> /// Starts Bumbershoot utility based on current row and destination program /// </summary> private void ProcessJob(HistoryItem hi) { var argumentString = new StringBuilder(); string configString; _killed = false; ProcessStartInfo psi; if (hi.Cpus > 0 && (_destinationProgram != "Comet" && _destinationProgram != "MSGF")) argumentString.Append(string.Format("-cpus {0} ", hi.Cpus)); var workingDirectory = hi.OutputDirectory.TrimEnd('*'); switch (_destinationProgram) { case "MyriMatch": //Set location of the program psi = new ProcessStartInfo(String.Format(@"""{0}\lib\Bumbershoot\MyriMatch\myrimatch.exe""", AppDomain.CurrentDomain.BaseDirectory)); //determine configuration configString = hi.InitialConfigFile.FilePath == "--Custom--" ? PropertyListToOverrideString(hi.InitialConfigFile.PropertyList) : string.Format("-cfg \"{0}\" ", hi.InitialConfigFile.FilePath); //continue to set up argument string argumentString.Append(String.Format("{0}-ProteinDatabase \"{1}\"", configString, hi.ProteinDatabase)); //add files to scan to argument string if (hi.FileList.Count == 1 && hi.FileList[0].FilePath.StartsWith("!")) { var fullMask = hi.FileList[0].FilePath.Trim('!'); var initialDir = Path.GetDirectoryName(fullMask); var mask = Path.GetFileName(fullMask); var maskedFiles = Directory.GetFiles(initialDir, mask); argumentString.Append(String.Format(" \"{0}\"", fullMask)); _filesToProcess = maskedFiles.Length; } else foreach (var file in hi.FileList) { argumentString.Append(String.Format(" {0}", file.FilePath)); _filesToProcess++; } break; case "Comet": //Set location of the program psi = new ProcessStartInfo(String.Format(@"""{0}\lib\comet.exe""", AppDomain.CurrentDomain.BaseDirectory)); //create temp params file var cometConfig = new List<ConfigProperty>(hi.InitialConfigFile.PropertyList).Find(x => x.Name == "config"); if (cometConfig == null) { JobFinished(false, true); return; } var tempCometPath = Path.GetTempFileName(); _tempFiles.Add(tempCometPath); var tempCometParams = new StreamWriter(tempCometPath); tempCometParams.Write(cometConfig.Value); tempCometParams.Flush(); tempCometParams.Close(); //make sure fasta has no spaces in name var cometDB = hi.ProteinDatabase; if (cometDB.Contains(" ")) { cometDB = Path.GetTempFileName(); File.Copy(hi.ProteinDatabase, cometDB,true); _tempFiles.Add(cometDB); } argumentString.Append(" -P\"" + tempCometPath + "\""); argumentString.Append(" -D\"" + cometDB + "\""); //add files to scan to argument string _moveFileList = new List<string>(); if (hi.FileList.Count == 1 && hi.FileList[0].FilePath.StartsWith("!")) { var fullMask = hi.FileList[0].FilePath.Trim('!'); var initialDir = Path.GetDirectoryName(fullMask); var mask = Path.GetFileName(fullMask); var maskedFiles = Directory.GetFiles(initialDir, mask); argumentString.Append(String.Format(" \"{0}\"", fullMask)); _filesToProcess = maskedFiles.Length; foreach (var file in maskedFiles) { var noExtension = Path.Combine(initialDir, Path.GetFileNameWithoutExtension(file) ?? string.Empty); var cometParams = CometHandler.FileContentsToCometParams(cometConfig.Value); _moveFileList.Add(noExtension + cometParams.OutputSuffix + ".pep.xml"); } } else { foreach (var file in hi.FileList) { var initialDir = Path.GetDirectoryName(hi.FileList[0].FilePath.Trim('"').Trim('!')); var noExtension = Path.Combine(initialDir ?? string.Empty, Path.GetFileNameWithoutExtension(file.FilePath.Trim('"')) ?? string.Empty); var cometParams = CometHandler.FileContentsToCometParams(cometConfig.Value); _moveFileList.Add(noExtension + cometParams.OutputSuffix + ".pep.xml"); argumentString.Append(String.Format(" {0}", file.FilePath)); _filesToProcess++; } } break; case "MSGF": //find java path var javaPath = string.Empty; string environmentPath = Environment.GetEnvironmentVariable("JAVA_HOME"); if (!string.IsNullOrEmpty(environmentPath)) javaPath = environmentPath; else { var javaKey = "SOFTWARE\\JavaSoft\\Java Runtime Environment\\"; var rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(javaKey); if (rk != null) { string currentVersion = rk.GetValue("CurrentVersion").ToString(); using (Microsoft.Win32.RegistryKey key = rk.OpenSubKey(currentVersion)) javaPath = key.GetValue("JavaHome").ToString(); } else { javaKey = "SOFTWARE\\JavaSoft\\Java Development Kit\\"; rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(javaKey); if (rk != null) { string currentVersion = rk.GetValue("CurrentVersion").ToString(); using (Microsoft.Win32.RegistryKey key = rk.OpenSubKey(currentVersion)) javaPath = key.GetValue("JavaHome").ToString(); } } } if (javaPath == string.Empty) throw new Exception("Could not locate Java path"); //Set location of the program psi = new ProcessStartInfo(Path.Combine(javaPath, "bin\\java.exe")); if (_msgfList == null || _msgfList.Count == 0) { //create temp mods file var msgfOverload = new List<ConfigProperty>(hi.InitialConfigFile.PropertyList).Find(x => x.Name == "config"); var msgfMods = new List<ConfigProperty>(hi.InitialConfigFile.PropertyList).Find(x => x.Name == "mods"); if (msgfOverload == null || msgfMods == null) { JobFinished(false, true); return; } var tempMSGFPath = Path.GetTempFileName(); _tempFiles.Add(tempMSGFPath); var tempMSGFMods = new StreamWriter(tempMSGFPath); tempMSGFMods.Write(msgfMods.Value); tempMSGFMods.Flush(); tempMSGFMods.Close(); //set up file list var fileList = new List<string>(); _moveFileList = new List<string>(); if (hi.FileList.Count == 1 && hi.FileList[0].FilePath.StartsWith("!")) { var fullMask = hi.FileList[0].FilePath.Trim('!'); var initialDir = Path.GetDirectoryName(fullMask); var mask = Path.GetFileName(fullMask); var maskedFiles = Directory.GetFiles(initialDir, mask); fileList.AddRange(maskedFiles.Select(file => "\"" + file + "\"")); foreach (var file in maskedFiles) { var noExtension = Path.Combine(initialDir, Path.GetFileNameWithoutExtension(file) ?? string.Empty); var msgfParams = MSGFHandler.OverloadToMSGFParams(msgfOverload.Value); _moveFileList.Add(noExtension + msgfParams.OutputSuffix + ".mzid"); } } else { fileList.AddRange(hi.FileList.Select(file => file.FilePath)); foreach (var file in hi.FileList) { var initialDir = Path.GetDirectoryName(hi.FileList[0].FilePath.Trim('"').Trim('!')); var noExtension = Path.Combine(initialDir, Path.GetFileNameWithoutExtension(file.FilePath.Trim('"')) ?? string.Empty); var msgfParams = MSGFHandler.OverloadToMSGFParams(msgfOverload.Value); _moveFileList.Add(noExtension + msgfParams.OutputSuffix + ".mzid"); } } _filesToProcess = fileList.Count; //create overload List _msgfList = new List<string>(); foreach (var file in fileList) { var arg = new StringBuilder(); arg.AppendFormat(@"-d64 -Xmx4000M -jar ""{0}\lib\MSGFPlus.jar""", AppDomain.CurrentDomain.BaseDirectory); arg.Append(" -d \"" + hi.ProteinDatabase + "\""); arg.Append(" -mod \"" + tempMSGFPath + "\""); var noExtension = Path.Combine(Path.GetDirectoryName(file.Trim('"')) ?? string.Empty, Path.GetFileNameWithoutExtension(file.Trim('"')) ?? string.Empty); arg.Append(" " + msgfOverload.Value.Trim() .Replace("[FileNameOnly]", noExtension) .Replace("[FullFileName]", file.Trim('"'))); _msgfList.Add(arg.ToString()); } } if (_fileProcessing >= 0 || _fileProcessing < _msgfList.Count) argumentString.Append(_msgfList[_fileProcessing]); else JobFinished(false, true); _fileProcessing++; break; case "DirecTag": //Set location of the program psi = new ProcessStartInfo(String.Format(@"""{0}\lib\Bumbershoot\DirecTag\directag.exe""", AppDomain.CurrentDomain.BaseDirectory)); //determine configuration configString = hi.InitialConfigFile.FilePath == "--Custom--" ? PropertyListToOverrideString(hi.InitialConfigFile.PropertyList) : string.Format("-cfg \"{0}\" ", hi.InitialConfigFile.FilePath); //HACK: Remove when deisotoping is usable configString += string.Format("-{0} {1} ", "DeisotopingMode", "0"); //continue to set up argument string argumentString.Append(configString.Trim()); //add files to scan to argument string _direcTagMask = null; if (hi.FileList.Count == 1 && hi.FileList[0].FilePath.StartsWith("!")) { var fullMask = hi.FileList[0].FilePath.Trim('!'); _direcTagMask = fullMask; var initialDir = Path.GetDirectoryName(fullMask); var mask = Path.GetFileName(fullMask); var maskedFiles = Directory.GetFiles(initialDir, mask); argumentString.Append(String.Format(" \"{0}\"", fullMask)); _filesToProcess = maskedFiles.Length; } else foreach (var file in hi.FileList) { argumentString.Append(String.Format(" {0}", file.FilePath)); _filesToProcess++; } break; case "TagRecon": //Set location of the program psi = new ProcessStartInfo(String.Format(@"""{0}\lib\Bumbershoot\TagRecon\tagrecon.exe""", AppDomain.CurrentDomain.BaseDirectory)); //determine configuration if (hi.TagConfigFile.FilePath == "--Custom--") { configString = PropertyListToOverrideString(hi.TagConfigFile.PropertyList); //use intranal blosum and unimod files if not specified if (!configString.Contains("-Blosum ")) configString += string.Format("-{0} \"{1}\" ", "Blosum", Path.Combine( AppDomain.CurrentDomain.BaseDirectory, @"lib\Bumbershoot\TagRecon\blosum62.fas")); if (!configString.Contains("UnimodXML")) configString += string.Format("-{0} \"{1}\" ", "UnimodXML", Path.Combine( AppDomain.CurrentDomain.BaseDirectory, @"lib\Bumbershoot\TagRecon\unimod.xml")); } else { configString = string.Format("-cfg \"{0}\" ", hi.TagConfigFile.FilePath); var configCheck = new StreamReader(hi.TagConfigFile.FilePath); var entireFile = configCheck.ReadToEnd(); configCheck.Close(); if (!entireFile.Contains("Blosum =")) configString += string.Format("-{0} \"{1}\" ", "Blosum", Path.Combine( AppDomain.CurrentDomain.BaseDirectory, @"lib\Bumbershoot\TagRecon\blosum62.fas")); if (!entireFile.Contains("UnimodXML =")) configString += string.Format("-{0} \"{1}\" ", "UnimodXML", Path.Combine( AppDomain.CurrentDomain.BaseDirectory, @"lib\Bumbershoot\TagRecon\unimod.xml")); } //continue to set up argument string argumentString.Append(String.Format("{0}-ProteinDatabase \"{1}\"", configString, hi.ProteinDatabase)); //add files to scan to argument string foreach (var file in _completedFiles) { argumentString.AppendFormat(" \"{0}\"", Path.Combine(hi.OutputDirectory.TrimEnd('*'), file)); _filesToProcess++; } break; case "Pepitome": //Set location of the program psi = new ProcessStartInfo(String.Format(@"""{0}\lib\Bumbershoot\Pepitome\pepitome.exe""", AppDomain.CurrentDomain.BaseDirectory)); //determine configuration configString = hi.InitialConfigFile.FilePath == "--Custom--" ? PropertyListToOverrideString(hi.InitialConfigFile.PropertyList) : string.Format("-cfg \"{0}\" ", hi.InitialConfigFile.FilePath); //continue to set up argument string argumentString.Append(String.Format("{0}-ProteinDatabase \"{1}\" -SpectralLibrary \"{2}\"", configString, hi.ProteinDatabase, hi.SpectralLibrary)); //add files to scan to argument string if (hi.FileList.Count == 1 && hi.FileList[0].FilePath.StartsWith("!")) { var fullMask = hi.FileList[0].FilePath.Trim('!'); var initialDir = Path.GetDirectoryName(fullMask); var mask = Path.GetFileName(fullMask); var maskedFiles = Directory.GetFiles(initialDir, mask); argumentString.Append(String.Format(" \"{0}\"", fullMask)); _filesToProcess = maskedFiles.Length; } else foreach (var file in hi.FileList) { argumentString.Append(String.Format(" {0}", file.FilePath)); _filesToProcess++; } break; default: //should never be called, throw error if it is throw new Exception(String.Format("Destination Program not set to known value: {0}", _destinationProgram)); } psi.WorkingDirectory = workingDirectory; psi.Arguments = argumentString.ToString(); var commandGiven = (string.Format("Command given:{0}{1}>{2} {3}{0}{0}", Environment.NewLine, psi.WorkingDirectory, psi.FileName, psi.Arguments)); SendToLog(commandGiven); //Make sure window stays hidden psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; psi.UseShellExecute = false; psi.CreateNoWindow = true; _runningProgram = new Process { StartInfo = psi, EnableRaisingEvents = true }; _runningProgram.Start(); _runningProgram.PriorityClass = ProcessPriorityClass.BelowNormal; _runningProgram.BeginOutputReadLine(); _runningProgram.OutputDataReceived += DataReceived; _runningProgram.BeginErrorReadLine(); _runningProgram.ErrorDataReceived += ErrorCaught; _runningProgram.Exited += (x, y) => { var bgWait = new BackgroundWorker(); bgWait.DoWork += (zzz, e) => { SendToLog(" ---Program exit detected---"); Thread.Sleep(100); SendToLog(" ---Calculating results---"); var a = ((object[])e.Argument)[0]; var b = (EventArgs)((object[])e.Argument)[1]; ProgramExited(a, b); }; bgWait.RunWorkerAsync(new object[] { x, y }); //ProgramExited(x,y); }; }
/// <summary> /// Selects the destination program and sets it to run in the background /// </summary> /// <param name="rowNumber"></param> /// <param name="hi"></param> internal void StartNewJob(int rowNumber, HistoryItem hi) { _scanning = true; _versionCaught = false; _currentRow = rowNumber; _minPercentage = 0; _fileProcessing = 0; _filesToProcess = 0; _tempFiles = new List<string>(); _currentHI = hi; ThreadStart ts = () => ProcessJob(hi); _workThread = new Thread(ts) { Name = "Program Handler", IsBackground = true }; if (hi.JobType == JobType.Myrimatch) { _completedFiles = new List<string>(); _destinationProgram = "MyriMatch"; SendToLog("BumberDash- Job has started"); } else if (hi.JobType == JobType.Comet) { _completedFiles = new List<string>(); _destinationProgram = "Comet"; SendToLog("BumberDash- Job has started"); } else if (hi.JobType == JobType.MSGF) { _completedFiles = new List<string>(); _destinationProgram = "MSGF"; SendToLog("BumberDash- Job has started"); } else if (hi.JobType == JobType.Library) { _completedFiles = new List<string>(); _destinationProgram = "Pepitome"; SendToLog("BumberDash- Job has started"); } else if (_destinationProgram == "DirecTag") { _destinationProgram = "TagRecon"; SendToLog(string.Format("{0}{1}{0}", Environment.NewLine, new string('-', 20))); } else { _completedFiles = new List<string>(); _destinationProgram = "DirecTag"; SendToLog("BumberDash- Job has started"); } _workThread.Start(); }
public static ISessionFactory CreateSessionFactory() { var currentGuiVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(3); var newdatabase = false; var root = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),"Bumberdash"); if (!Directory.Exists(root)) Directory.CreateDirectory(root); var dataFile = Path.Combine(root, "Bumbershoot " + currentGuiVersion + ".db"); var newfactory = CreateSessionFactory(dataFile, true); var session = newfactory.OpenSession(); //check that all preloaded templates are present if (session.QueryOver<ConfigFile>().List().Count<16) { //check for presence of completely empty database if (session.QueryOver<HistoryItem>().List().Count == 0 && session.QueryOver<ConfigFile>().List().Count == 0) newdatabase = true; //load base database var baseRoot = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); if (baseRoot == null) throw new Exception("Cannot find base database file"); if (!File.Exists(Path.Combine(baseRoot, "lib\\Bumbershoot.db"))) throw new Exception("Looking for \"" + Path.Combine(baseRoot, "lib\\Bumbershoot.db") + "\", however I cant find it"); var baseFactory = CreateSessionFactory(Path.Combine(baseRoot, "lib\\Bumbershoot.db"), false); var baseSession = baseFactory.OpenSession(); //load base templates var connectedBaseConfigs = baseSession.QueryOver<ConfigFile>().List(); var baseConfigs = new List<ConfigFile>(); foreach (var config in connectedBaseConfigs) { var newInstrument = new ConfigFile { Name = config.Name, DestinationProgram = config.DestinationProgram, FilePath = config.FilePath, PropertyList = new List<ConfigProperty>() }; foreach (var property in config.PropertyList) { var newProperty = new ConfigProperty { ConfigAssociation = newInstrument, Name = property.Name, Type = property.Type, Value = property.Value }; newInstrument.PropertyList.Add(newProperty); } baseConfigs.Add(newInstrument); } //delete old templates (if any remain) and load base template foreach (var config in baseConfigs) { ConfigFile config1 = config; var deleteList = session.QueryOver<ConfigFile>() .Where(x => x.Name == config1.Name && x.DestinationProgram == config1.DestinationProgram) .List(); foreach (var item in deleteList) session.Delete(item); session.Flush(); var newInstrument = new ConfigFile() { Name = config.Name, DestinationProgram = config.DestinationProgram, FilePath = config.FilePath }; session.SaveOrUpdate(newInstrument); session.Flush(); foreach (var property in config.PropertyList) { var newProperty = new ConfigProperty() { ConfigAssociation = newInstrument, Name = property.Name, Type = property.Type, Value = property.Value }; session.SaveOrUpdate(newProperty); } session.Flush(); } //automatically try to recover old history items if database is flagged as new if (newdatabase) { //if database structure is ever changed this will need to be updated to include conversion (probably in the form of basic sqlite queries) var directoryInfo = new DirectoryInfo(root); var bdFiles = directoryInfo.GetFiles("Bumbershoot*.db").Select(file => file.Name).ToList(); bdFiles.Sort(); if (bdFiles.Count > 1) { //reorder to proper location if (bdFiles[bdFiles.Count - 1] == "Bumbershoot.db") { bdFiles.RemoveAt(bdFiles.Count - 1); bdFiles.Insert(0, "Bumbershoot.db"); } var restorePath = Path.Combine(root, bdFiles[bdFiles.Count - 2]); var restoreFactory = CreateSessionFactory(restorePath, true); var restoreSession = restoreFactory.OpenSession(); var restoreJobs = restoreSession.QueryOver<HistoryItem>().List<HistoryItem>(); var restoredConfigs = new Dictionary<int,ConfigFile>(); //start restoring jobs foreach (var job in restoreJobs) { var newjob = new HistoryItem { Cpus = job.Cpus, CurrentStatus = job.CurrentStatus, EndTime = job.EndTime, JobName = job.JobName, JobType = job.JobType, OutputDirectory = job.OutputDirectory, ProteinDatabase = job.ProteinDatabase, RowNumber = job.RowNumber, SpectralLibrary = job.SpectralLibrary, StartTime = job.StartTime }; if (!restoredConfigs.ContainsKey(job.InitialConfigFile.ConfigId)) { var newConfig = new ConfigFile { DestinationProgram = job.InitialConfigFile.DestinationProgram, FilePath = job.InitialConfigFile.FilePath, FirstUsedDate = job.InitialConfigFile.FirstUsedDate, Name = job.InitialConfigFile.Name }; session.SaveOrUpdate(newConfig); session.Flush(); foreach (var property in job.InitialConfigFile.PropertyList) { var newProperty = new ConfigProperty { Name = property.Name, ConfigAssociation = newConfig, Type = property.Type, Value = property.Value }; session.SaveOrUpdate(newProperty); } session.Flush(); newjob.InitialConfigFile = newConfig; restoredConfigs.Add(job.InitialConfigFile.ConfigId, newConfig); } else newjob.InitialConfigFile = restoredConfigs[job.InitialConfigFile.ConfigId]; if (job.TagConfigFile != null) { if (!restoredConfigs.ContainsKey(job.TagConfigFile.ConfigId)) { var newConfig = new ConfigFile { DestinationProgram = job.TagConfigFile.DestinationProgram, FilePath = job.TagConfigFile.FilePath, FirstUsedDate = job.TagConfigFile.FirstUsedDate, Name = job.TagConfigFile.Name }; session.SaveOrUpdate(newConfig); session.Flush(); foreach (var property in job.TagConfigFile.PropertyList) { var newProperty = new ConfigProperty { Name = property.Name, ConfigAssociation = newConfig, Type = property.Type, Value = property.Value }; session.SaveOrUpdate(newProperty); } session.Flush(); newjob.TagConfigFile = newConfig; restoredConfigs.Add(job.TagConfigFile.ConfigId,newConfig); } else newjob.TagConfigFile = restoredConfigs[job.TagConfigFile.ConfigId]; } session.SaveOrUpdate(newjob); session.Flush(); foreach (var file in job.FileList) { var newFile = new InputFile {FilePath = file.FilePath, HistoryItem = newjob}; session.SaveOrUpdate(newFile); session.Flush(); } } } } } session.Close(); return newfactory; }
public List<HistoryItem> GetHistoryItems() { var hiList = new List<HistoryItem>(); var files = GetInputFileNames(); var outputDir = OutputDirectoryBox.Text; //generic hi setup var initialHi = new HistoryItem { JobName = NameBox.Text, OutputDirectory = newFolderBox.Checked ? outputDir + "+" : outputDir, ProteinDatabase = DatabaseLocBox.Text, Cpus = 0, CurrentStatus = string.Empty, StartTime = null, EndTime = null, RowNumber = 0, TagConfigFile = null, FileList = new List<InputFile>() }; foreach (var item in files) initialHi.FileList.Add(new InputFile { FilePath = item, HistoryItem = initialHi }); if (SearchTypeBox.Text == JobType.Library) { initialHi.JobType = JobType.Library; initialHi.SpectralLibrary = SpecLibBox.Text; initialHi.InitialConfigFile = GetConfigFile("Pepitome"); //HACK: Until fix gets pushed out Pepitome should only run with 1 cpu core initialHi.Cpus = 1; } else if (SearchTypeBox.Text == JobType.Tag) { initialHi.JobType = JobType.Tag; initialHi.InitialConfigFile = GetConfigFile("DirecTag"); initialHi.TagConfigFile = GetConfigFile("TagRecon"); } else if (SearchTypeBox.Text == JobType.Myrimatch) { var newOutput = initialHi.OutputDirectory; initialHi.JobType = JobType.Myrimatch; initialHi.InitialConfigFile = GetConfigFile("MyriMatch"); if (MyriActiveBox.Checked && newFolderBox.Checked) newOutput = Path.Combine(outputDir ?? string.Empty, NameBox.Text); var cometHi = new HistoryItem { JobType = JobType.Comet, OutputDirectory = newOutput, JobName = initialHi.JobName, ProteinDatabase = initialHi.ProteinDatabase, Cpus = 0, CurrentStatus = string.Empty, StartTime = null, EndTime = null, RowNumber = 0, InitialConfigFile = GetConfigFile("Comet"), FileList = new List<InputFile>() }; var msgfHi = new HistoryItem { JobType = JobType.MSGF, OutputDirectory = newOutput, JobName = initialHi.JobName, ProteinDatabase = initialHi.ProteinDatabase, Cpus = 0, CurrentStatus = string.Empty, StartTime = null, EndTime = null, RowNumber = 0, InitialConfigFile = GetConfigFile("MSGF"), FileList = new List<InputFile>() }; foreach (var item in files) { cometHi.FileList.Add(new InputFile { FilePath = item, HistoryItem = cometHi }); msgfHi.FileList.Add(new InputFile { FilePath = item, HistoryItem = msgfHi }); } if (CometActiveBox.Checked) hiList.Add(cometHi); if (MSGFActiveBox.Checked) hiList.Add(msgfHi); } else throw new Exception("None of the known search types were checked." + " Was there a new one added that hasn't been accounted for?"); if (SearchTypeBox.Text != JobType.Myrimatch || MyriActiveBox.Checked) hiList.Insert(0, initialHi); return hiList; }
/// <summary> /// Returns new history item from form /// </summary> /// <returns></returns> internal HistoryItem GetHistoryItem() { var hi = new HistoryItem { JobName = NameBox.Text, JobType = SearchTypeBox.Text, OutputDirectory = OutputDirectoryBox.Text + (newFolderBox.Checked ? "+" : string.Empty), ProteinDatabase = DatabaseLocBox.Text, SpectralLibrary = SearchTypeBox.Text == JobType.Library ? SpecLibBox.Text : null, Cpus = (int) CPUsBox.Value, CurrentStatus = string.Empty, StartTime = null, EndTime = null, RowNumber = 0, InitialConfigFile = GetConfigFile( SearchTypeBox.Text == JobType.Myrimatch ? "MyriMatch" : (SearchTypeBox.Text == JobType.Tag ? "DirecTag" : "Pepitome")), TagConfigFile = SearchTypeBox.Text == JobType.Tag ? GetConfigFile("TagRecon") : null }; //File List if (hi.FileList == null) hi.FileList = new List<InputFile>(); else hi.FileList.Clear(); var files = GetInputFileNames(); foreach (var item in files) hi.FileList.Add(new InputFile { FilePath = item, HistoryItem = hi }); return hi; }
/// <summary> /// Populates fields with recieved values /// </summary> /// <param name="hi"></param> private void SetHistoryItem(HistoryItem hi) { var fileList = hi.FileList.Select(file => file.FilePath).Distinct().ToList(); NameBox.Text = hi.JobName; CPUsBox.Value = hi.Cpus; if (hi.FileList.Count == 1 && hi.FileList[0].FilePath.StartsWith("!")) { InputMethodBox.Text = "File Mask"; var fullMask = hi.FileList[0].FilePath.Trim('!'); var initialDir = Path.GetDirectoryName(fullMask); var mask = Path.GetFileName(fullMask); InputDirectoryBox.Text = initialDir; FileMaskBox.Text = mask; } else { InputMethodBox.Text = "File List"; var usedFiles = GetInputFileNames(); foreach (var file in fileList) { if (usedFiles.Contains(file)) continue; var currentRow = InputFilesList.Rows.Count; var newItem = new[] { Path.GetFileName(file.Trim('"')) }; InputFilesList.Rows.Insert(currentRow, newItem); InputFilesList.Rows[currentRow].Cells[0].ToolTipText = file; } } DatabaseLocBox.Text = hi.ProteinDatabase; //Output directory handled differently depending on if new folder is/was created if (hi.OutputDirectory.EndsWith("+")) { //folder has not been made yet, just indicate it is to be made newFolderBox.Checked = true; OutputDirectoryBox.Text = hi.OutputDirectory.TrimEnd('+'); } else if (hi.OutputDirectory.EndsWith("*")) { //Folder has already been made, trim created folder and indicate new folder is to be made var baseDirectory = new DirectoryInfo(hi.OutputDirectory.TrimEnd('*')); newFolderBox.Checked = true; OutputDirectoryBox.Text = baseDirectory.Parent != null ? baseDirectory.Parent.FullName : hi.OutputDirectory.TrimEnd('*'); } else { newFolderBox.Checked = false; OutputDirectoryBox.Text = hi.OutputDirectory; } if (hi.JobType == JobType.Tag || (hi.JobType == null && hi.TagConfigFile != null)) { if (hi.InitialConfigFile.Name == null) DTConfigBox.Text = hi.InitialConfigFile.FilePath; else { DTConfigBox.Tag = "--Custom--"; DTConfigBox.Text = hi.InitialConfigFile.Name; } DirecTagInfoBox.Clear(); foreach (var property in hi.InitialConfigFile.PropertyList) DirecTagInfoBox.Text += string.Format("{0} = {1}{2}", property.Name, property.Value, Environment.NewLine); if (hi.TagConfigFile.Name == null) TRConfigBox.Text = hi.TagConfigFile.FilePath; else { TRConfigBox.Tag = "--Custom--"; TRConfigBox.Text = hi.TagConfigFile.Name; } TagReconInfoBox.Clear(); foreach (var property in hi.TagConfigFile.PropertyList) TagReconInfoBox.Text += string.Format("{0} = {1}{2}", property.Name, property.Value, Environment.NewLine); SearchTypeBox.Text = JobType.Tag; } else if (hi.JobType == JobType.Library || (hi.JobType == null && hi.SpectralLibrary != null)) { SpecLibBox.Text = hi.SpectralLibrary; if (hi.InitialConfigFile.Name == null) PepConfigBox.Text = hi.InitialConfigFile.FilePath; else { PepConfigBox.Tag = "--Custom--"; PepConfigBox.Text = hi.InitialConfigFile.Name; } PepitomeInfoBox.Clear(); foreach (var property in hi.InitialConfigFile.PropertyList) PepitomeInfoBox.Text += string.Format("{0} = {1}{2}", property.Name, property.Value, Environment.NewLine); SearchTypeBox.Text = JobType.Library; } else { if (hi.InitialConfigFile.Name == null) MyriConfigBox.Text = hi.InitialConfigFile.FilePath; else { MyriConfigBox.Tag = "--Custom--"; MyriConfigBox.Text = hi.InitialConfigFile.Name; } MyriMatchInfoBox.Clear(); foreach (var property in hi.InitialConfigFile.PropertyList) MyriMatchInfoBox.Text += string.Format("{0} = {1}{2}", property.Name, property.Value, Environment.NewLine); SearchTypeBox.Text = JobType.Myrimatch; } }
public static ISessionFactory CreateSessionFactory() { var currentGuiVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(3); var newdatabase = false; var root = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Bumberdash"); if (!Directory.Exists(root)) { Directory.CreateDirectory(root); } var dataFile = Path.Combine(root, "Bumbershoot " + currentGuiVersion + ".db"); var newfactory = CreateSessionFactory(dataFile, true); var session = newfactory.OpenSession(); //check that all preloaded templates are present if (session.QueryOver <ConfigFile>().List().Count < 16) { //check for presence of completely empty database if (session.QueryOver <HistoryItem>().List().Count == 0 && session.QueryOver <ConfigFile>().List().Count == 0) { newdatabase = true; } //load base database var baseRoot = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); if (baseRoot == null) { throw new Exception("Cannot find base database file"); } if (!File.Exists(Path.Combine(baseRoot, "lib\\Bumbershoot.db"))) { throw new Exception("Looking for \"" + Path.Combine(baseRoot, "lib\\Bumbershoot.db") + "\", however I cant find it"); } var baseFactory = CreateSessionFactory(Path.Combine(baseRoot, "lib\\Bumbershoot.db"), false); var baseSession = baseFactory.OpenSession(); //load base templates var connectedBaseConfigs = baseSession.QueryOver <ConfigFile>().List(); var baseConfigs = new List <ConfigFile>(); foreach (var config in connectedBaseConfigs) { var newInstrument = new ConfigFile { Name = config.Name, DestinationProgram = config.DestinationProgram, FilePath = config.FilePath, PropertyList = new List <ConfigProperty>() }; foreach (var property in config.PropertyList) { var newProperty = new ConfigProperty { ConfigAssociation = newInstrument, Name = property.Name, Type = property.Type, Value = property.Value }; newInstrument.PropertyList.Add(newProperty); } baseConfigs.Add(newInstrument); } //delete old templates (if any remain) and load base template foreach (var config in baseConfigs) { ConfigFile config1 = config; var deleteList = session.QueryOver <ConfigFile>() .Where(x => x.Name == config1.Name && x.DestinationProgram == config1.DestinationProgram) .List(); foreach (var item in deleteList) { session.Delete(item); } session.Flush(); var newInstrument = new ConfigFile() { Name = config.Name, DestinationProgram = config.DestinationProgram, FilePath = config.FilePath }; session.SaveOrUpdate(newInstrument); session.Flush(); foreach (var property in config.PropertyList) { var newProperty = new ConfigProperty() { ConfigAssociation = newInstrument, Name = property.Name, Type = property.Type, Value = property.Value }; session.SaveOrUpdate(newProperty); } session.Flush(); } //automatically try to recover old history items if database is flagged as new if (newdatabase) { //if database structure is ever changed this will need to be updated to include conversion (probably in the form of basic sqlite queries) var directoryInfo = new DirectoryInfo(root); var bdFiles = directoryInfo.GetFiles("Bumbershoot*.db").Select(file => file.Name).ToList(); bdFiles.Sort(); if (bdFiles.Count > 1) { //reorder to proper location if (bdFiles[bdFiles.Count - 1] == "Bumbershoot.db") { bdFiles.RemoveAt(bdFiles.Count - 1); bdFiles.Insert(0, "Bumbershoot.db"); } var restorePath = Path.Combine(root, bdFiles[bdFiles.Count - 2]); var restoreFactory = CreateSessionFactory(restorePath, true); var restoreSession = restoreFactory.OpenSession(); var restoreJobs = restoreSession.QueryOver <HistoryItem>().List <HistoryItem>(); var restoredConfigs = new Dictionary <int, ConfigFile>(); //start restoring jobs foreach (var job in restoreJobs) { var newjob = new HistoryItem { Cpus = job.Cpus, CurrentStatus = job.CurrentStatus, EndTime = job.EndTime, JobName = job.JobName, JobType = job.JobType, OutputDirectory = job.OutputDirectory, ProteinDatabase = job.ProteinDatabase, RowNumber = job.RowNumber, SpectralLibrary = job.SpectralLibrary, StartTime = job.StartTime }; if (!restoredConfigs.ContainsKey(job.InitialConfigFile.ConfigId)) { var newConfig = new ConfigFile { DestinationProgram = job.InitialConfigFile.DestinationProgram, FilePath = job.InitialConfigFile.FilePath, FirstUsedDate = job.InitialConfigFile.FirstUsedDate, Name = job.InitialConfigFile.Name }; session.SaveOrUpdate(newConfig); session.Flush(); foreach (var property in job.InitialConfigFile.PropertyList) { var newProperty = new ConfigProperty { Name = property.Name, ConfigAssociation = newConfig, Type = property.Type, Value = property.Value }; session.SaveOrUpdate(newProperty); } session.Flush(); newjob.InitialConfigFile = newConfig; restoredConfigs.Add(job.InitialConfigFile.ConfigId, newConfig); } else { newjob.InitialConfigFile = restoredConfigs[job.InitialConfigFile.ConfigId]; } if (job.TagConfigFile != null) { if (!restoredConfigs.ContainsKey(job.TagConfigFile.ConfigId)) { var newConfig = new ConfigFile { DestinationProgram = job.TagConfigFile.DestinationProgram, FilePath = job.TagConfigFile.FilePath, FirstUsedDate = job.TagConfigFile.FirstUsedDate, Name = job.TagConfigFile.Name }; session.SaveOrUpdate(newConfig); session.Flush(); foreach (var property in job.TagConfigFile.PropertyList) { var newProperty = new ConfigProperty { Name = property.Name, ConfigAssociation = newConfig, Type = property.Type, Value = property.Value }; session.SaveOrUpdate(newProperty); } session.Flush(); newjob.TagConfigFile = newConfig; restoredConfigs.Add(job.TagConfigFile.ConfigId, newConfig); } else { newjob.TagConfigFile = restoredConfigs[job.TagConfigFile.ConfigId]; } } session.SaveOrUpdate(newjob); session.Flush(); foreach (var file in job.FileList) { var newFile = new InputFile { FilePath = file.FilePath, HistoryItem = newjob }; session.SaveOrUpdate(newFile); session.Flush(); } } } } } session.Close(); return(newfactory); }
public void SetHistoryItem(HistoryItem recievedHi) { ModBox.Rows.Clear(); //set generic values first if (!string.IsNullOrEmpty(recievedHi.JobName)) OutputNewFolderBox.Text = recievedHi.JobName; if (!string.IsNullOrEmpty(recievedHi.ProteinDatabase)) DatabaseBox.Text = recievedHi.ProteinDatabase; if (!string.IsNullOrEmpty(recievedHi.SpectralLibrary)) LibraryBox.Text = recievedHi.SpectralLibrary; if (!string.IsNullOrEmpty(recievedHi.OutputDirectory)) { if (recievedHi.OutputDirectory.EndsWith("+") || recievedHi.OutputDirectory.EndsWith("*")) OutputNewCheckBox.Checked = true; OutputFolderBox.Text = recievedHi.OutputDirectory.EndsWith("*") ? Path.GetDirectoryName(recievedHi.OutputDirectory.TrimEnd('*')) : recievedHi.OutputDirectory.TrimEnd('+'); } if (recievedHi.FileList != null) foreach (var file in recievedHi.FileList) { if (file.FilePath.StartsWith("!")) { InputDirectoryBox.Text = Path.GetDirectoryName(file.FilePath.TrimStart('!')); try { var mask = Path.GetFileName(file.FilePath.TrimStart('!')); if (mask.ToLower().Contains(".mz5")) mz5Radio.Checked = true; else if (mask.ToLower().Contains(".mzml")) mzMLRadio.Checked = true; else if (mask.ToLower().Contains(".mzxml")) mzXMLRadio.Checked = true; else if (mask.ToLower().Contains(".mgf")) mgfRadio.Checked = true; else if (mask.ToLower().Contains(".raw")) rawRadio.Checked = true; else if (mask.ToLower().Contains(".d")) dRadio.Checked = true; } catch { //ignore, let the user figure out why folder doesn't contain the right files } continue; } InputFilesList.Rows.Add(new object[]{file.FilePath}); } if (recievedHi.JobType == JobType.Myrimatch) { DBRadio.Checked = true; MyriBox.Checked = true; } else if (recievedHi.JobType == JobType.Comet) { DBRadio.Checked = true; MyriBox.Checked = false; CometBox.Checked = true; } else if (recievedHi.JobType == JobType.MSGF) { DBRadio.Checked = true; MyriBox.Checked = false; MSGFBox.Checked = true; } else if (recievedHi.JobType == JobType.Tag) TagRadio.Checked = true; else if (recievedHi.JobType == JobType.Library) PepRadio.Checked = true; //get program-specific parameters var configFile = recievedHi.InitialConfigFile.PropertyList; if (recievedHi.JobType == JobType.Tag) configFile = recievedHi.TagConfigFile.PropertyList; if (recievedHi.JobType == JobType.Myrimatch || recievedHi.JobType == JobType.Tag || recievedHi.JobType == JobType.Library) { var currentParam = configFile.FirstOrDefault(x => x.Name == "OutputSuffix"); if (currentParam != null) { SuffixBox.Checked = true; PrimarySuffixBox.Text = currentParam.Value.Trim('"'); } currentParam = configFile.FirstOrDefault(x => x.Name == "CleavageRules"); if (currentParam != null) CleavageAgentBox.Text = currentParam.Value.Trim('"'); currentParam = configFile.FirstOrDefault(x => x.Name == "MinTerminiCleavages"); if (currentParam != null) { int value; if (int.TryParse(currentParam.Value, out value)) SpecificityBox.SelectedIndex = value; } currentParam = configFile.FirstOrDefault(x => x.Name == "ExplainUnknownMassShiftsAs"); if (recievedHi.JobType == JobType.Tag && currentParam != null) BlindModBox.Checked = currentParam.Value.Trim('"') == "blindptms"; //tolerances currentParam = recievedHi.JobType == JobType.Tag ? configFile.FirstOrDefault(x => x.Name == "PrecursorMzTolerance") : configFile.FirstOrDefault(x => x.Name == "MonoPrecursorMzTolerance"); var precursor = string.Empty; var precursorUnit = string.Empty; if (currentParam != null) { double value; if (currentParam.Value.Trim('"').EndsWith("mz") && double.TryParse(currentParam.Value.Trim('"').Replace("mz", string.Empty),NumberStyles.Number,CultureInfo.InvariantCulture, out value)) { PrecursorLowRadio.Checked = true; precursor = value.ToString(); precursorUnit = "mz"; } else if (currentParam.Value.Trim('"').EndsWith("ppm") && double.TryParse(currentParam.Value.Trim('"').Replace("ppm", string.Empty), NumberStyles.Number, CultureInfo.InvariantCulture, out value)) { if (value > 15) PrecursorMidRadio.Checked = true; else PrecursorHighRadio.Checked = true; precursor = value.ToString(); precursorUnit = "ppm"; } } currentParam = configFile.FirstOrDefault(x => x.Name == "FragmentMzTolerance"); if (currentParam != null) { double value; if (currentParam.Value.Trim('"').EndsWith("mz") && double.TryParse(currentParam.Value.Trim('"').Replace("mz", string.Empty), NumberStyles.Number, CultureInfo.InvariantCulture, out value)) { FragmentLowRadio.Checked = true; FragmentToleranceBox.Text = value.ToString(); FragmentToleranceUnitsBox.Text = "mz"; } else if (currentParam.Value.Trim('"').EndsWith("ppm") && double.TryParse(currentParam.Value.Trim('"').Replace("ppm", string.Empty), NumberStyles.Number, CultureInfo.InvariantCulture, out value)) { if (value > 30) FragmentMidRadio.Checked = true; else FragmentHighRadio.Checked = true; FragmentToleranceBox.Text = value.ToString(); FragmentToleranceUnitsBox.Text = "ppm"; } } if (!string.IsNullOrEmpty(precursor)) PrecursorToleranceBox.Text = precursor; if (!string.IsNullOrEmpty(precursorUnit)) PrecursorToleranceUnitsBox.Text = precursorUnit; //mods currentParam = configFile.FirstOrDefault(x => x.Name == "StaticMods"); if (currentParam != null) { var splitString = currentParam.Value.Trim('"').Split(); for (var x = 0; x + 1 < splitString.Length; x += 2) { double mass; if (!double.TryParse(splitString[x + 1], NumberStyles.Number, CultureInfo.InvariantCulture, out mass)) continue; ModBox.Rows.Add(new object[] { splitString[x], mass, "Static" }); } } currentParam = configFile.FirstOrDefault(x => x.Name == "DynamicMods"); if (currentParam != null) { var splitString = currentParam.Value.Trim('"').Split(); for (var x = 0; x + 2 < splitString.Length; x += 3) { double mass; if (!double.TryParse(splitString[x + 2], NumberStyles.Number, CultureInfo.InvariantCulture, out mass)) continue; ModBox.Rows.Add(new object[] { splitString[x], mass, "Dynamic" }); } } } else if (recievedHi.JobType == JobType.Comet) { var currentParam = configFile.FirstOrDefault(x => x.Name.ToLower() == "config"); if (currentParam == null) return; var cometConfig = CometHandler.FileContentsToCometParams(currentParam.Value); CometSuffixBox.Text = cometConfig.OutputSuffix; CleavageAgentBox.Text = CometParams.CleavageAgentOptions.First(x=>x.Value == cometConfig.CleavageAgent).Key; SpecificityBox.SelectedIndex = cometConfig.Specificity; //tolerance if (cometConfig.FragmentBinTolerance > 0.5) FragmentLowRadio.Checked = true; else FragmentHighRadio.Checked = true; if (cometConfig.PrecursorUnit == CometParams.PrecursorUnitOptions.Daltons) { PrecursorLowRadio.Checked = true; PrecursorToleranceUnitsBox.Text = "mz"; } else { PrecursorHighRadio.Checked = true; PrecursorToleranceUnitsBox.Text = "ppm"; } PrecursorToleranceBox.Text = cometConfig.PrecursorTolerance.ToString(); //mods if (cometConfig.StaticCysteineMod > 0) ModBox.Rows.Add(new object[] {"C", cometConfig.StaticCysteineMod, "Static"}); foreach (var mod in cometConfig.DynamicModifications) { if (mod.Residue == "X") continue; var residue = (mod.isNterminal() ? "(" : string.Empty) + mod.Residue.Replace("*", string.Empty) + (mod.isCterminal() ? ")" : string.Empty); ModBox.Rows.Add(new object[] {residue, mod.MassChange, "Dynamic"}); } } else if (recievedHi.JobType == JobType.MSGF) { var currentParam = configFile.FirstOrDefault(x => x.Name.ToLower() == "config"); if (currentParam == null) return; var msgfConfig = MSGFHandler.OverloadToMSGFParams(currentParam.Value); currentParam = configFile.FirstOrDefault(x => x.Name.ToLower() == "mods"); if (currentParam == null) return; var msgfMods = MSGFHandler.ModStringToModList(currentParam.Value); CometSuffixBox.Text = msgfConfig.OutputSuffix; CleavageAgentBox.Text = MSGFParams.CleavageAgentOptions.First(x => x.Value == msgfConfig.CleavageAgent).Key; SpecificityBox.SelectedIndex = msgfConfig.Specificity; ////tolerance //if (msgfConfig.FragmentationMethod == MSGFParams.FragmentationMethodOptions.CID) // FragmentLowRadio.Checked = true; //else // FragmentHighRadio.Checked = true; if (msgfConfig.PrecursorToleranceUnits == MSGFParams.PrecursorToleranceUnitOptions.Daltons) { PrecursorLowRadio.Checked = true; PrecursorToleranceUnitsBox.Text = "mz"; } else { PrecursorHighRadio.Checked = true; PrecursorToleranceUnitsBox.Text = "ppm"; } PrecursorToleranceBox.Text = msgfConfig.PrecursorTolerance.ToString(); //mods foreach (var mod in msgfMods) ModBox.Rows.Add(new object[] {mod.Residue, mod.Mass, mod.Type}); } }
private void ConfigWizard_Load(object sender, EventArgs e) { //set up panel reference _panelReference = new Dictionary<int, Panel>(); var index = 1; var indexSet = new HashSet<int>(); foreach (Panel panel in splitContainer1.Panel1.Controls.Cast<Panel>().ToList().OrderBy(x=>x.TabIndex)) { //Note, panel order is determined by TabIndex if (!indexSet.Add(panel.TabIndex)) throw new Exception("Duplicate panel index found. "+ "If this error is encountered outside development please contact "+ "the person in charge of BumberDash upkeep."); _panelReference.Add(index, panel); index++; } _finalPanel = _panelReference.Count; //set default values ModTypeBox.Text = "Dynamic"; PrecursorToleranceUnitsBox.Text = "ppm"; FragmentToleranceUnitsBox.Text = "ppm"; SpecificityBox.Text = "Fully-Specific"; ModBox.Rows.Add(new object[] {"C", 57.021464.ToString(), "Static"}); ModBox.Rows.Add(new object[] { "M", 15.994915.ToString(), "Dynamic" }); DBSavedBrowse.Enabled = (!string.IsNullOrEmpty(Properties.Settings.Default.DatabaseFolder) && Directory.Exists(Properties.Settings.Default.DatabaseFolder)); LibSavedBrowse.Enabled = (!string.IsNullOrEmpty(Properties.Settings.Default.LibraryFolder) && Directory.Exists(Properties.Settings.Default.LibraryFolder)); //set up unimod suggestions var uniModSuggestions = new List<string>(); foreach (var item in Util.UnimodLookup.FullUnimodList) uniModSuggestions.Add(item.MonoMass + " " + item.Name); var source = new AutoCompleteStringCollection(); source.AddRange(uniModSuggestions.ToArray()); ModMassBox.AutoCompleteMode = AutoCompleteMode.Suggest; ModMassBox.AutoCompleteSource = AutoCompleteSource.CustomSource; ModMassBox.AutoCompleteCustomSource = source; ModMassBox.TextChanged += (x, y) => { if (ModMassBox.Text.Contains(" ")) ModMassBox.Text = ModMassBox.Text.Remove(ModMassBox.Text.IndexOf(' ')); }; foreach (var kvp in _panelReference) { if (kvp.Key == _currentPanel) { kvp.Value.Dock = DockStyle.Fill; kvp.Value.Visible = true; continue; } kvp.Value.Visible = false; kvp.Value.Dock = DockStyle.None; } if (_currentJob == null) _currentJob = new HistoryItem(); else SetHistoryItem(_currentJob); }
public ConfigWizard(IList<ConfigFile> templateList) { InitializeComponent(); _currentJob = null; _templateList = templateList; }
/// <summary> /// Starts Bumbershoot utility based on current row and destination program /// </summary> private void ProcessJob(HistoryItem hi) { var argumentString = new StringBuilder(); string configString; _killed = false; ProcessStartInfo psi; if (hi.Cpus > 0) argumentString.Append(string.Format("-cpus {0} ", hi.Cpus)); var workingDirectory = hi.OutputDirectory.TrimEnd('*'); switch (_destinationProgram) { case "MyriMatch": //Set location of the program psi = new ProcessStartInfo(String.Format(@"""{0}\lib\Bumbershoot\MyriMatch\myrimatch.exe""", AppDomain.CurrentDomain.BaseDirectory)); //determine configuration configString = hi.InitialConfigFile.FilePath == "--Custom--" ? PropertyListToOverrideString(hi.InitialConfigFile.PropertyList) : string.Format("-cfg \"{0}\" ", hi.InitialConfigFile.FilePath); //continue to set up argument string argumentString.Append(String.Format("{0}-ProteinDatabase \"{1}\"", configString, hi.ProteinDatabase)); //add files to scan to argument string if (hi.FileList.Count == 1 && hi.FileList[0].FilePath.StartsWith("!")) { var fullMask = hi.FileList[0].FilePath.Trim('!'); var initialDir = Path.GetDirectoryName(fullMask); var mask = Path.GetFileName(fullMask); var maskedFiles = Directory.GetFiles(initialDir, mask); argumentString.Append(String.Format(" \"{0}\"", fullMask)); _filesToProcess = maskedFiles.Length; } else foreach (var file in hi.FileList) { argumentString.Append(String.Format(" {0}", file.FilePath)); _filesToProcess++; } break; case "DirecTag": //Set location of the program psi = new ProcessStartInfo(String.Format(@"""{0}\lib\Bumbershoot\DirecTag\directag.exe""", AppDomain.CurrentDomain.BaseDirectory)); //determine configuration configString = hi.InitialConfigFile.FilePath == "--Custom--" ? PropertyListToOverrideString(hi.InitialConfigFile.PropertyList) : string.Format("-cfg \"{0}\" ", hi.InitialConfigFile.FilePath); //HACK: Remove when deisotoping is usable configString += string.Format("-{0} {1} ", "DeisotopingMode", "0"); //continue to set up argument string argumentString.Append(configString.Trim()); //add files to scan to argument string _direcTagMask = null; if (hi.FileList.Count == 1 && hi.FileList[0].FilePath.StartsWith("!")) { var fullMask = hi.FileList[0].FilePath.Trim('!'); _direcTagMask = fullMask; var initialDir = Path.GetDirectoryName(fullMask); var mask = Path.GetFileName(fullMask); var maskedFiles = Directory.GetFiles(initialDir, mask); argumentString.Append(String.Format(" \"{0}\"", fullMask)); _filesToProcess = maskedFiles.Length; } else foreach (var file in hi.FileList) { argumentString.Append(String.Format(" {0}", file.FilePath)); _filesToProcess++; } break; case "TagRecon": //Set location of the program psi = new ProcessStartInfo(String.Format(@"""{0}\lib\Bumbershoot\TagRecon\tagrecon.exe""", AppDomain.CurrentDomain.BaseDirectory)); //determine configuration if (hi.TagConfigFile.FilePath == "--Custom--") { configString = PropertyListToOverrideString(hi.TagConfigFile.PropertyList); //use intranal blosum and unimod files if not specified if (!configString.Contains("-Blosum ")) configString += string.Format("-{0} \"{1}\" ", "Blosum", Path.Combine( AppDomain.CurrentDomain.BaseDirectory, @"lib\Bumbershoot\TagRecon\blosum62.fas")); if (!configString.Contains("UnimodXML")) configString += string.Format("-{0} \"{1}\" ", "UnimodXML", Path.Combine( AppDomain.CurrentDomain.BaseDirectory, @"lib\Bumbershoot\TagRecon\unimod.xml")); } else { configString = string.Format("-cfg \"{0}\" ", hi.TagConfigFile.FilePath); var configCheck = new StreamReader(hi.TagConfigFile.FilePath); var entireFile = configCheck.ReadToEnd(); configCheck.Close(); if (!entireFile.Contains("Blosum =")) configString += string.Format("-{0} \"{1}\" ", "Blosum", Path.Combine( AppDomain.CurrentDomain.BaseDirectory, @"lib\Bumbershoot\TagRecon\blosum62.fas")); if (!entireFile.Contains("UnimodXML =")) configString += string.Format("-{0} \"{1}\" ", "UnimodXML", Path.Combine( AppDomain.CurrentDomain.BaseDirectory, @"lib\Bumbershoot\TagRecon\unimod.xml")); } //continue to set up argument string argumentString.Append(String.Format("{0}-ProteinDatabase \"{1}\"", configString, hi.ProteinDatabase)); //add files to scan to argument string foreach (var file in _completedFiles) { argumentString.AppendFormat(" \"{0}\"", Path.Combine(hi.OutputDirectory.TrimEnd('*'), file)); _filesToProcess++; } break; case "Pepitome": //Set location of the program psi = new ProcessStartInfo(String.Format(@"""{0}\lib\Bumbershoot\Pepitome\pepitome.exe""", AppDomain.CurrentDomain.BaseDirectory)); //determine configuration configString = hi.InitialConfigFile.FilePath == "--Custom--" ? PropertyListToOverrideString(hi.InitialConfigFile.PropertyList) : string.Format("-cfg \"{0}\" ", hi.InitialConfigFile.FilePath); //continue to set up argument string argumentString.Append(String.Format("{0}-ProteinDatabase \"{1}\" -SpectralLibrary \"{2}\"", configString, hi.ProteinDatabase, hi.SpectralLibrary)); //add files to scan to argument string if (hi.FileList.Count == 1 && hi.FileList[0].FilePath.StartsWith("!")) { var fullMask = hi.FileList[0].FilePath.Trim('!'); var initialDir = Path.GetDirectoryName(fullMask); var mask = Path.GetFileName(fullMask); var maskedFiles = Directory.GetFiles(initialDir, mask); argumentString.Append(String.Format(" \"{0}\"", fullMask)); _filesToProcess = maskedFiles.Length; } else foreach (var file in hi.FileList) { argumentString.Append(String.Format(" {0}", file.FilePath)); _filesToProcess++; } break; default: //should never be called, throw error if it is throw new Exception(String.Format("Destination Program not set to known value: {0}", _destinationProgram)); } psi.WorkingDirectory = workingDirectory; psi.Arguments = argumentString.ToString(); var commandGiven = (string.Format("Command given:{0}{1}>{2} {3}{0}{0}", Environment.NewLine, psi.WorkingDirectory, psi.FileName, psi.Arguments)); SendToLog(commandGiven); //Make sure window stays hidden psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; psi.UseShellExecute = false; psi.CreateNoWindow = true; _runningProgram = new Process { StartInfo = psi, EnableRaisingEvents = true }; _runningProgram.Start(); _runningProgram.PriorityClass = ProcessPriorityClass.BelowNormal; _runningProgram.BeginOutputReadLine(); _runningProgram.OutputDataReceived += DataReceived; _runningProgram.BeginErrorReadLine(); _runningProgram.ErrorDataReceived += ErrorCaught; _runningProgram.Exited += (x, y) => { var bgWait = new BackgroundWorker(); bgWait.DoWork += (zzz, e) => { SendToLog(" ---Program exit detected---"); Thread.Sleep(100); SendToLog(" ---Calculating results---"); var a = ((object[])e.Argument)[0]; var b = (EventArgs)((object[])e.Argument)[1]; ProgramExited(a, b); }; bgWait.RunWorkerAsync(new object[] { x, y }); //ProgramExited(x,y); }; }
private void RunFile(string neededFile, string neededDB, string neededLibrary, string destinationProgram) { log= new StringBuilder(); var errorFound = false; var waitHandle = new AutoResetEvent(false); var target = new ProgramHandler(); var hi = new HistoryItem { JobName = Path.GetDirectoryName(neededFile), JobType = destinationProgram, OutputDirectory = _outputDirectory, ProteinDatabase = neededDB, SpectralLibrary = destinationProgram == JobType.Library ? neededLibrary : null, Cpus = 0, CurrentStatus = string.Empty, StartTime = null, EndTime = null, RowNumber = 0, InitialConfigFile = new ConfigFile() { FilePath = "--Custom--", PropertyList = new List<ConfigProperty>() }, TagConfigFile = destinationProgram == JobType.Tag ? new ConfigFile() { FilePath = "--Custom--", PropertyList = new List<ConfigProperty>() } : null }; //File List hi.FileList = new List<InputFile> { new InputFile { FilePath = "\"" + neededFile + "\"", HistoryItem = hi } }; //set end event target.JobFinished = (x, y) => { errorFound = y; if (!errorFound && x) target.StartNewJob(0, hi); else waitHandle.Set(); // signal that the finished event was raised }; target.LogUpdate = x => log.AppendLine(x); target.ErrorForward = x => log.AppendLine(x); // call the async method target.StartNewJob(0, hi); // Wait until the event handler is invoked); if (!waitHandle.WaitOne(60000, false)) { var logstring1 = log.ToString(); if (logstring1 != "Test Case") Assert.Fail("Test timed out." + Environment.NewLine + logstring1); } var logstring = log.ToString(); Assert.IsFalse(errorFound, "Not as many output files as input" + Environment.NewLine + logstring); }
/// <summary> /// Show AddJobForm with given properties already filled out /// </summary> /// <param name="oldHi"></param> private void ShowCloneBox(HistoryItem oldHi) { var templateList = _session.QueryOver<ConfigFile>().Where(x => x.FilePath == "Template").List(); var addJob = new ConfigWizard(oldHi, templateList, false); if (addJob.ShowDialog() == DialogResult.OK) { var items = addJob.GetHistoryItems(); foreach (var hi in items) InsertRowFromHistoryItem(hi, JobQueueDGV.Rows.Count - 1); _programmaticallyPaused = false; } CheckForRunableJob(); }
/// <summary> /// Adds job based on given HistoryItem /// </summary> /// <param name="hi"></param> /// <param name="row"></param> private void InsertRowFromHistoryItem(HistoryItem hi, int row) { //Fill in job type if needed if (hi.JobType == null) { hi.JobType = hi.TagConfigFile == null ? JobType.Myrimatch : JobType.Tag; lock (_session) { _session.Save(hi); _session.Flush(); } } #region Check for duplicate config files //Check initial config file var oldConfigList = _session.QueryOver<ConfigFile>(). Where(x => x.FilePath == hi.InitialConfigFile.FilePath && x.DestinationProgram == hi.InitialConfigFile.DestinationProgram).OrderBy(y => y.FirstUsedDate).Asc.List(); //Hack: initialize used by list to keep it from being deleted //on program close (if job has not finished) hi.InitialConfigFile.UsedByList = new List<HistoryItem> { hi }; hi.InitialConfigFile.FirstUsedDate = DateTime.Now; foreach (var item in oldConfigList) { var foundDuplicate = true; if (item.PropertyList.Count == hi.InitialConfigFile.PropertyList.Count) { for (var oldProperty = 0; oldProperty < item.PropertyList.Count; oldProperty++) { var property = item.PropertyList[oldProperty]; var otherPropertyList = hi.InitialConfigFile.PropertyList.Where( x => (x.Name == property.Name && x.Value == property.Value)).ToList(); var otherProperty = otherPropertyList.Any() ? otherPropertyList[0] : null; if (otherProperty == null) { foundDuplicate = false; break; } } } else foundDuplicate = false; if (foundDuplicate) { hi.InitialConfigFile = item; break; } } //Check tag config file if (hi.TagConfigFile != null) { oldConfigList = _session.QueryOver<ConfigFile>(). Where(x => x.FilePath == hi.TagConfigFile.FilePath && x.DestinationProgram == hi.TagConfigFile.DestinationProgram).OrderBy(y => y.FirstUsedDate).Asc.List(); //Hack: initialize used by list to keep it from being deleted //on program close (if job has not finished) hi.TagConfigFile.UsedByList = new List<HistoryItem> { hi }; hi.TagConfigFile.FirstUsedDate = DateTime.Now; foreach (var item in oldConfigList) { var foundDuplicate = true; if (item.PropertyList.Count == hi.TagConfigFile.PropertyList.Count) { for (var oldProperty = 0; oldProperty < item.PropertyList.Count; oldProperty++) { var property = item.PropertyList[oldProperty]; var otherPropertyList = hi.InitialConfigFile.PropertyList.Where( x => (x.Name == property.Name && x.Value == property.Value)).ToList(); var otherProperty = otherPropertyList.Any() ? otherPropertyList[0] : null; if (otherProperty == null) { foundDuplicate = false; break; } } } else foundDuplicate = false; if (foundDuplicate) { hi.TagConfigFile = item; break; } } } #endregion var values = new object[6]; //fill values list with appropriate info values[0] = hi.JobName; values[1] = (new DirectoryInfo(hi.OutputDirectory.TrimEnd('+').TrimEnd('*'))).Name; if (hi.JobType == JobType.Library) values[2] = string.Format("{0} / {1}", Path.GetFileName(hi.ProteinDatabase), Path.GetFileName(hi.SpectralLibrary)); else values[2] = Path.GetFileName(hi.ProteinDatabase); if (hi.TagConfigFile != null) { values[3] = String.Format("{0} / {1}", hi.InitialConfigFile.Name ?? Path.GetFileNameWithoutExtension(hi.InitialConfigFile.FilePath), hi.TagConfigFile.Name ?? Path.GetFileNameWithoutExtension(hi.TagConfigFile.FilePath)); values[4] = JobType.Tag; } else { values[3] = hi.InitialConfigFile.Name ?? Path.GetFileNameWithoutExtension(hi.InitialConfigFile.FilePath); values[4] = hi.JobType; } if (hi.CurrentStatus == "Finished") values[5] = 100; else values[5] = 0; //Add row and set current status JobQueueDGV.Rows.Insert(row, values); JobQueueDGV.Rows[row].Tag = hi.CurrentStatus; //Adjust row appearance if status is special if (hi.CurrentStatus == "Locked") for (int x = 0; x < 6; x++) JobQueueDGV.Rows[row].Cells[x].Style.BackColor = Color.Wheat; else if (hi.CurrentStatus == "Unsuccessful") JobQueueDGV[5, row].Style.BackColor = Color.LightPink; //Add tooltip to name cell listing file names var tempString = string.Empty; foreach (var i in hi.FileList) tempString += i.FilePath + Environment.NewLine; tempString = tempString.Trim(); JobQueueDGV.Rows[row].Cells[0].ToolTipText = tempString; //Hold on to history item for future use JobQueueDGV.Rows[row].Cells[0].Tag = hi; //Add full output directory to tooltip JobQueueDGV.Rows[row].Cells[1].ToolTipText = hi.OutputDirectory; //Myrimatch File Name JobQueueDGV.Rows[row].Cells[2].ToolTipText = hi.ProteinDatabase + (hi.SpectralLibrary == null ? string.Empty : Environment.NewLine + hi.SpectralLibrary); //Configs bool databaseCustom = hi.InitialConfigFile.FilePath == "--Custom--"; if (hi.TagConfigFile != null) { bool tagCustom = hi.TagConfigFile.FilePath == "--Custom--"; JobQueueDGV.Rows[row].Cells[3].ToolTipText = string.Format("{0}{1}{2}{1}{3}", databaseCustom ? CreatePropertyStringFromConfig(hi.InitialConfigFile) : hi.InitialConfigFile.FilePath, Environment.NewLine, new string('-', 20), tagCustom ? CreatePropertyStringFromConfig(hi.TagConfigFile) : hi.TagConfigFile.FilePath); } else JobQueueDGV.Rows[row].Cells[3].ToolTipText = databaseCustom ? CreatePropertyStringFromConfig(hi.InitialConfigFile) : hi.InitialConfigFile.FilePath; //last button JobQueueDGV.Rows[row].Cells[6].Value = "X"; hi.RowNumber = row; _session.SaveOrUpdate(hi.InitialConfigFile); if (hi.TagConfigFile != null) _session.SaveOrUpdate(hi.TagConfigFile); _session.SaveOrUpdate(hi); _session.Flush(); }