private void CometConfigBrowse_Click(object sender, EventArgs e) { var fileLoc = new OpenFileDialog { InitialDirectory = OutputDirectoryBox.Text, RestoreDirectory = true, Filter = "Config Files|*.params|All files|*.*", CheckFileExists = true, CheckPathExists = true, Multiselect = false, Title = "Comet config file location" }; if (fileLoc.ShowDialog() == DialogResult.OK) { var newConfig = new ConfigFile { Name = Path.GetFileName(fileLoc.FileName), FilePath = fileLoc.FileName, DestinationProgram = "Comet" }; CometConfigBox.Tag = newConfig; CometConfigBox.Text = newConfig.Name; } }
public static ConfigFile PepXMLToCustomConfig(string file, string destinationProgram) { var newConfig = new ConfigFile { DestinationProgram = destinationProgram, Name = Path.GetFileName(file), PropertyList = new List<ConfigProperty>() }; var parameterTypes = Util.parameterTypes; var cutFile = string.Empty; var fileStream = new StreamReader(file); while (!fileStream.EndOfStream) { var tempString = fileStream.ReadLine() ?? string.Empty; if (tempString.Contains("<parameter name=\"Config:")) cutFile += tempString + System.Environment.NewLine; else if (cutFile.Length > 0) break; } fileStream.Close(); var entireLine = cutFile.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); string[] propertySplit; for (int x = 0; x < entireLine.Length; x++) { //get the two meaningful values entireLine[x] = entireLine[x].Replace("<parameter name=\"Config:", " "); entireLine[x] = entireLine[x].Replace("\" value=", " "); entireLine[x] = entireLine[x].Replace("/>", " "); propertySplit = entireLine[x].Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); propertySplit[0] = propertySplit[0].Trim(); propertySplit[1] = propertySplit[1].Trim(); //check if value is actually meaningful to the editor if (parameterTypes.ContainsKey(propertySplit[0])) { if (parameterTypes[propertySplit[0]] == "bool") { propertySplit[1] = propertySplit[1].Trim('\"'); propertySplit[1] = Convert.ToBoolean(int.Parse(propertySplit[1])).ToString().ToLower(); newConfig.PropertyList.Add(new ConfigProperty { Name = propertySplit[0], Value = propertySplit[1], Type = parameterTypes[propertySplit[0]] }); } else if (parameterTypes[propertySplit[0]] == "int" || parameterTypes[propertySplit[0]] == "double") { propertySplit[1] = propertySplit[1].Trim('\"'); newConfig.PropertyList.Add(new ConfigProperty { Name = propertySplit[0], Value = propertySplit[1], Type = parameterTypes[propertySplit[0]] }); } else if (parameterTypes[propertySplit[0]] == "string") { if (propertySplit.Length > 2) { for (int i = 2; i < propertySplit.Length; i++) propertySplit[1] += " " + propertySplit[i]; } newConfig.PropertyList.Add(new ConfigProperty { Name = propertySplit[0], Value = propertySplit[1], Type = parameterTypes[propertySplit[0]] }); } } } return newConfig; }
private ConfigFile GetConfigFile(string destinationProgram) { if (destinationProgram == "MyriMatch" || destinationProgram == "DirecTag" || destinationProgram == "TagRecon" || destinationProgram == "Pepitome") { var config = new ConfigFile() { DestinationProgram = destinationProgram, PropertyList = new List<ConfigProperty>(), FilePath = "--Custom--" }; var tolerance = double.Parse(PrecursorToleranceBox.Text); if (destinationProgram == "DirecTag") { if (PrecursorToleranceUnitsBox.Text == "ppm") tolerance /= 1000; config.PropertyList.Add(new ConfigProperty { Name = "PrecursorMzTolerance", Value = tolerance.ToString(CultureInfo.InvariantCulture), Type = "string", ConfigAssociation = config }); } else if (destinationProgram == "TagRecon") config.PropertyList.Add(new ConfigProperty { Name = "PrecursorMzTolerance", Value = "\"" + tolerance.ToString(CultureInfo.InvariantCulture) + PrecursorToleranceUnitsBox.Text + "\"", Type = "string", ConfigAssociation = config }); else config.PropertyList.Add(new ConfigProperty { Name = "MonoPrecursorMzTolerance", Value = "\"" + tolerance.ToString(CultureInfo.InvariantCulture) + PrecursorToleranceUnitsBox.Text + "\"", Type = "string", ConfigAssociation = config }); if (!destinationProgram.Contains("Tag") && PrecursorToleranceUnitsBox.Text == "mz" && double.Parse(PrecursorToleranceBox.Text) > 0.2) config.PropertyList.Add(new ConfigProperty { Name = "MonoisotopeAdjustmentSet", Value = "\"0\"", Type = "string", ConfigAssociation = config }); tolerance = double.Parse(FragmentToleranceBox.Text); if (destinationProgram == "DirecTag") { if (FragmentToleranceUnitsBox.Text == "ppm") tolerance /= 1000; config.PropertyList.Add(new ConfigProperty { Name = "FragmentMzTolerance", Value = tolerance.ToString(CultureInfo.InvariantCulture), Type = "string", ConfigAssociation = config }); config.PropertyList.Add(new ConfigProperty { Name = "ComplementMzTolerance", Value = tolerance.ToString(CultureInfo.InvariantCulture), Type = "string", ConfigAssociation = config }); config.PropertyList.Add(new ConfigProperty { Name = "IsotopeMzTolerance", Value = tolerance.ToString(CultureInfo.InvariantCulture), Type = "string", ConfigAssociation = config }); } else config.PropertyList.Add(new ConfigProperty { Name = "FragmentMzTolerance", Value = "\"" + tolerance.ToString(CultureInfo.InvariantCulture) + FragmentToleranceUnitsBox.Text + "\"", Type = "string", ConfigAssociation = config }); if (destinationProgram != "DirecTag") { if (SuffixBox.Checked) config.PropertyList.Add(new ConfigProperty { Name = "OutputSuffix", Value = "\"" + PrimarySuffixBox.Text + "\"", Type = "string", ConfigAssociation = config }); config.PropertyList.Add(new ConfigProperty { Name = "CleavageRules", Value = "\"" + CleavageAgentBox.Text + "\"", Type = "string", ConfigAssociation = config }); config.PropertyList.Add(new ConfigProperty { Name = "MinTerminiCleavages", Value = SpecificityBox.SelectedIndex.ToString(CultureInfo.InvariantCulture), Type = "int", ConfigAssociation = config }); config.PropertyList.Add(new ConfigProperty { Name = "DecoyPrefix", Value = "XXX_", Type = "string", ConfigAssociation = config }); } if (destinationProgram == "TagRecon" && BlindModBox.Checked) config.PropertyList.Add(new ConfigProperty { Name = "ExplainUnknownMassShiftsAs", Value = "\"blindptms\"", Type = "string", ConfigAssociation = config }); var staticMods = new List<string>(); var dynamicMods = new List<string>(); for (var x = 0; x < ModBox.Rows.Count; x++) { var residue = ModBox.Rows[x].Cells[0].Value.ToString(); var massString = ModBox.Rows[x].Cells[1].Value.ToString(); var type = ModBox.Rows[x].Cells[2].Value.ToString(); double mass; if (string.IsNullOrEmpty(residue) || string.IsNullOrEmpty(massString) || !double.TryParse(massString, out mass) || string.IsNullOrEmpty(type)) continue; if (type == "Static") { staticMods.Add(residue); staticMods.Add(mass.ToString(CultureInfo.InvariantCulture)); } else { dynamicMods.Add(residue); dynamicMods.Add("*"); dynamicMods.Add(mass.ToString(CultureInfo.InvariantCulture)); } } if (staticMods.Count > 0) config.PropertyList.Add(new ConfigProperty { Name = "StaticMods", Value = "\"" + string.Join(" ", staticMods) + "\"", Type = "string", ConfigAssociation = config }); if (dynamicMods.Count > 0) config.PropertyList.Add(new ConfigProperty { Name = "DynamicMods", Value = "\"" + string.Join(" ", dynamicMods) + "\"", Type = "string", ConfigAssociation = config }); return config; } if (destinationProgram == "Comet") { CometParams cometParams; if (FragmentLowRadio.Checked) cometParams = CometParams.GetIonTrapParams(); else if (FragmentMidRadio.Checked) cometParams = CometParams.GetTofParams(); else cometParams = CometParams.GetHighResParams(); cometParams.PrecursorTolerance = double.Parse(PrecursorToleranceBox.Text); cometParams.PrecursorUnit = PrecursorToleranceUnitsBox.Text == "mz" ? CometParams.PrecursorUnitOptions.Daltons : CometParams.PrecursorUnitOptions.PPM; cometParams.OutputSuffix = CometSuffixBox.Text; if (CometParams.CleavageAgentOptions.ContainsKey(CleavageAgentBox.Text)) cometParams.CleavageAgent = CometParams.CleavageAgentOptions[CleavageAgentBox.Text]; else MessageBox.Show("[Comet] Cannot use " + CleavageAgentBox.Text + " as a digestive enzyme for comet searches. Results may be unpredictable."); cometParams.Specificity = SpecificityBox.Text == "Fully-Specific" ? CometParams.SpecificityOptions.Tryptic : CometParams.SpecificityOptions.SemiTryptic; for (var x = 0; x < ModBox.Rows.Count; x++) { var residue = ModBox.Rows[x].Cells[0].Value.ToString(); var massString = ModBox.Rows[x].Cells[1].Value.ToString(); var type = ModBox.Rows[x].Cells[2].Value.ToString(); double mass; if (string.IsNullOrEmpty(residue) || string.IsNullOrEmpty(massString) || !double.TryParse(massString, out mass) || string.IsNullOrEmpty(type)) continue; if (type == "Static" && residue == "C") { cometParams.StaticCysteineMod = mass; continue; } //for now can only do static on cystine if (type == "Static") MessageBox.Show("[Comet] Warning, BumberDash can only apply static modifications "+ "to cystine at this time. Applying \'" +residue + ";" + mass + "\' as dynamic"); cometParams.DynamicModifications.Add(new CometParams.Modification(residue, mass)); } var config = new ConfigFile { DestinationProgram = "Comet", FilePath = "--Custom--" }; config.PropertyList = new List<ConfigProperty> { new ConfigProperty { Name = "config", Value = CometHandler.CometParamsToFileContents(cometParams), Type = "string", ConfigAssociation = config } }; return config; } if (destinationProgram == "MSGF") { var msgfParams = new MSGFParams(); msgfParams.PrecursorTolerance = double.Parse(PrecursorToleranceBox.Text); msgfParams.PrecursorToleranceUnits = PrecursorToleranceUnitsBox.Text == "mz" ? MSGFParams.PrecursorToleranceUnitOptions.Daltons : MSGFParams.PrecursorToleranceUnitOptions.PPM; //msgfParams.FragmentationMethod = FragmentLowRadio.Checked // ? MSGFParams.FragmentationMethodOptions.CID // : MSGFParams.FragmentationMethodOptions.HCD; if (PrecursorLowRadio.Checked || FragmentLowRadio.Checked) msgfParams.Instrument = MSGFParams.InstrumentOptions.LowResLTQ; else if (PrecursorMidRadio.Checked || FragmentMidRadio.Checked) msgfParams.Instrument = MSGFParams.InstrumentOptions.TOF; else msgfParams.Instrument = MSGFParams.InstrumentOptions.HighResLTQ; msgfParams.OutputSuffix = MSGFSuffixBox.Text; if (MSGFParams.CleavageAgentOptions.ContainsKey(CleavageAgentBox.Text)) msgfParams.CleavageAgent = MSGFParams.CleavageAgentOptions[CleavageAgentBox.Text]; else if (CleavageAgentBox.Text != "Trypsin/P") MessageBox.Show("[MSGF] Cannot use " + CleavageAgentBox.Text + " as a digestive enzyme for MS-GF+ searches. Results may be unpredictable."); msgfParams.Specificity = SpecificityBox.Text == "Fully-Specific" ? MSGFParams.SpecificityOptions.Tryptic : MSGFParams.SpecificityOptions.SemiTryptic; var msgfMods = new List<Util.Modification>(); for (var x = 0; x < ModBox.Rows.Count; x++) { var residue = ModBox.Rows[x].Cells[0].Value.ToString(); var massString = ModBox.Rows[x].Cells[1].Value.ToString(); var type = ModBox.Rows[x].Cells[2].Value.ToString(); double mass; if (string.IsNullOrEmpty(residue) || string.IsNullOrEmpty(massString) || !double.TryParse(massString, out mass) || string.IsNullOrEmpty(type)) continue; msgfMods.Add(new Util.Modification {Residue = residue, Mass = mass, Type = type}); } var config = new ConfigFile { DestinationProgram = "MSGF", FilePath = "--Custom--" }; config.PropertyList = new List<ConfigProperty> { new ConfigProperty { Name = "config", Value = MSGFHandler.MSGFParamsToOverload(msgfParams), Type = "string", ConfigAssociation = config }, new ConfigProperty { Name = "mods", Value = MSGFHandler.ModListToModString(msgfMods, 2), Type = "string", ConfigAssociation = config } }; return config; } throw new Exception("Invalid destination program, can't construct configuration"); }
public static ConfigFile TagsFileToEntireFileString(string file) { var newConfig = new ConfigFile { DestinationProgram = "DirecTag", Name = Path.GetFileName(file), PropertyList = new List<ConfigProperty>() }; var parameterTypes = Util.parameterTypes; var cutFile = string.Empty; var fileStream = new StreamReader(file); while (!fileStream.EndOfStream) { var tempString = fileStream.ReadLine() ?? string.Empty; if (tempString.Contains("TagsParameters")) { tempString = fileStream.ReadLine(); while (!string.IsNullOrEmpty(tempString)) { tempString = tempString.Remove(0, 2); cutFile += tempString + ","; tempString = fileStream.ReadLine(); } cutFile = cutFile.Trim(); break; } } fileStream.Close(); var entireLine = cutFile.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); string[] propertySplit; foreach (var parameter in entireLine) { //get the two meaningful values propertySplit = parameter.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); propertySplit[0] = propertySplit[0].Trim(); propertySplit[1] = propertySplit[1].Trim(); //check if value is actually meaningful to the editor if (parameterTypes.ContainsKey(propertySplit[0])) { if (parameterTypes[propertySplit[0]] == "bool") { propertySplit[1] = propertySplit[1].Trim('\"'); propertySplit[1] = Convert.ToBoolean(int.Parse(propertySplit[1])).ToString().ToLower(); newConfig.PropertyList.Add(new ConfigProperty { Name = propertySplit[0], Value = propertySplit[1], Type = parameterTypes[propertySplit[0]] }); } else if (parameterTypes[propertySplit[0]] == "int" || parameterTypes[propertySplit[0]] == "double") { propertySplit[1] = propertySplit[1].Trim('\"'); newConfig.PropertyList.Add(new ConfigProperty { Name = propertySplit[0], Value = propertySplit[1], Type = parameterTypes[propertySplit[0]] }); } else if (parameterTypes[propertySplit[0]] == "string") { if (propertySplit.Length > 2) { for (int foo = 2; foo < propertySplit.Length; foo++) propertySplit[1] += " " + propertySplit[foo]; } newConfig.PropertyList.Add(new ConfigProperty { Name = propertySplit[0], Value = propertySplit[1], Type = parameterTypes[propertySplit[0]] }); } } } return newConfig; }
/// <summary> /// Sets values of items to values in config /// </summary> /// <param name="baseConfig"></param> private void LoadConfig(ConfigFile baseConfig) { var configValues = baseConfig.PropertyList .ToDictionary(property => property.Name, property => property.Value.Trim('"')); foreach (var kvp in _defaults) { var root = RootName(kvp.Key.Name); var value = configValues.ContainsKey(root) ? configValues[root] : kvp.Value; if (root == "MaxMissedCleavages" && decimal.Parse(value) > 90000) value = "-1"; if (root == "TicCutoffPercentage" || root == "LibTicCutoffPercentage") value = Math.Round(decimal.Parse(value), 2).ToString(); if (root == "PrecursorAdjustmentStep") value = Math.Round(decimal.Parse(value), 6).ToString(); var isDual = GetDualDependenceValue(kvp.Key); if (isDual != null) SetDualDependenceValue(kvp.Key, value); else if (root == "AppliedMod") { var modString = string.Empty; if (configValues.ContainsKey("StaticMods")) { modString += "StaticMods = \"" + configValues["StaticMods"] + "\"" + Environment.NewLine; } if (configValues.ContainsKey("DynamicMods")) { modString += "DynamicMods = \"" + configValues["DynamicMods"] + "\"" + Environment.NewLine; } if (configValues.ContainsKey("PreferredDeltaMasses")) { modString += "PreferredDeltaMasses = \"" + configValues["PreferredDeltaMasses"] + "\""; } if (!string.IsNullOrEmpty(modString)) { SetModString(modString.Trim()); } } else if (root == "UseAvgMassOfSequences") ((ComboBox)kvp.Key).SelectedIndex = (value == "true") ? 1 : 0; else if (root == "MinTerminiCleavages" || root == "DeisotopingMode") ((ComboBox)kvp.Key).SelectedIndex = int.Parse(value); else if (kvp.Key is ComboBox || kvp.Key is TextBox) kvp.Key.Text = value; else if (kvp.Key is NumericUpDown) ((NumericUpDown)kvp.Key).Value = decimal.Parse(value); else if (kvp.Key is CheckBox) ((CheckBox)kvp.Key).Checked = bool.Parse(value); } }
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); }
private List<ConfigProperty> GetProperties(List<Control> items, ConfigFile newConfig) { var propertyList = new List<ConfigProperty>(); foreach (var item in items) { var root = RootName(item.Name); var isDual = GetDualDependenceValue(item); if (isDual != null) propertyList.Add(new ConfigProperty { Name = root, Type = "string", ConfigAssociation = newConfig, Value = isDual }); else if (root == "AppliedMod") { var modProperties = GetModProperties((DataGridView)item); foreach (var property in modProperties) property.ConfigAssociation = newConfig; propertyList.AddRange(modProperties); } else if (root == "UseAvgMassOfSequences") propertyList.Add(new ConfigProperty { Name = root, Type = "string", ConfigAssociation = newConfig, Value = (((ComboBox)item).SelectedIndex == 1).ToString().ToLower() }); else if (root == "MinTerminiCleavages" || root == "DeisotopingMode") propertyList.Add(new ConfigProperty { Name = root, Type = "string", ConfigAssociation = newConfig, Value = ((ComboBox)item).SelectedIndex.ToString() }); else if (root == "UnimodXML" && TRUnimodXMLBox.Text == "Default") propertyList.Add(new ConfigProperty { Name = root, Type = "string", ConfigAssociation = newConfig, Value = Path.Combine(Application.StartupPath, @"lib\Bumbershoot\TagRecon\unimod.xml") }); else if (root == "Blosum" && TRBlosumBox.Text == "Default") propertyList.Add(new ConfigProperty { Name = root, Type = "string", ConfigAssociation = newConfig, Value = Path.Combine(Application.StartupPath, @"lib\Bumbershoot\TagRecon\blosum62.fas") }); else if (root == "DeisotopingMode") propertyList.Add(new ConfigProperty { Name = root, Type = "string", ConfigAssociation = newConfig, Value = ((ComboBox)item).SelectedIndex.ToString() }); else if (item is ComboBox || item is TextBox) { double x; propertyList.Add(new ConfigProperty { Name = root, Type = "string", ConfigAssociation = newConfig, Value = double.TryParse(item.Text, out x) ? item.Text : string.Format("\"{0}\"", item.Text) }); } if (item is NumericUpDown) propertyList.Add(new ConfigProperty { Name = root, Type = "string", ConfigAssociation = newConfig, Value = ((NumericUpDown) item).Value.ToString() }); if (item is CheckBox) propertyList.Add(new ConfigProperty { Name = root, Type = "string", ConfigAssociation = newConfig, Value = ((CheckBox) item).Checked.ToString().ToLower() }); } return propertyList; }
/// <summary> /// Returns properties from the given config file (newline seperated, in format "Property = Value") /// </summary> /// <param name="config"></param> /// <returns></returns> private static string CreatePropertyStringFromConfig(ConfigFile config) { var tempString = new StringBuilder(); foreach (var param in config.PropertyList) tempString.AppendLine(string.Format("{0} = {1}", param.Name, param.Value)); return tempString.ToString().Trim(); }
public ConfigFile GetCometConfig() { if (!ProgramSelectComet.Checked) return null; var newConfig = new ConfigFile { DestinationProgram = "Comet", Name = "--Custom--", FilePath = "--Custom--", PropertyList = new List<ConfigProperty>() }; var cometConfig = CometInstrumentBox.SelectedIndex == 0 ? CometParams.GetIonTrapParams() : CometInstrumentBox.SelectedIndex == 0 ? CometParams.GetTofParams() : CometParams.GetHighResParams(); if (CometParams.CleavageAgentOptions.ContainsKey(MyriCleavageRulesBox.Text)) cometConfig.CleavageAgent = CometParams.CleavageAgentOptions[MyriCleavageRulesBox.Text]; foreach (DataGridViewRow row in MyriAppliedModBox.Rows) { if (row.Cells[MyriTypeColumn.Index].Value.ToString() == "Dynamic") cometConfig.DynamicModifications.Add( new CometParams.Modification(row.Cells[MyriMotifColumn.Index].Value.ToString(), double.Parse(row.Cells[MyriMassColumn.Index].Value.ToString()))); else if (row.Cells[MyriMotifColumn.Index].Value.ToString() == "C") cometConfig.StaticCysteineMod = double.Parse(row.Cells[MyriMassColumn.Index].Value.ToString()); } cometConfig.MaxMissedCleavages = (int)MyriMaxMissedCleavagesBox.Value; cometConfig.MaxMods = (int)MyriMaxDynamicModsBox.Value; cometConfig.OutputSuffix = CometOutputSuffixBox.Text; cometConfig.PrecursorTolerance = Double.Parse(MyriMonoPrecursorMzToleranceBox.Text); cometConfig.PrecursorUnit = MyriMonoPrecursorMzToleranceUnitsList.SelectedIndex == 0 ? CometParams.PrecursorUnitOptions.Daltons : CometParams.PrecursorUnitOptions.PPM; cometConfig.Specificity = MyriMinTerminiCleavagesBox.SelectedIndex; newConfig.PropertyList.Add(new ConfigProperty { Name = "config", Type = "string", ConfigAssociation = newConfig, Value = CometHandler.CometParamsToFileContents(cometConfig) }); return newConfig; }
public ConfigFile GetMSGFConfig() { if (!ProgramSelectMSGF.Checked) return null; var newConfig = new ConfigFile { DestinationProgram = "MSGF", Name = "--Custom--", FilePath = "--Custom--", PropertyList = new List<ConfigProperty>() }; var msgfConfig = new MSGFParams(); if (MSGFParams.CleavageAgentOptions.ContainsKey(MyriCleavageRulesBox.Text)) msgfConfig.CleavageAgent = MSGFParams.CleavageAgentOptions[MyriCleavageRulesBox.Text]; //msgfConfig.FragmentationMethod = MSGFFragmentMethodBox.SelectedIndex; msgfConfig.Instrument = MSGFInstrumentBox.SelectedIndex; msgfConfig.OutputSuffix = MSGFOutputSuffixBox.Text; msgfConfig.PrecursorTolerance = Double.Parse(MyriMonoPrecursorMzToleranceBox.Text); msgfConfig.PrecursorToleranceUnits = MyriMonoPrecursorMzToleranceUnitsList.SelectedIndex == 0 ? MSGFParams.PrecursorToleranceUnitOptions.Daltons : MSGFParams.PrecursorToleranceUnitOptions.PPM; msgfConfig.Protocol = MSGFPhosphoBox.Checked ? MSGFiTRAQBox.Checked ? MSGFParams.ProtocolOptions.iTRAQPhospho : MSGFParams.ProtocolOptions.Phosphorylation : MSGFiTRAQBox.Checked ? MSGFParams.ProtocolOptions.iTRAQ : MSGFParams.ProtocolOptions.NoProtocol; msgfConfig.Specificity = MyriMinTerminiCleavagesBox.SelectedIndex; var modList = new List<Util.Modification>(); foreach (DataGridViewRow row in MyriAppliedModBox.Rows) { modList.Add(new Util.Modification { Mass = double.Parse(row.Cells[MyriMassColumn.Index].Value.ToString()), Residue = row.Cells[MyriMotifColumn.Index].Value.ToString(), Type = row.Cells[MyriTypeColumn.Index].Value.ToString() }); } newConfig.PropertyList.Add(new ConfigProperty { Name = "config", Type = "string", ConfigAssociation = newConfig, Value = MSGFHandler.MSGFParamsToOverload(msgfConfig) }); newConfig.PropertyList.Add(new ConfigProperty { Name = "mods", Type = "string", ConfigAssociation = newConfig, Value = MSGFHandler.ModListToModString(modList, (int) MyriMaxDynamicModsBox.Value) }); return newConfig; }
private void SaveTemplateButton_Click(object sender, EventArgs e) { var parameterType = Util.parameterTypes; string prefix; var newTemplate = false; try { ConfigFile currentConfig; if (ProgramModeBox.Text == "MyriMatch") { if (MyriInstrumentList.SelectedIndex > 0) currentConfig = _myriTemplateList[MyriInstrumentList.SelectedIndex - 1]; else { currentConfig = new ConfigFile { DestinationProgram = "MyriMatch", FilePath = "Template", PropertyList = new List<ConfigProperty>() }; newTemplate = true; } prefix = "Myri"; } else if (ProgramModeBox.Text == "DirecTag") { if (DTInstrumentList.SelectedIndex > 0) currentConfig = _DTTemplateList[DTInstrumentList.SelectedIndex-1]; else { currentConfig = new ConfigFile { DestinationProgram = "DirecTag", FilePath = "Template", PropertyList = new List<ConfigProperty>() }; newTemplate = true; } prefix = "DT"; } else if (ProgramModeBox.Text == "TagRecon") { if (TRInstrumentList.SelectedIndex > 0) currentConfig = _TRTemplateList[TRInstrumentList.SelectedIndex-1]; else { currentConfig = new ConfigFile { DestinationProgram = "TagRecon", FilePath = "Template", PropertyList = new List<ConfigProperty>() }; newTemplate = true; } prefix = "TR"; } else { if (PepInstrumentList.SelectedIndex > 0) currentConfig = _pepTemplateList[PepInstrumentList.SelectedIndex - 1]; else { currentConfig = new ConfigFile { DestinationProgram = "Pepitome", FilePath = "Template", PropertyList = new List<ConfigProperty>() }; newTemplate = true; } prefix = "Pep"; } if (newTemplate) { var namebox = new TextPromptBox("Instrument Name", string.Empty); if (namebox.ShowDialog() == DialogResult.OK) currentConfig.Name = namebox.GetText(); else return; } currentConfig.PropertyList.Clear(); foreach (var kvp in _labelAssociation .Where(kvp => kvp.Key.Name.StartsWith(prefix)) .Where(kvp => kvp.Value.ForeColor != DefaultForeColor && kvp.Value.ForeColor != Color.Blue)) { currentConfig.PropertyList.Add(new ConfigProperty { Name = RootName(kvp.Key.Name), Value = GetControlValueString(kvp.Key), Type = parameterType.ContainsKey(RootName(kvp.Key.Name)) ? parameterType[RootName(kvp.Key.Name)] : "unknown", ConfigAssociation = currentConfig }); } _session.SaveOrUpdate(currentConfig); _session.Flush(); ResetTemplateLists(); MessageBox.Show("Save successful"); } catch { MessageBox.Show("Unable to save"); } }
/// <summary> /// Create ConfigForm in edit/clone mode /// </summary> /// <param name="baseConfig"></param> /// <param name="baseDirectory"></param> /// <param name="defaultName"></param> /// <param name="templates"></param> public ConfigForm(ConfigFile baseConfig, string baseDirectory, string defaultName, IEnumerable<ConfigFile> templates) { InitializeComponent(); ProgramModeBox.Text = baseConfig.DestinationProgram; _defaults = new Dictionary<Control, string>(); _templateDefaults = new Dictionary<Control, string>(); //starts as blank for comparison purposes _labelAssociation = new Dictionary<Control, Control>(); _itemList = new Dictionary<string, List<Control>> { {baseConfig.DestinationProgram, new List<Control>()} }; _filePath = baseConfig.FilePath; _baseDirectory = baseDirectory; _defaultName = defaultName; if (!File.Exists(_filePath)) SaveOverOldButton.Visible = false; _nonTemplate = new HashSet<Control>(); _changedItems = new HashSet<Control>(); SetInitialValues(); switch (baseConfig.DestinationProgram) { case "MyriMatch": this.Text = "MyriMatch Configuration Editor"; _myriTemplateList = templates.Where(x => x.DestinationProgram == "MyriMatch").ToList(); InitializePane(MyriGenPanel); InitializePane(MyriAdvPanel); MyriInstrumentList.Items.Add("New"); foreach (var item in _myriTemplateList) MyriInstrumentList.Items.Add(item.Name); MyriInstrumentList.Text = "New"; break; case "DirecTag": this.Text = "DirecTag Configuration Editor"; _DTTemplateList = templates.Where(x => x.DestinationProgram == "DirecTag").ToList(); InitializePane(DTGenPanel); InitializePane(DTAdvPanel); DTInstrumentList.Items.Add("New"); foreach (var item in _DTTemplateList) DTInstrumentList.Items.Add(item.Name); DTInstrumentList.Text = "New"; break; case "TagRecon": this.Text = "TagRecon Configuration Editor"; _TRTemplateList = templates.Where(x => x.DestinationProgram == "TagRecon").ToList(); InitializePane(TRGenPanel); InitializePane(TRAdvPanel); TRInstrumentList.Items.Add("New"); foreach (var item in _TRTemplateList) TRInstrumentList.Items.Add(item.Name); TRInstrumentList.Text = "New"; break; case "Pepitome": this.Text = "Pepitome Configuration Editor"; _pepTemplateList = templates.Where(x => x.DestinationProgram == "Pepitome").ToList(); InitializePane(PepGenPanel); InitializePane(PepAdvPanel); PepInstrumentList.Items.Add("New"); foreach (var item in _pepTemplateList) PepInstrumentList.Items.Add(item.Name); PepInstrumentList.Text = "New"; break; } mainTabControl.TabPages.Remove(AdvTab); LoadConfig(baseConfig); }
internal ConfigFile GetMainConfigFile() { if (ProgramModeBox.Text == "MyriMatch" && !ProgramSelectMyri.Checked) return null; var changed = new List<Control>(); if (_isCustom) foreach (var item in _itemList[ProgramModeBox.Text]) { var value = GetControlValueString(item); var compareValue = value.Trim('"'); var root = RootName(item.Name); var isModBox = root == "AppliedMod"; if (isModBox && compareValue.Length > 0) compareValue += "\""; if (compareValue != _defaults[item] || (isModBox && !ModStringsEqual(compareValue, _defaults[item]))) changed.Add(item); } var newConfig = new ConfigFile(); newConfig.DestinationProgram = ProgramModeBox.Text; newConfig.Name = "--Custom--"; newConfig.PropertyList = _isCustom ? GetProperties(changed, newConfig) : null; newConfig.FilePath = _isCustom ? "--Custom--" : _filePath; return newConfig; }
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; }
/// <summary> /// Takes a template config and populates the template defaults dictionary /// </summary> /// <param name="baseConfig"></param> private void SetTemplateDefaults(ConfigFile baseConfig) { _templateDefaults = new Dictionary<Control, string>(); var configValues = new Dictionary<string, string>(); foreach (var item in baseConfig.PropertyList) if (!configValues.ContainsKey(item.Name)) configValues.Add(item.Name, item.Value.Trim('"')); if (configValues.ContainsKey("AppliedMod") && configValues["AppliedMod"].Length > 0) configValues["AppliedMod"] += "\""; //Set values foreach (var item in _itemList[ProgramModeBox.Text]) { var root = RootName(item.Name); if (configValues.ContainsKey(root)) _templateDefaults.Add(item, configValues[root]); } foreach (var item in _itemList[ProgramModeBox.Text]) CheckForChange(item, null); }
/// <summary> /// Returns list of output templates /// </summary> /// <returns></returns> internal List<ConfigFile> GetConfigs() { var list = from DataGridViewRow row in OutputDGV.Rows select (ConfigFile) row.Tag; var newList = new List<ConfigFile>(); foreach (var item in list) { var newconfig = new ConfigFile { Name = item.Name, DestinationProgram = item.DestinationProgram, FilePath = item.FilePath, PropertyList = new List<ConfigProperty>() }; foreach (var property in item.PropertyList) newconfig.PropertyList.Add(new ConfigProperty { Name = property.Name, Type = property.Type, Value = property.Value, ConfigAssociation = newconfig }); newList.Add(newconfig); } return newList; }
/// <summary> /// Reloads database representation of a valid config file /// </summary> /// <param name="config"></param> private void ReloadConfig(ConfigFile config) { if (Path.GetExtension(config.FilePath) == ".cfg") { if (File.Exists(config.FilePath)) { var parameterType = Util.parameterTypes; var fileIn = new StreamReader(config.FilePath); var completeFile = fileIn.ReadToEnd(); fileIn.Close(); fileIn.Dispose(); var propertyList = completeFile.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); config.PropertyList.Clear(); foreach (var line in propertyList) { var breakDown = line.Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); config.PropertyList.Add(new ConfigProperty { Name = breakDown[0].Trim(), Value = breakDown[1].Trim(), Type = parameterType.ContainsKey(breakDown[0].Trim()) ? parameterType[breakDown[0].Trim()] : "unknown", ConfigAssociation = config }); } _session.SaveOrUpdate(config); _session.Flush(); } else { //Occurs when the file has been deleted, convert to custom config config.Name = "File missing (" + config.FilePath + ")"; config.FilePath = "--Custom--"; _session.SaveOrUpdate(config); _session.Flush(); } } }