/// <summary>
        /// 本transaction与另一个transaction的保留时间是否一致。标准是起始和终止时间的差值都在给定阈值范围内。
        /// </summary>
        /// <param name="other">另一个transaction</param>
        /// <param name="rtToleranceInSecond">保留时间阈值</param>
        /// <returns>true/false</returns>
        public bool RetentionTimeEqualsTo(SrmTransition other, double rtToleranceInSecond)
        {
            var startGap = Math.Abs(this.Intensities[0].RetentionTime - other.Intensities[0].RetentionTime);
            var endGap   = Math.Abs(this.Intensities.Last().RetentionTime - other.Intensities.Last().RetentionTime);

            return((startGap <= rtToleranceInSecond) && (endGap <= rtToleranceInSecond));
        }
Example #2
0
        public void Select(SrmTransition trans)
        {
            var intensities = (from s in trans.Intensities
                               where s.Intensity > 0
                               orderby s.Intensity
                               select s.Intensity).ToList();

            if (intensities.Count > 0)
            {
                int selectedCount = (int)(intensities.Count * this.lowestPercentageForBaseline);
                if (selectedCount > 0)
                {
                    trans.Noise = intensities.Take(selectedCount).Average();

                    var minIntensity = trans.Noise * minFactor;

                    trans.Intensities.ForEach(m => m.Enabled = m.Intensity >= minIntensity);

                    trans.KeepHighestContig();

                    return;
                }
                else
                {
                    trans.Noise = intensities.Average();
                }
            }
            else
            {
                trans.Noise = 1.0;
            }

            trans.Intensities.ForEach(m => m.Enabled = false);
        }
        public SrmPairedProductIon(SrmTransition light, SrmTransition heavy)
        {
            this.Enabled = true;

            this.Light = light;
            this.Heavy = heavy;
        }
Example #4
0
        private SrmTransition ElementToTransaction(XElement xElement)
        {
            if (xElement == null)
            {
                return(null);
            }

            SrmTransition result = new SrmTransition(0, 0);

            if (xElement.Element("Noise") != null)
            {
                result.Noise = MyConvert.ToDouble(xElement.Element("Noise").Value);
            }
            if (xElement.Element("SignalToNoise") != null)
            {
                result.SignalToNoise = MyConvert.ToDouble(xElement.Element("SignalToNoise").Value);
            }

            result.Intensities = (from a in xElement.Descendants("Scan")
                                  select SrmScanFileFormat.ElementToScan(a)).ToList();

            if (result.Intensities.Count > 0)
            {
                result.PrecursorMZ = result.Intensities[0].PrecursorMz;
                result.ProductIon  = result.Intensities[0].ProductMz;
            }

            return(result);
        }
        private double GetMaxIntensity(SrmTransition trans)
        {
            if (trans == null)
            {
                return(0.0);
            }

            return(trans.Intensities.Max(m => m.Intensity));
        }
        private double GetMaxIntensity(SrmTransition trans, Func <SrmScan, bool> valid)
        {
            if (trans == null || trans.EnabledCount == 0)
            {
                return(0.0);
            }

            return((from scan in trans.Intensities
                    where valid(scan)
                    select scan.Intensity).Max());
        }
        public void CopyData(SrmTransition mrm)
        {
            if (this == mrm)
            {
                return;
            }

            this.Intensities.Clear();
            this.Intensities.AddRange(mrm.Intensities);
            this.Noise         = mrm.Noise;
            this.SignalToNoise = mrm.SignalToNoise;
        }
        private double GetArea(SrmTransition trans)
        {
            if (trans != null)
            {
                var enabled = (from s in trans.Intensities
                               where s.Enabled
                               select s.Intensity).ToList();

                return(_deductBaseLine ? enabled.Sum() - Noise * enabled.Count : enabled.Sum());
            }

            return(0.0);
        }
Example #9
0
        private XElement TransactionToElement(SrmTransition trans, string name)
        {
            if (trans == null)
            {
                return(null);
            }

            return(new XElement(name,
                                new XElement("Noise", trans.Noise),
                                new XElement("SignalToNoise", trans.SignalToNoise),
                                from s in trans.Intensities
                                select SrmScanFileFormat.ScanToElement(s, "Scan")));
        }
Example #10
0
        private void AddAbsoluteCurve2(SrmTransition trans, double factor, Color color)
        {
            if (trans == null || trans.Intensities == null || trans.Intensities.Count == 0)
            {
                return;
            }

            var item = trans.Intensities;

            var ppl = new PointPairList();

            item.ForEach(m => ppl.Add(m.RetentionTime, m.Intensity * factor));
            var line = panel.AddCurve("", ppl, color, SymbolType.None);

            line.Line.Style = System.Drawing.Drawing2D.DashStyle.DashDot;
        }
Example #11
0
        public void Select(SrmTransition trans)
        {
            var maxIntensity = trans.Intensities.Max(m => m.Intensity);

            if (maxIntensity > 0)
            {
                double minIntensity = maxIntensity * percentage;

                trans.Intensities.ForEach(m => m.Enabled = m.Intensity >= minIntensity);

                trans.KeepHighestContig();
            }
            else
            {
                trans.Intensities.ForEach(m => m.Enabled = false);
            }
        }
Example #12
0
        private void AddAbsoluteCurve(SrmTransition trans, string title, Color color, DashStyle dStyle)
        {
            if (trans == null || trans.Intensities == null || trans.Intensities.Count == 0)
            {
                return;
            }

            var item = trans.Intensities;

            var ppl = new PointPairList();

            item.ForEach(m => ppl.Add(m.RetentionTime, m.Intensity));
            var line = panel.AddCurve(MyConvert.Format("{0}, {1:0.00}-{2:0.00}", title, item[0].PrecursorMz, item[0].ProductMz), ppl, color, SymbolType.None);

            line.Line.Style = dStyle;

            var  pplCurve = new PointPairList();
            bool bChecked = false;

            item.ForEach(envelope =>
            {
                if (envelope.Enabled != bChecked)
                {
                    if (pplCurve.Count > 0)
                    {
                        if (bChecked)
                        {
                            panel.AddPoly("", pplCurve, color, new[] { SilacQuantificationConstants.PLOY_COLOR });
                        }
                    }
                    pplCurve = new PointPairList();
                    bChecked = envelope.Enabled;
                }

                pplCurve.Add(envelope.RetentionTime, envelope.Intensity);
            });

            if (pplCurve.Count > 0)
            {
                if (bChecked)
                {
                    panel.AddPoly("", pplCurve, color, new[] { SilacQuantificationConstants.PLOY_COLOR });
                }
            }
        }
        public void PeakPicking(IRangeSelection peakPicking)
        {
            if (Light == null && Heavy == null)
            {
                return;
            }

            CheckAlignment();

            //找到轻重标记中最高峰所在transaction
            SrmTransition maxTrans = null;
            SrmTransition another  = null;

            if (Light == null)
            {
                maxTrans = Heavy;
            }
            else if (Heavy == null)
            {
                maxTrans = Light;
            }
            else if (LightMaxIntensity > HeavyMaxIntensity)
            {
                maxTrans = Light;
                another  = Heavy;
            }
            else
            {
                maxTrans = Heavy;
                another  = Light;
            }

            peakPicking.Select(maxTrans);

            //设置另外一半相对应的区域。
            if (another != null)
            {
                for (int i = 0; i < maxTrans.Intensities.Count; i++)
                {
                    another.Intensities[i].Enabled = maxTrans.Intensities[i].Enabled;
                }
            }
        }
Example #14
0
        private List <SrmTransition> ScanToTransaction(List <SrmScan> mrmIntensities)
        {
            //赋值所有MRMTransaction
            Dictionary <string, SrmTransition> mrmMap = new Dictionary <string, SrmTransition>();
            SrmTransition action = new SrmTransition(0, 0);

            foreach (var scan in mrmIntensities)
            {
                //合并ProductIon完全一样的Item
                action.PrecursorMZ = scan.PrecursorMz;
                action.ProductIon  = scan.ProductMz;
                var key = action.ToString();
                if (!mrmMap.ContainsKey(key))
                {
                    mrmMap[key] = action;
                    action.Intensities.Add(scan);
                    action = new SrmTransition(0, 0);
                }
                else
                {
                    mrmMap[key].Intensities.Add(scan);
                }
            }

            //获取检测到的MRM Transaction
            var mrms = (from m in mrmMap.Values
                        orderby m.PrecursorMZ, m.ProductIon
                        select m).ToList();

            //合并时间差距在1分钟,母离子、子离子均在给定阈值范围内的transition。
            for (int i = mrms.Count - 1; i >= 0; i--)
            {
                for (int j = i - 1; j >= 0; j--)
                {
                    if (Math.Abs(mrms[i].PrecursorMZ - mrms[j].PrecursorMZ) < options.MzTolerance &&
                        Math.Abs(mrms[i].ProductIon - mrms[j].ProductIon) < options.MzTolerance)
                    {
                        if (mrms[i].LastRetentionTime < mrms[j].FirstRetentionTime)
                        {
                            if (mrms[j].FirstRetentionTime - mrms[i].LastRetentionTime < 1)
                            {
                                mrms[j].Intensities.InsertRange(0, mrms[i].Intensities);
                                mrms.RemoveAt(i);
                                break;
                            }
                        }
                        else if (mrms[j].LastRetentionTime < mrms[i].FirstRetentionTime)
                        {
                            if (mrms[i].FirstRetentionTime - mrms[j].LastRetentionTime < 1)
                            {
                                mrms[j].Intensities.AddRange(mrms[i].Intensities);
                                mrms.RemoveAt(i);
                                break;
                            }
                        }
                    }
                }
            }

            //平滑
            if (this.options.AskForSmooth)
            {
                mrms.ForEach(m => m.Smoothing());
            }
            return(mrms);
        }
 public SrmPairedProductIon(SrmTransition light)
 {
     this.Enabled = true;
     this.Light   = light;
 }
 public bool ActualRtMatch(SrmTransition mrm, double rtTolerance)
 {
     return(Math.Abs(this.ActualCenterRetentionTime - mrm.ActualCenterRetentionTime) < rtTolerance);
 }
 public bool MzMatch(SrmTransition mrm, double mzTolerance)
 {
     return(Math.Abs(this.PrecursorMZ - mrm.PrecursorMZ) < mzTolerance &&
            Math.Abs(this.ProductIon - mrm.ProductIon) < mzTolerance);
 }
 public void SetHeavyIon(SrmPairedProductIon heavy)
 {
     this.Heavy = heavy.Light;
 }
 /// <summary>
 /// 判断两个transaction是否来自同一个precursor。判断依据是母离子质量差在一定范围,同时保留时间差也在一定范围。
 /// </summary>
 /// <param name="other">另一个transaction</param>
 /// <param name="rtToleranceInSecond">保留时间阈值</param>
 /// <param name="precursorMzTolerance">母离子质荷比阈值</param>
 /// <returns>true/false</returns>
 public bool IsBrother(SrmTransition other, double rtToleranceInSecond, double precursorMzTolerance)
 {
     return(Math.Abs(PrecursorMZ - other.PrecursorMZ) < precursorMzTolerance && RetentionTimeEqualsTo(other, rtToleranceInSecond));
 }
Example #20
0
        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);
        }