From e93937df191c282ceffeda738aaee7107cff1f51 Mon Sep 17 00:00:00 2001 From: Dominik Kopczynski Date: Tue, 10 Oct 2023 09:27:53 +0200 Subject: [PATCH] added lipid transfer from quick lipid search --- LipidCreator/Adduct.cs | 2 +- LipidCreator/CreatorGUI.Designer.cs | 90 +++++++++++-------- LipidCreator/CreatorGUI.cs | 131 +++++++++++++++++++--------- LipidCreator/LipidCreator.cs | 15 ++-- LipidCreator/MS2Fragment.cs | 28 ++++-- LipidCreator/NewFragment.cs | 2 +- 6 files changed, 175 insertions(+), 93 deletions(-) diff --git a/LipidCreator/Adduct.cs b/LipidCreator/Adduct.cs index b6ed51e8..18ef010b 100644 --- a/LipidCreator/Adduct.cs +++ b/LipidCreator/Adduct.cs @@ -32,7 +32,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE namespace LipidCreator { - public enum AdductType {Hp, HHp, NHHHHp, Hm, HHm, HCOOm, CHHHCOOm}; + public enum AdductType {Hp, HHp, NHHHHp, Hm, HHm, HCOOm, CHHHCOOm, NoAdduct}; [Serializable] public partial class Adduct diff --git a/LipidCreator/CreatorGUI.Designer.cs b/LipidCreator/CreatorGUI.Designer.cs index 36cf8704..058b3abd 100644 --- a/LipidCreator/CreatorGUI.Designer.cs +++ b/LipidCreator/CreatorGUI.Designer.cs @@ -446,6 +446,7 @@ partial class CreatorGUI public Button startSecondTutorialButton; [NonSerialized] public Button startThirdTutorialButton; + [NonSerialized] public Button startFourthTutorialButton; @@ -828,6 +829,8 @@ partial class CreatorGUI public ComboBox searchAdduct; [NonSerialized] DataGridView searchfragmentsGridview; + [NonSerialized] + public Button transferLipid; [NonSerialized] public GroupBox lipidMassSearchBox; @@ -838,8 +841,12 @@ partial class CreatorGUI [NonSerialized] public ComboBox searchToleranceType; [NonSerialized] + public ComboBox searchPolarity; + [NonSerialized] public TextBox searchTolerance; [NonSerialized] + public Label searchPolarityLabel; + [NonSerialized] public Label searchMassLabel; [NonSerialized] public Label searchToleranceLabel; @@ -847,6 +854,8 @@ partial class CreatorGUI public Label searchToleranceTypeLabel; [NonSerialized] public Label searchlipidsGridviewLabel; + [NonSerialized] + public CheckBox precursorAdductCombinations; @@ -2485,12 +2494,11 @@ private void InitializeComponent() lipidsGridview.ScrollBars = ScrollBars.Vertical; if (!lipidCreatorInitError) { - lipidsGridview.DataBindingComplete += new DataGridViewBindingCompleteEventHandler(lipidsGridviewDataBindingComplete); + lipidsGridview.DataBindingComplete += lipidsGridviewDataBindingComplete; lipidsGridview.DoubleClick += new EventHandler(lipidsGridviewDoubleClick); lipidsGridview.KeyDown += new KeyEventHandler(lipidsGridviewKeydown); lipidsGridview.EditMode = DataGridViewEditMode.EditOnEnter; } - lipidsGridviewPanel = new Panel(); lipidsGridviewPanel.Dock = DockStyle.Fill; lipidsGridviewPanel.AutoSize = true; @@ -2715,6 +2723,7 @@ private void InitializeComponent() lipidSumFormulaLabel = new Label(); searchAdductLabel = new Label(); fragmentsTableLabel = new Label(); + transferLipid = new Button(); searchAdduct = new ComboBox(); searchAdduct.Items.Add("Neutral molecule"); @@ -2727,7 +2736,7 @@ private void InitializeComponent() searchAdduct.Items.Add("+CH3COO-"); searchfragmentsGridview = new DataGridView(); - + precursorAdductCombinations = new CheckBox(); lipidNameSearchBox.Controls.Add(suggestedLipidName); @@ -2737,7 +2746,7 @@ private void InitializeComponent() suggestedLipidName.TextChanged += lipidNameSearch; suggestedLipidNameLabel.Location = new Point(suggestedLipidName.Left, suggestedLipidName.Top - sep); suggestedLipidNameLabel.Width = faLength; - suggestedLipidNameLabel.Text = "Lipid Name"; + suggestedLipidNameLabel.Text = "Lipid name"; lipidNameSearchBox.Controls.Add(translatedLipidName); lipidNameSearchBox.Controls.Add(translatedLipidNameLabel); @@ -2746,18 +2755,18 @@ private void InitializeComponent() translatedLipidName.Enabled = false; translatedLipidNameLabel.Location = new Point(translatedLipidName.Left, translatedLipidName.Top - sep); translatedLipidNameLabel.Width = faLength; - translatedLipidNameLabel.Text = "Translated Lipid Name"; + translatedLipidNameLabel.Text = "Translated lipid name"; lipidNameSearchBox.Controls.Add(lipidMassLabel); lipidNameSearchBox.Controls.Add(lipidSumFormulaLabel); lipidMassLabel.Location = new Point(suggestedLipidName.Left, suggestedLipidName.Top + suggestedLipidName.Height + 10); - lipidMassLabel.Width = 2 * faLength; + lipidMassLabel.Width = faLength; lipidMassLabel.Text = "m/z: "; lipidSumFormulaLabel.Location = new Point(lipidMassLabel.Left, lipidMassLabel.Top + sep); - lipidSumFormulaLabel.Width = (int)(2.5 * faLength); - lipidSumFormulaLabel.Text = "sum formula: "; + lipidSumFormulaLabel.Width = faLength; + lipidSumFormulaLabel.Text = "Sum formula: "; lipidSumFormulaLabel.BringToFront(); lipidNameSearchBox.Controls.Add(searchAdduct); @@ -2769,7 +2778,7 @@ private void InitializeComponent() searchAdduct.SelectedIndex = 0; searchAdductLabel.Location = new Point(searchAdduct.Left, searchAdduct.Top - sep); searchAdductLabel.Width = faLength; - searchAdductLabel.Text = "Selected Adduct"; + searchAdductLabel.Text = "Selected adduct"; lipidNameSearchBox.Controls.Add(searchfragmentsGridview); searchfragmentsGridview.DefaultCellStyle.WrapMode = DataGridViewTriState.True; @@ -2789,8 +2798,17 @@ private void InitializeComponent() lipidNameSearchBox.Controls.Add(fragmentsTableLabel); fragmentsTableLabel.Location = new Point(searchfragmentsGridview.Left, searchfragmentsGridview.Top - sep); fragmentsTableLabel.Width = faLength; - fragmentsTableLabel.Text = "Table of lipid fragments"; + fragmentsTableLabel.Text = "Fragment table"; + lipidNameSearchBox.Controls.Add(transferLipid); + transferLipid.Text = "Transfer lipid"; + transferLipid.Width = 200; + transferLipid.Height = 26; + //transferLipid.Location = new Point(searchfragmentsGridview.Left - transferLipid.Width, transferLipid.Top - transferLipid.Height - 10); + transferLipid.Location = new Point(searchfragmentsGridview.Left + searchfragmentsGridview.Width - transferLipid.Width, searchfragmentsGridview.Top - transferLipid.Height - 10); + transferLipid.BackColor = SystemColors.Control; + transferLipid.Click += transferLipidAction; + transferLipid.Enabled = false; @@ -2800,9 +2818,14 @@ private void InitializeComponent() searchToleranceType.Items.Add("ppm"); searchTolerance = new TextBox(); searchMassLabel = new Label(); + searchPolarityLabel = new Label(); searchToleranceLabel = new Label(); searchToleranceTypeLabel = new Label(); searchlipidsGridviewLabel = new Label(); + searchPolarity = new ComboBox(); + searchPolarity.Items.Add("both"); + searchPolarity.Items.Add("negative"); + searchPolarity.Items.Add("positive"); searchlipidsGridview = new DataGridView(); @@ -2813,7 +2836,7 @@ private void InitializeComponent() searchMass.TextChanged += lipidMassSearch; searchMassLabel.Location = new Point(searchMass.Left, searchMass.Top - sep); searchMassLabel.Width = (int)(faLength * 0.7); - searchMassLabel.Text = "Lipid Mass"; + searchMassLabel.Text = "Lipid mass"; lipidMassSearchBox.Controls.Add(searchToleranceType); lipidMassSearchBox.Controls.Add(searchToleranceTypeLabel); @@ -2824,7 +2847,7 @@ private void InitializeComponent() searchToleranceType.SelectedIndex = 0; searchToleranceTypeLabel.Location = new Point(searchToleranceType.Left, searchToleranceType.Top - sep); searchToleranceTypeLabel.Width = (int)(faLength * 0.7); - searchToleranceTypeLabel.Text = "Type of tolerance"; + searchToleranceTypeLabel.Text = "Tolerance type"; lipidMassSearchBox.Controls.Add(searchTolerance); lipidMassSearchBox.Controls.Add(searchToleranceLabel); @@ -2836,6 +2859,13 @@ private void InitializeComponent() searchToleranceLabel.Width = (int)(faLength * 0.7); searchToleranceLabel.Text = "Tolerance"; + lipidMassSearchBox.Controls.Add(precursorAdductCombinations); + precursorAdductCombinations.Location = new Point(searchMass.Left, searchMass.Top + searchMass.Height); + precursorAdductCombinations.Text = "All lipid class / adduct combinations"; + precursorAdductCombinations.Checked = true; + precursorAdductCombinations.Width = 2 * faLength; + precursorAdductCombinations.CheckedChanged += lipidMassSearch; + lipidMassSearchBox.Controls.Add(searchlipidsGridview); searchlipidsGridview.DefaultCellStyle.WrapMode = DataGridViewTriState.True; searchlipidsGridview.AllowUserToResizeColumns = false; @@ -2851,34 +2881,22 @@ private void InitializeComponent() searchlipidsGridview.Size = new Size(480, 270); searchlipidsGridview.DataBindingComplete += searchLipidsComplete; + lipidMassSearchBox.Controls.Add(searchPolarity); + lipidMassSearchBox.Controls.Add(searchPolarityLabel); + searchPolarity.Location = new Point(searchTolerance.Left + searchTolerance.Width + 10, searchTolerance.Top); + searchPolarity.Width = (int)(faLength * 0.7); + searchPolarity.DropDownStyle = ComboBoxStyle.DropDownList; + searchPolarity.SelectedIndex = 0; + searchPolarity.SelectedIndexChanged += lipidMassSearch; + searchPolarityLabel.Location = new Point(searchPolarity.Left, searchPolarity.Top - sep); + searchPolarityLabel.Width = (int)(faLength * 0.7); + searchPolarityLabel.Text = "Polarity"; + lipidMassSearchBox.Controls.Add(searchlipidsGridviewLabel); searchlipidsGridviewLabel.Location = new Point(searchlipidsGridview.Left, searchlipidsGridview.Top - sep); searchlipidsGridviewLabel.Width = faLength; - searchlipidsGridviewLabel.Text = "Table of lipids"; - - - - - - - - - - - - - - - - - - - - - - - + searchlipidsGridviewLabel.Text = "Lipid table"; diff --git a/LipidCreator/CreatorGUI.cs b/LipidCreator/CreatorGUI.cs index 99df8895..ce9a975b 100644 --- a/LipidCreator/CreatorGUI.cs +++ b/LipidCreator/CreatorGUI.cs @@ -63,13 +63,15 @@ public class LipidAssembly { public string name; public double mass; - public string adduct; + public AdductType adduct; + public Precursor precursor; - public LipidAssembly(string n, double m, string a = "") + public LipidAssembly(string n, double m, Precursor p, AdductType a = AdductType.NoAdduct) { name = n; mass = m; adduct = a; + precursor = p; } } @@ -110,6 +112,7 @@ public partial class CreatorGUI : Form public static readonly float REGULAR_FONT_SIZE = 8.25f; public bool lipidCreatorInitError = false; public List searchLipids = new List(); + private Lipid searchLipid = null; public CreatorGUI(string _inputParameters) { @@ -332,8 +335,6 @@ public CreatorGUI(string _inputParameters) } } - double base_mass = fatty_acids[(2 << 20) + ((0 + 1) << 5)].mass; - double empty_mass = MS2Fragment.ALL_ELEMENTS[Molecule.H].mass; foreach (KeyValuePair kvp in lipidCreator.headgroups) { Precursor precursor = kvp.Value; @@ -351,39 +352,39 @@ public CreatorGUI(string _inputParameters) case 0: { - addLipidAssemblies(4, headgroup, fatty_acids); + addLipidAssemblies(4, headgroup, precursor, fatty_acids); break; } case 1: { - addLipidAssemblies(3, headgroup, fatty_acids); + addLipidAssemblies(3, headgroup, precursor, fatty_acids); break; } case 2: { - if (plasmalogen) addLipidAssemblies(2, headgroup, fatty_acids_o); - else addLipidAssemblies(2, headgroup, fatty_acids); + if (plasmalogen) addLipidAssemblies(2, headgroup, precursor, fatty_acids_o); + else addLipidAssemblies(2, headgroup, precursor, fatty_acids); break; } case 3: { - if (plasmalogen) addLipidAssemblies(1, headgroup, fatty_acids_o); - else addLipidAssemblies(1, headgroup, fatty_acids); + if (plasmalogen) addLipidAssemblies(1, headgroup, precursor, fatty_acids_o); + else addLipidAssemblies(1, headgroup, precursor, fatty_acids); break; } case 4: { - addLipidAssemblies(2, headgroup, long_chain_bases, true); + addLipidAssemblies(2, headgroup, precursor, long_chain_bases, true); break; } case 5: { - addLipidAssemblies(1, headgroup, long_chain_bases, true); + addLipidAssemblies(1, headgroup, precursor, long_chain_bases, true); break; } @@ -396,7 +397,7 @@ public CreatorGUI(string _inputParameters) if (elements[m] < 0) throw new LipidException((Molecule)m, elements[m], "For element '" + MS2Fragment.ALL_ELEMENTS[(Molecule)m].shortcut + "' the count dropped below zero to " + elements[m]); mass += elements[m] * MS2Fragment.ALL_ELEMENTS[(Molecule)m].mass; } - searchLipids.Add(new LipidAssembly(kvp.Key, mass)); + searchLipids.Add(new LipidAssembly(kvp.Key, mass, precursor)); break; } @@ -427,11 +428,11 @@ public CreatorGUI(string _inputParameters) double mass = searchLipids[i].mass + kvp.Value; mass = (mass - charge * LipidCreator.ELECTRON_REST_MASS) / Math.Abs(charge); - searchLipids.Add(new LipidAssembly(searchLipids[i].name, mass, adduct.visualization)); + searchLipids.Add(new LipidAssembly(searchLipids[i].name, mass, searchLipids[i].precursor, kvp.Key)); } } - searchLipids = searchLipids.Where(x => x.adduct.Length > 0).ToList(); + searchLipids = searchLipids.Where(x => x.adduct != AdductType.NoAdduct).ToList(); searchLipids.Sort(delegate(LipidAssembly x, LipidAssembly y){ return x.mass < y.mass ? -1 : 1; @@ -441,7 +442,7 @@ public CreatorGUI(string _inputParameters) - private void addLipidAssemblies(int fa, string headgroup, Dictionary chain_dict, bool isLCB = false) + private void addLipidAssemblies(int fa, string headgroup, Precursor precursor, Dictionary chain_dict, bool isLCB = false) { csgoslin.Headgroup hg = new csgoslin.Headgroup(headgroup); ElementTable elements = hg.get_elements(); @@ -464,7 +465,7 @@ private void addLipidAssemblies(int fa, string headgroup, Dictionary> 1; if (searchLipids[mid].mass < min_value) L = mid + 1; else R = mid; } - int pos = R + ((R == (searchLipids.Count - 1) && searchLipids[R].mass < min_value) ? 1 : 0); + int pos = Math.Max(0, R + ((R == (searchLipids.Count - 1) && searchLipids[R].mass < min_value) ? 1 : 0)); while (pos < searchLipids.Count) { - if (searchLipids[pos].mass < min_value) + if (searchLipids[pos].adduct == AdductType.NoAdduct) + { + pos++; + continue; + } + Adduct adduct = Lipid.ALL_ADDUCTS[searchLipids[pos].adduct]; + if (searchLipids[pos].mass < min_value || (adduct.charge > 0 && polarityNegative) || (adduct.charge < 0 && polarityPositive) || (LCspecificCombinations && !searchLipids[pos].precursor.adductRestrictions[adduct.name])) { pos++; continue; @@ -557,7 +573,8 @@ public void lipidMassSearch(Object sender, EventArgs e) double tolerance_val = Math.Abs(value - searchLipids[pos].mass) * (tolerance_mz ? 1.0 : 1e6 / value); lipidRow[tolerance_string] = string.Format("{0:N4}", tolerance_val); lipidRow["Lipid name"] = searchLipids[pos].name; - lipidRow["Adduct"] = searchLipids[pos].adduct; + lipidRow["Adduct"] = Lipid.ALL_ADDUCTS[searchLipids[pos].adduct].visualization; + lipidRow["Category"] = searchLipids[pos].precursor.category; lipidList.Rows.Add(lipidRow); pos++; } @@ -574,6 +591,8 @@ public void lipidNameSearch(Object sender, EventArgs e) DataTable transitionList = new DataTable(); foreach (string columnKey in LipidCreator.STATIC_DATA_COLUMN_KEYS) transitionList.Columns.Add(columnKey); searchfragmentsGridview.DataSource = transitionList; + transferLipid.Enabled = false; + searchLipid = null; try { @@ -586,16 +605,16 @@ public void lipidNameSearch(Object sender, EventArgs e) { switch((string)searchAdduct.Items[searchAdduct.SelectedIndex]) { - case "+H+": lipidName += Lipid.ALL_ADDUCTS[AdductType.Hp].ToString(); break; - case "+2H+": lipidName += Lipid.ALL_ADDUCTS[AdductType.HHp].ToString(); break; - case "+NH4+": lipidName += Lipid.ALL_ADDUCTS[AdductType.NHHHHp].ToString(); break; - case "-H-": lipidName += Lipid.ALL_ADDUCTS[AdductType.Hm].ToString(); break; - case "-2H-": lipidName += Lipid.ALL_ADDUCTS[AdductType.HHm].ToString(); break; - case "+HCOO-": lipidName += Lipid.ALL_ADDUCTS[AdductType.HCOOm].ToString(); break; - case "+CH3COO-": lipidName += Lipid.ALL_ADDUCTS[AdductType.CHHHCOOm].ToString(); break; + case "+H+": lipidAdduct.adduct = new csgoslin.Adduct("", "+H", 1, 1); break; + case "+2H+": lipidAdduct.adduct = new csgoslin.Adduct("", "+2H", 2, 1); break; + case "+HH4+": lipidAdduct.adduct = new csgoslin.Adduct("", "+NH4", 1, 1); break; + + case "-H-": lipidAdduct.adduct = new csgoslin.Adduct("", "-H", 1, -1); break; + case "-2H-": lipidAdduct.adduct = new csgoslin.Adduct("", "-2H", 2, -1); break; + case "+HCOO-": lipidAdduct.adduct = new csgoslin.Adduct("", "+HCOO", 1, -1); break; + case "+CH3COO-": lipidAdduct.adduct = new csgoslin.Adduct("", "+CH3COO", 1, -1); break; default: break; } - lipidAdduct = lipidCreator.lipidParser.parse(lipidName); } lipidMassLabel.Text = "m/z: " + string.Format("{0:N4}", lipidAdduct.get_mass()); @@ -605,7 +624,14 @@ public void lipidNameSearch(Object sender, EventArgs e) { try { - Lipid lipid = lipidCreator.translateLipid(lipidAdduct); + Lipid lipid = null; + if (lipidCreator.headgroups.ContainsKey(suggestedLipidName.Text) && lipidCreator.headgroups[suggestedLipidName.Text].category == LipidCategory.LipidMediator && (string)searchAdduct.Items[searchAdduct.SelectedIndex] == "-H-") + { + lipid = new Mediator(lipidCreator); + lipid.headGroupNames.Add(suggestedLipidName.Text); + lipid.adducts["-H"] = true; + } + else lipid = lipidCreator.translateLipid(lipidAdduct); if (lipid != null && !(lipid is UnsupportedLipid)) { HashSet usedKeys = new HashSet(); @@ -617,10 +643,12 @@ public void lipidNameSearch(Object sender, EventArgs e) { Lipid.computeFragmentData(transitionList, precursor, lipidCreator.allFragments, lipidCreator.headgroups, new ArrayList(){false, 0}); } + transferLipid.Enabled = true; + searchLipid = lipid; } } - catch(Exception) {} + catch(Exception) { } } } catch(Exception) @@ -632,6 +660,7 @@ public void lipidNameSearch(Object sender, EventArgs e) } + private void searchFragmentsComplete(object sender, DataGridViewBindingCompleteEventArgs e) { for (int c = 0; c < 8; c++) searchfragmentsGridview.Columns[c].Visible = false; @@ -646,10 +675,11 @@ private void searchFragmentsComplete(object sender, DataGridViewBindingCompleteE private void searchLipidsComplete(object sender, DataGridViewBindingCompleteEventArgs e) { - searchlipidsGridview.Columns[0].Width = (int)Math.Floor(searchfragmentsGridview.Size.Width * 0.2); - searchlipidsGridview.Columns[1].Width = (int)Math.Floor(searchfragmentsGridview.Size.Width * 0.2); - searchlipidsGridview.Columns[2].Width = (int)Math.Floor(searchfragmentsGridview.Size.Width * 0.4); - searchlipidsGridview.Columns[3].Width = (int)Math.Floor(searchfragmentsGridview.Size.Width * 0.2); + searchlipidsGridview.Columns[0].Width = (int)Math.Floor(searchfragmentsGridview.Size.Width * 0.15); + searchlipidsGridview.Columns[1].Width = (int)Math.Floor(searchfragmentsGridview.Size.Width * 0.15); + searchlipidsGridview.Columns[2].Width = (int)Math.Floor(searchfragmentsGridview.Size.Width * 0.27); + searchlipidsGridview.Columns[3].Width = (int)Math.Floor(searchfragmentsGridview.Size.Width * 0.15); + searchlipidsGridview.Columns[4].Width = (int)Math.Floor(searchfragmentsGridview.Size.Width * 0.28); } @@ -829,8 +859,9 @@ private void lipidsGridviewDataBindingComplete(object sender, DataGridViewBindin { lipidsGridview.InvokeIfRequired(() => { - if (initialCall) - { + if (initialCall) + { + initialCall = false; log.Debug("Initializing lipid table!"); int numCols = registeredLipidsDatatable.Columns.Count; DataGridViewImageColumn editColumn = new DataGridViewImageColumn(); @@ -843,6 +874,10 @@ private void lipidsGridviewDataBindingComplete(object sender, DataGridViewBindin deleteColumn.HeaderText = "Delete"; deleteColumn.ValuesAreIcons = false; lipidsGridview.Columns.Add(deleteColumn); + for (int i = 0; i < lipidsGridview.Columns.Count; ++i) + { + lipidsGridview.Columns[i].DisplayIndex = lipidsGridview.Columns[i].Index; + } foreach (DataGridViewColumn col in lipidsGridview.Columns) { col.Frozen = false; @@ -852,11 +887,10 @@ private void lipidsGridviewDataBindingComplete(object sender, DataGridViewBindin lipidsGridview.Columns[6].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; editColumn.Width = 40; deleteColumn.Width = 40; - initialCall = false; lipidsGridview.Enabled = true; lipidsGridview.Invalidate(); lipidsGridview.PerformLayout(); - } + } }); } @@ -890,6 +924,25 @@ public void tabIndexChanged(Object sender, TabControlCancelEventArgs e) + public void transferLipidAction(Object sender, EventArgs e) + { + if (searchLipid == null) return; + + int index = 0; + if (searchLipid is Glycerolipid) index = 1; + else if (searchLipid is Phospholipid) index = 2; + else if (searchLipid is Sphingolipid) index = 3; + else if (searchLipid is Sterol) index = 4; + else if (searchLipid is Mediator) index = 5; + else return; + + lipidTabList[index] = searchLipid; + lipidModifications[index] = 0; + changeTab(index); + } + + + public void tabControl_DrawItem(object sender, DrawItemEventArgs e) diff --git a/LipidCreator/LipidCreator.cs b/LipidCreator/LipidCreator.cs index b8b49c76..69a22e46 100644 --- a/LipidCreator/LipidCreator.cs +++ b/LipidCreator/LipidCreator.cs @@ -2064,9 +2064,12 @@ public Lipid translateLipid(csgoslin.LipidAdduct lipidAdduct) default: break; } - - if (headgroups.ContainsKey(lipidAdduct.lipid.headgroup.unaltered_headgroup) && !headgroups.ContainsKey(lipid.headGroupNames[0])) lipid.headGroupNames[0] = lipidAdduct.lipid.headgroup.unaltered_headgroup; - + + if (headgroups.ContainsKey(lipidAdduct.lipid.headgroup.unaltered_headgroup) && !headgroups.ContainsKey(lipid.headGroupNames[0])) + { + lipid.headGroupNames[0] = lipidAdduct.lipid.headgroup.unaltered_headgroup; + } + if (lipid != null && lipidAdduct.lipid.info.level == csgoslin.LipidLevel.SPECIES) { @@ -2074,7 +2077,7 @@ public Lipid translateLipid(csgoslin.LipidAdduct lipidAdduct) throw new Exception("Lipid on species level not supported."); } - if (lipid != null) + if (lipid != null && !(lipid is Mediator)) { foreach (csgoslin.FattyAcid fa in lipidAdduct.lipid.fa_list) { @@ -2110,7 +2113,6 @@ public Lipid translateLipid(csgoslin.LipidAdduct lipidAdduct) checked_functional_groups += 1; string fg = fa.functional_groups.ContainsKey("OH") ? "OH" : "O"; int cnt = (fa.functional_groups.ContainsKey("[X]") && !lipidAdduct.lipid.headgroup.sp_exception) ? 1 : 0; - Console.WriteLine("cnt: " + cnt + " " + fa.functional_groups.ContainsKey("[X]") + " " + lipidAdduct.lipid.headgroup.sp_exception); if (fa.functional_groups[fg].Count == 1) { cnt += fa.functional_groups[fg][0].count; @@ -2203,9 +2205,8 @@ public ArrayList translate(ArrayList lipidNamesList, bool reportError = false) lipid = translateLipid(lipidAdduct); } } - catch (Exception e) + catch (Exception) { - Console.WriteLine(e); if (reportError) { log.Error("Warning: lipid '" + lipidName + "' could not parsed."); diff --git a/LipidCreator/MS2Fragment.cs b/LipidCreator/MS2Fragment.cs index 5da122e0..435c22ad 100644 --- a/LipidCreator/MS2Fragment.cs +++ b/LipidCreator/MS2Fragment.cs @@ -43,12 +43,13 @@ public class MS2Fragment public string fragmentFile; public ElementDictionary fragmentElements; public Adduct fragmentAdduct; - public ArrayList fragmentBase; + public HashSet fragmentBase = new HashSet(); public bool specific; public bool userDefined; public const double MAX_INTENSITY = 100.0; public const double DEFAULT_INTENSITY = 10.0; public string CommentForSpectralLibrary { get { return fragmentName; } } + public static HashSet UNSPECIFIC_BLOCKS = new HashSet(){"HG", "M"}; public static Dictionary ALL_ELEMENTS = new Dictionary(){ {Molecule.C, new Element("C", "C", "C", "C", 0, 12.0, false, new Molecule[]{Molecule.C13}, Molecule.C)}, @@ -305,7 +306,6 @@ public MS2Fragment() fragmentFile = "-"; fragmentAdduct = Lipid.ALL_ADDUCTS[AdductType.Hp]; fragmentElements = new ElementDictionary(); - fragmentBase = new ArrayList(); userDefined = false; specific = false; } @@ -319,7 +319,6 @@ public MS2Fragment(String name, String fileName) fragmentFile = fileName; fragmentElements = new ElementDictionary(); fragmentAdduct = Lipid.ALL_ADDUCTS[AdductType.Hp]; - fragmentBase = new ArrayList(); userDefined = false; specific = false; } @@ -332,7 +331,6 @@ public MS2Fragment(String name, String fileName, Adduct _adduct) fragmentFile = fileName; fragmentElements = new ElementDictionary(); fragmentAdduct = _adduct; - fragmentBase = new ArrayList(); userDefined = false; specific = false; } @@ -346,9 +344,15 @@ public MS2Fragment(String name, String outputname, Adduct _adduct, String fileNa fragmentFile = fileName; fragmentAdduct = _adduct; fragmentElements = dataElements; - fragmentBase = (baseForms.Length > 0) ? new ArrayList(baseForms.Split(new char[] {';'})) : new ArrayList(); + if (baseForms.Length > 0) + { + foreach (string bb in baseForms.Split(new char[] {';'})) fragmentBase.Add(bb); + } userDefined = false; - specific = false; + + HashSet f = new HashSet(fragmentBase); + f.ExceptWith(UNSPECIFIC_BLOCKS); + specific = f.Count == 0; } @@ -360,9 +364,16 @@ public MS2Fragment(String name, String outputname, Adduct _adduct, String fileNa fragmentFile = fileName; fragmentAdduct = _adduct; fragmentElements = dataElements; - fragmentBase = (baseForms.Length > 0) ? new ArrayList(baseForms.Split(new char[] {';'})) : new ArrayList(); + if (baseForms.Length > 0) + { + foreach (string bb in baseForms.Split(new char[] {';'})) fragmentBase.Add(bb); + } userDefined = false; - specific = _specific; + + HashSet f = new HashSet(fragmentBase); + f.ExceptWith(UNSPECIFIC_BLOCKS); + specific = f.Count == 0; + //specific = _specific; } @@ -375,7 +386,6 @@ public MS2Fragment(MS2Fragment copy) fragmentElements = new ElementDictionary(); fragmentAdduct = copy.fragmentAdduct; for (int m = 0; m < copy.fragmentElements.Count; ++m) fragmentElements[m] = copy.fragmentElements[m]; - fragmentBase = new ArrayList(); userDefined = copy.userDefined; foreach (string fbase in copy.fragmentBase) fragmentBase.Add(fbase); specific = copy.specific; diff --git a/LipidCreator/NewFragment.cs b/LipidCreator/NewFragment.cs index 2e2cf669..54735145 100644 --- a/LipidCreator/NewFragment.cs +++ b/LipidCreator/NewFragment.cs @@ -140,7 +140,7 @@ public NewFragment(MS2Form ms2form, bool _edit = false, LipidException _lipidExc addButton.Text = "OK"; fragmentOutputName = ms2Fragment.fragmentOutputName; - HashSet fragmentBB = new HashSet( (String[]) ms2Fragment.fragmentBase.ToArray( typeof( string ) )); + HashSet fragmentBB = new HashSet(ms2Fragment.fragmentBase); for (int i = 1; i < buildingBlocksArray.Count; ++i) { HashSet currentBB = new HashSet(((string)buildingBlocksArray[i]).Split(new char[]{';'}));