private void mnuCrosslink_Click(object sender, EventArgs e) { TreeNode node1 = tvMRM.SelectedNodes[0] as TreeNode; TreeNode node2 = tvMRM.SelectedNodes[1] as TreeNode; var mr = GetResult(node1); SrmPairedPeptideItem item1 = node1.Tag as SrmPairedPeptideItem; SrmPairedPeptideItem item2 = node2.Tag as SrmPairedPeptideItem; SrmPairedPeptideItem light, heavy; if (item1.LightPrecursorMZ < item2.LightPrecursorMZ) { light = item1; heavy = item2; } else { light = item2; heavy = item1; } if (light.AddErrorPairedPeptideItem(heavy, mr.Options.AllowedGaps, mr.Options.MzTolerance, mr.Options.RetentionTimeToleranceInSecond)) { mr.Remove(heavy); tvMRM.Nodes.Remove(node2); AssignItem(light, node1); SetCurrentResultModified(); } }
private void mnuCrosslink_Click(object sender, EventArgs e) { TreeNode node1 = tvMRM.SelectedNodes[0] as TreeNode; TreeNode node2 = tvMRM.SelectedNodes[1] as TreeNode; SrmPairedPeptideItem item1 = node1.Tag as SrmPairedPeptideItem; SrmPairedPeptideItem item2 = node2.Tag as SrmPairedPeptideItem; SrmPairedPeptideItem item; if (item1.LightPrecursorMZ < item2.LightPrecursorMZ) { item = item1; item.SetHeavyPeptideItem(item2); mrmPairs.Remove(item2); } else { item = item2; item.SetHeavyPeptideItem(item1); mrmPairs.Remove(item1); } tvMRM.Nodes.Remove(node2); AssignItem(item, node1); }
/// <summary> /// 合并轻重标结果。如果自动识别未能把成对的肽段合并,就需要手工合并。 /// </summary> /// <param name="heavy">重标肽段</param> public void SetHeavyPeptideItem(SrmPairedPeptideItem heavy) { var sorted = (from h in heavy.ProductIonPairs orderby h.Light.ProductIon select h).ToList(); var sortedThis = (from h in this.ProductIonPairs orderby h.Light.ProductIon select h).ToList(); //首先去除完全一样的production for (int i = sorted.Count - 1; i >= 0; i--) { var index = sortedThis.FindIndex(m => m.Light.ProductIon == sorted[i].Light.ProductIon); if (index != -1) { sortedThis[index].SetHeavyIon(sorted[i]); sorted.RemoveAt(i); sortedThis.RemoveAt(index); } } for (int i = 0; i < sorted.Count; i++) { sortedThis[i].SetHeavyIon(sorted[i]); } }
private void mnuSetScanEnabledOnly_Click(object sender, EventArgs e) { GraphPane graphScans = mnuSetScanEnabledOnly.Tag as GraphPane; double min = graphScans.XAxis.Scale.Min; double max = graphScans.XAxis.Scale.Max; SrmPairedProductIon ion = graphScans.Tag as SrmPairedProductIon; SrmPairedPeptideItem item = FindItemByProductIon(ion); if (null == item) { return; } item.SetEnabledRetentionTimeRange(min, max); CurrentResult.Update(item); gvProductPair.Refresh(); DoUpdateProductIon(); tvMRM_AfterSelect(null, null); SetCurrentResultModified(); }
private void tvMRM_AfterSelect(object sender, TreeViewEventArgs e) { if (displaying) { return; } DoUpdatePeptide(); var node = tvMRM.SelectedNode; if (null == node || node.Level != 2) { return; } //设置当前product ion SrmPairedProductIon item = node.Tag as SrmPairedProductIon; SrmPairedPeptideItem pep = node.Parent.Tag as SrmPairedPeptideItem; int rowIndex = pep.ProductIonPairs.IndexOf(item); CurrencyManager cm = (CurrencyManager)this.BindingContext[pep.ProductIonPairs]; if (cm.Position != rowIndex) { cm.Position = rowIndex; } }
private static void Transfer(SrmPairedPeptideItem source, SrmPairedPeptideItem target, DataGridView gvSource, DataGridView gvTarget) { if (gvSource.SelectedRows.Count == 0) { return; } var rowIndecies = new List <int>(); for (int i = 0; i < gvSource.SelectedRows.Count; i++) { rowIndecies.Add(gvSource.SelectedRows[i].Index); } rowIndecies.Sort(); gvSource.DataSource = null; gvTarget.DataSource = null; try { for (int i = rowIndecies.Count - 1; i >= 0; i--) { target.ProductIonPairs.Add(source.ProductIonPairs[rowIndecies[i]]); source.ProductIonPairs.RemoveAt(rowIndecies[i]); } } finally { gvSource.DataSource = source.ProductIonPairs; gvTarget.DataSource = target.ProductIonPairs; } }
private void tvMRM_AfterCheck(object sender, TreeViewEventArgs e) { if (displaying) { return; } var node = e.Node; if (node.Level == 0) { return; } if (node.Level == 1) { SrmPairedPeptideItem pepItem = node.Tag as SrmPairedPeptideItem; pepItem.Enabled = node.Checked; return; } if (node.Level == 2) { SrmPairedProductIon item = node.Tag as SrmPairedProductIon; item.Enabled = node.Checked; SrmPairedPeptideItem pepItem = node.Parent.Tag as SrmPairedPeptideItem; pepItem.CalculatePeptideRatio(); } tvMRM_AfterSelect(null, null); SetCurrentResultModified(); }
private XElement PeptideToItem(SrmPairedPeptideItem item) { if (null == item) { return(null); } return(new XElement("Item", new XElement("Enabled", item.Enabled.ToString()), new XElement("Ratio", MyConvert.Format("{0:0.0000}", item.Ratio)), new XElement("SD", double.IsInfinity(item.SD) || double.IsNaN(item.SD) ? "-" : MyConvert.Format("{0:0.0000}", item.SD)), new XElement("ObjectName", item.ObjectName), new XElement("PrecursorFormula", item.PrecursorFormula), new XElement("PrecursorCharge", item.PrecursorCharge), from p in item.ProductIonPairs select new XElement("ProductIonPair", new XElement("Enabled", p.Enabled.ToString()), new XElement("Ratio", MyConvert.Format("{0:0.0000}", p.Ratio)), new XElement("Distance", MyConvert.Format("{0:0.0000}", p.Distance)), new XElement("RegressionCorrelation", MyConvert.Format("{0:0.0000}", p.RegressionCorrelation)), new XElement("LightArea", MyConvert.Format("{0:0.0}", p.LightArea)), new XElement("HeavyArea", MyConvert.Format("{0:0.0}", p.HeavyArea)), new XElement("Noise", MyConvert.Format("{0:0.00}", p.Noise)), new XElement("LightSignalToNoise", MyConvert.Format("{0:0.00}", p.LightSignalToNoise)), new XElement("HeavySignalToNoise", MyConvert.Format("{0:0.00}", p.HeavySignalToNoise)), TransactionToElement(p.Light, "LightTransaction"), TransactionToElement(p.Heavy, "HeavyTransaction")))); }
public SrmFileItem(SrmPairedResult result, SrmPairedPeptideItem peptide, SrmPairedProductIon production) { this.PairedResult = result; this.PairedPeptide = peptide; this.PairedProductIon = production; _precursorMz = new Pair <double, double>(peptide.LightPrecursorMZ, peptide.HeavyPrecursorMZ); _productIonMz = new Pair <double, double>(production.LightProductIon, production.HeavyProductIon); }
private CompoundItem FindComponent(SrmPairedPeptideItem pep) { var fileitem = (from f in allFiles.Compounds where f.ObjectName.Equals(pep.ProductIonPairs[0].ObjectName) && f.PrecursurFormula.Equals(pep.ProductIonPairs[0].PrecursorFormula) select f).FirstOrDefault(); return(fileitem); }
public static SrmPairedResult ToPairedResult(this List <SrmTransition> transList) { SrmPairedResult result = new SrmPairedResult(); //所有母离子有相同名称、相同质荷比认为是来自相同precursor,合并为一个peptide。 var pepgroup = transList.GroupBy(m => m.PrecursorFormula + MyConvert.Format("{0:0.0000}", m.PrecursorMZ)); var peptides = new List <SrmPeptideItem>(); foreach (var g in pepgroup) { var pep = new SrmPeptideItem(); pep.PrecursorMZ = g.First().PrecursorMZ; pep.ProductIons = new List <SrmTransition>(g); peptides.Add(pep); } //具有相同母离子名称和电荷的transition认为是轻重标。 var lhgroup = peptides.GroupBy(m => m.ProductIons[0].PrecursorFormula + "_" + m.ProductIons[0].PrecursorCharge.ToString()).ToList(); // var lhgroup = peptides.GroupBy(m => m.ProductIons[0].PrecursorFormula + "_" + m.ProductIons[0].PrecursorCharge.ToString()).ToList(); foreach (var g in lhgroup) { if (g.Count() > 2) { throw new Exception(string.Format("There are {0} transition with same precursor formula and precursor charge: {1}, {2}", g.Count(), g.First().ProductIons[0].PrecursorFormula, g.First().ProductIons[0].PrecursorCharge)); } else if (g.Count() > 1) { var items = g.ToList(); items.Sort((m1, m2) => m1.PrecursorMZ.CompareTo(m2.PrecursorMZ)); SrmPairedPeptideItem light = new SrmPairedPeptideItem(items[0]); SrmPairedPeptideItem heavy = new SrmPairedPeptideItem(items[1]); if (!string.IsNullOrEmpty(light.ProductIonPairs[0].Light.Ion)) { light.SetHeavyPeptideItemByIon(heavy); } else { light.SetHeavyPeptideItem(heavy); } result.Add(light); } else { SrmPairedPeptideItem light = new SrmPairedPeptideItem(g.First()); result.Add(light); } } return(result); }
private static void AssignItem(SrmPairedPeptideItem mrm, TreeNode node) { node.Nodes.Clear(); node.Text = mrm.ToString(); node.Tag = mrm; node.Checked = mrm.Enabled; mrm.ProductIonPairs.ForEach(m => { string ions = MyConvert.Format("{0:0.0000} : {1:0.0000}", m.Light.ProductIon, mrm.IsPaired ? m.Heavy.ProductIon : 0); TreeNode subNode = node.Nodes.Add(ions); subNode.Tag = m; subNode.Checked = m.Enabled; }); }
private void tcFiles_SelectedIndexChanged(object sender, EventArgs e) { if (tcFiles.TabCount > 0 && tcFiles.SelectedTab != null) { var fileName = tcFiles.SelectedTab.Text; files.Compounds.ForEach(m => m.FileName = fileName); gvCompounds.Refresh(); filePeptide = currentCompound.GetPeptideItem(fileName); gvProductPair.DataSource = filePeptide.ProductIonPairs; } }
private static void WritePeptide(StreamWriter sw, SrmPairedPeptideItem pep, Color c) { String strHtmlColor = System.Drawing.ColorTranslator.ToHtml(c); sw.WriteLine("<font color=\"{0}\">", strHtmlColor); sw.WriteLine("{0} - {1} : {2:0.0000} - {3:0.0000}<br>", pep.ProductIonPairs[0].ObjectName, pep.ProductIonPairs[0].PrecursorFormula, pep.LightPrecursorMZ, pep.HeavyPrecursorMZ); sw.WriteLine("</font>"); sw.WriteLine("<table border=\"1\">"); sw.WriteLine("<tr>"); sw.WriteLine("<th scope=\"col\">Enabled</th>"); sw.WriteLine("<th scope=\"col\">Light</th>"); sw.WriteLine("<th scope=\"col\">Heavy</th>"); sw.WriteLine("<th scope=\"col\">Ratio</th>"); sw.WriteLine("<th scope=\"col\">Correl</th>"); sw.WriteLine("<th scope=\"col\">ValidScan</th>"); sw.WriteLine("</tr>"); foreach (var ion in pep.ProductIonPairs) { sw.WriteLine("<tr>"); if (ion.Enabled) { sw.WriteLine("<td><input type=\"checkbox\" checked=\"checked\"></td>"); } else { sw.WriteLine("<td><input type=\"checkbox\"></td>"); } sw.WriteLine("<td>{0:0.0000}</td>", ion.LightProductIon); sw.WriteLine("<td>{0:0.0000}</td>", ion.HeavyProductIon); if (double.IsNaN(ion.Ratio) || double.IsInfinity(ion.Ratio)) { sw.WriteLine("<td></td>"); sw.WriteLine("<td></td>"); } else { sw.WriteLine("<td>{0:0.0000}</td>", ion.Ratio); sw.WriteLine("<td>{0:0.0000}</td>", ion.RegressionCorrelation); } sw.WriteLine("<td>{0}</td>", ion.EnabledScanCount); sw.WriteLine("</tr>"); } sw.WriteLine("</table>"); }
/// <summary> /// 根据Ion来合并轻重标结果。如果自动识别未能把成对的肽段合并,就需要手工合并。 /// </summary> /// <param name="heavy">重标肽段</param> public void SetHeavyPeptideItemByIon(SrmPairedPeptideItem heavy) { foreach (var light in this.ProductIonPairs) { var ion = light.Light.Ion; foreach (var h in heavy.ProductIonPairs) { if (ion.Equals(h.Light.Ion)) { light.SetHeavyIon(h); heavy.ProductIonPairs.Remove(h); break; } } } this.ProductIonPairs.RemoveAll(m => m.Heavy == null); }
private void mnuSetScanEnabledOnlyToolStripMenuItem_Click(object sender, EventArgs e) { GraphPane graphScans = mnuSetScanEnabledOnlyToolStripMenuItem.Tag as GraphPane; double min = graphScans.XAxis.Scale.Min; double max = graphScans.XAxis.Scale.Max; SrmPairedProductIon ion = graphScans.Tag as SrmPairedProductIon; SrmPairedPeptideItem item = FindItemByProductIon(ion); if (null == item) { return; } item.SetEnabledRetentionTimeRange(min, max); mrmPairs.Update(item); UpdateProductPairs(); DoUpdateProductIon(); tvMRM_AfterSelect(null, null); }
private void gvFiles_SelectionChanged(object sender, EventArgs e) { if (gvFiles.SelectedRows.Count == 0) { return; } var fis = currentItems[gvFiles.SelectedRows[0].Index].Items; currentCompound = new SrmPairedPeptideItem(); for (int i = 0; i < fis.Count; i++) { if (fis[i] == null) { currentCompound.ProductIonPairs.Add(null); } else { currentCompound.ProductIonPairs.Add(fis[i].PairedProductIon); } } UpdateGraph(); }
private CompoundItem FindCompoundByPeptide(SrmPairedPeptideItem item) { return(files.Compounds.FirstOrDefault(m => m.HasPeptideItem(item))); }
public UpdateMRMPairedPeptideItemEventArgs(SrmPairedPeptideItem item, SrmViewOption viewOption) : base() { this.Item = item; this.ViewOption = viewOption; }
private bool IsPeptideInvalid(SrmPairedPeptideItem pep) { return(pep == null || pep.Ratio == -1 || (exportInvalidCompoundAsNA.Checked && !pep.Enabled)); }
private void WriteImage(string imageDir, string imageDirName, StreamWriter sw, SrmPairedPeptideItem pep) { var imageFile = MyConvert.Format("{0}\\{1}.png", imageDir, pep.PrecursorFormula); zgcPeptide.GetImage().Save(imageFile, ImageFormat.Png); sw.WriteLine("<img src=\"{0}/{1}.png\" width=\"800\" /><br>", imageDirName, pep.PrecursorFormula); sw.WriteLine("<hr>"); }
public bool HasPeptideItem(SrmPairedPeptideItem item) { return(TransitionItems.Any(m => m.FileItems.Any(n => n.PairedPeptide == item))); }
public bool PrecursorEquals(SrmPairedPeptideItem another, double mzTolerance) { return((Math.Abs(this.LightPrecursorMZ - another.LightPrecursorMZ) <= mzTolerance) && (Math.Abs(this.HeavyPrecursorMZ - another.HeavyPrecursorMZ) <= mzTolerance)); }
/// <summary> /// 合并两个peptideitem。如果自动识别未能把来自同一个肽段的不同transaction合并,就需要手工合并。 /// </summary> /// <param name="another">同一个肽段(对)的其他部分</param> public void MergePeptideItem(SrmPairedPeptideItem another) { this.ProductIonPairs.AddRange(another.ProductIonPairs); }
/// <summary> /// 判断另外一个肽段是否是这个肽段的配对肽段,要求该肽段与本肽段的所有子离子质荷比完全相同,或者差值在给定允许集合内。 /// 允许两个肽段只有部分离子相等或者差值在给定集合内。 /// </summary> /// <param name="another">另一个肽段</param> /// <param name="allowedGaps">子离子质荷比之差的容许值集合</param> /// <param name="mzTolerance">质荷比阈值</param> /// <returns>配对是否成功</returns> public bool AddErrorPairedPeptideItem(SrmPairedPeptideItem another, double[] allowedGaps, double mzTolerance, double rtTolerance) { if (another == null) { return(false); } if (!RetentionTimeEqualsTo(another, rtTolerance)) { return(false); } List <double> thisions = (from p in this.ProductIonPairs orderby p.Light.ProductIon select p.Light.ProductIon).ToList(); List <double> anotherions = (from p in another.ProductIonPairs select p.Light.ProductIon).ToList(); List <Pair <double, double> > pairs = new List <Pair <double, double> >(); for (int i = thisions.Count - 1; i >= 0; i--) { for (int j = anotherions.Count - 1; j >= 0; j--) { if (thisions[i] == anotherions[j]) { pairs.Add(new Pair <double, double>(thisions[i], anotherions[j])); thisions.RemoveAt(i); anotherions.RemoveAt(j); break; } } } for (int i = thisions.Count - 1; i >= 0; i--) { for (int j = anotherions.Count - 1; j >= 0; j--) { var gap = Math.Abs(thisions[i] - anotherions[j]); if (InAllowedGap(gap, allowedGaps, mzTolerance)) { pairs.Add(new Pair <double, double>(thisions[i], anotherions[j])); thisions.RemoveAt(i); anotherions.RemoveAt(j); break; } } } if (pairs.Count == 0) { return(false); } if (thisions.Count > 0) { this.ProductIonPairs.RemoveAll(m => thisions.Contains(m.LightProductIon)); } if (anotherions.Count > 0) { another.ProductIonPairs.RemoveAll(m => anotherions.Contains(m.LightProductIon)); } SetHeavyPeptideItem(another); return(true); }
/// <summary> /// 判断目标肽段与本肽段的保留时间是否一致 /// </summary> /// <param name="another">目标肽段</param> /// <param name="rtToleranceMilliseconds">保留时间阈值</param> /// <returns></returns> public bool RetentionTimeEqualsTo(SrmPairedPeptideItem another, double rtToleranceMilliseconds) { return(this.ProductIonPairs[0].Light.RetentionTimeEqualsTo(another.ProductIonPairs[0].Light, rtToleranceMilliseconds)); }
private SrmPairedPeptideItem ItemToPeptide(XElement item) { if (item == null) { return(null); } SrmPairedPeptideItem result = new SrmPairedPeptideItem(); result.Enabled = Convert.ToBoolean(item.Element("Enabled").Value); result.ProductIonPairs = new List <SrmPairedProductIon>(); foreach (var p in item.Descendants("ProductIonPair")) { SrmPairedProductIon ion = new SrmPairedProductIon(); ion.Enabled = Convert.ToBoolean(p.Element("Enabled").Value); ion.Ratio = MyConvert.ToDouble(p.Element("Ratio").Value); ion.Distance = MyConvert.ToDouble(p.Element("Distance").Value); ion.RegressionCorrelation = MyConvert.ToDouble(p.Element("RegressionCorrelation").Value); var scanEle = p.Elements("Scan"); if (scanEle.Count() > 0) { var scans = (from a in scanEle select new SrmPairedScan() { Light = SrmScanFileFormat.ElementToScan(a.Element("Light")), Heavy = SrmScanFileFormat.ElementToScan(a.Element("Heavy")) }).ToList(); if (scans.Count > 0) { if (scans[0].Light != null) { var light = new SrmTransition(scans[0].Light.PrecursorMz, scans[0].Light.ProductMz); light.Intensities = (from s in scans select s.Light).ToList(); ion.Light = light; } if (scans[0].Heavy != null) { var heavy = new SrmTransition(scans[0].Heavy.PrecursorMz, scans[0].Heavy.ProductMz); heavy.Intensities = (from s in scans select s.Heavy).ToList(); ion.Heavy = heavy; } } } else { ion.Light = ElementToTransaction(p.Element("LightTransaction")); ion.Heavy = ElementToTransaction(p.Element("HeavyTransaction")); } if (p.Element("LightArea") != null) { ion.LightArea = MyConvert.ToDouble(p.Element("LightArea").Value); ion.HeavyArea = MyConvert.ToDouble(p.Element("HeavyArea").Value); } result.ProductIonPairs.Add(ion); } if (item.Element("Ratio") != null) { result.Ratio = MyConvert.ToDouble(item.Element("Ratio").Value); if (item.Element("SD").Value.Equals("-")) { result.SD = double.NaN; } else { result.SD = MyConvert.ToDouble(item.Element("SD").Value); } } else { result.CalculatePeptideRatio(); } var objname = string.Empty; var pepname = string.Empty; var pepcharge = 0; if (item.Element("ObjectName") != null) { objname = item.Element("ObjectName").Value; } if (item.Element("PrecursorFormula") != null) { pepname = item.Element("PrecursorFormula").Value; } if (item.Element("PrecursorCharge") != null) { pepcharge = int.Parse(item.Element("PrecursorCharge").Value); } result.ProductIonPairs.ForEach(m => { if (m.Light != null) { m.Light.ObjectName = objname; m.Light.PrecursorFormula = pepname; m.Light.PrecursorCharge = pepcharge; } if (m.Heavy != null) { m.Heavy.ObjectName = objname; m.Heavy.PrecursorFormula = pepname; m.Heavy.PrecursorCharge = pepcharge; } }); return(result); }