예제 #1
0
        public void TestMatch()
        {
            var factory = new MockRepository(MockBehavior.Strict);

            PeakList <MatchedPeak> expPeaks = new PeakList <MatchedPeak>()
            {
                new MatchedPeak(165.00, 1, 1),
                new MatchedPeak(182.40, 1, 1),
                new MatchedPeak(982.5, 1, 1)
            };

            expPeaks.PrecursorCharge = 1;

            var sr = factory.Create <IIdentifiedPeptideResult>();

            sr.Setup(x => x.GetIonSeries()).Returns(dic);
            sr.Setup(x => x.Peptide).Returns("K.S*R.F");
            sr.Setup(x => x.ExperimentalPeakList).Returns(expPeaks);

            matcher.Match(sr.Object);

            PeakList <MatchedPeak> annotatedPeaks = sr.Object.ExperimentalPeakList;

            AssertPeak(annotatedPeaks[0], "[b2-H2O-NH3]", 165);
            AssertPeak(annotatedPeaks[1], "[b2-H2O]", 182.40);
            AssertPeak(annotatedPeaks[2], "[y1-NH3]", 982.5);
        }
        public void WriteElementPeakList(XmlWriter xw, PeakList <Peak> pkls, string pklName, bool isPeakInWindow)
        {
            xw.WriteStartElement(pklName);

            foreach (var p in pkls)
            {
                xw.WriteStartElement("Peak");
                xw.WriteAttributeFormat("mz", "{0:0.#####}", p.Mz);
                xw.WriteAttributeFormat("intensity", "{0:0.0}", p.Intensity);
                xw.WriteAttribute("charge", p.Charge);
                if (isPeakInWindow)
                {
                    xw.WriteAttribute("tag", p.Tag);
                }
                xw.WriteEndElement();
            }

            if (isPeakInWindow)
            {
                xw.WriteStartElement("Precursor");
                xw.WriteElement("MasterScan", pkls.Precursor.MasterScan);
                xw.WriteElementFormat("MonoIsotopicMass", "{0:0.00000}", pkls.Precursor.MonoIsotopicMass);
                xw.WriteElementFormat("IsolationMass", "{0:0.00000}", pkls.Precursor.IsolationMass);
                xw.WriteElementFormat("IsolationWidth", "{0:0.00}", pkls.Precursor.IsolationWidth);
                xw.WriteElement("Charge", pkls.Precursor.Charge);
                xw.WriteElementFormat("Intensity", "{0:0.0}", pkls.Precursor.Intensity);
                xw.WriteEndElement();
            }

            xw.WriteEndElement();
        }
        protected void WritePeak(StreamWriter writer, PeakList <T> pl)
        {
            PeakList <T> pkl;

            //Mascot Generic Format 要求每个spectrum不能超过10000个离子。
            if (pl.Count > 10000)
            {
                pkl = new PeakList <T>(pl);
                pkl.SortByIntensity();
                pkl.RemoveRange(10000, pkl.Count - 10000);
                pkl.SortByMz();
            }
            else
            {
                pkl = pl;
            }

            //if (pkl.Any(m => m.Charge > 0))
            //{
            //  foreach (T peak in pkl)
            //  {
            //    writer.WriteLine(MyConvert.Format("{0:0.#####} {1:0.0} {2}", peak.Mz, peak.Intensity, peak.Charge));
            //  }
            //}
            //else
            //{
            foreach (T peak in pkl)
            {
                writer.WriteLine(MyConvert.Format("{0:0.#####} {1:0.0###}", peak.Mz, peak.Intensity));
            }
            //}

            writer.WriteLine(MascotGenericFormatConstants.END_PEAK_LIST_TAG);
            writer.WriteLine();
        }
예제 #4
0
        public void TestMatch()
        {
            var factory = new MockRepository(MockBehavior.Strict);

            PeakList <MatchedPeak> expPeaks = new PeakList <MatchedPeak>()
            {
                new MatchedPeak(902.02, 1, 1),
                new MatchedPeak(920.03, 1, 1),
                new MatchedPeak(822.06, 1, 1),
                new MatchedPeak(884.01, 1, 1),
                new MatchedPeak(885, 1, 1),
                new MatchedPeak(903, 1, 1)
            };

            expPeaks.PrecursorCharge = 1;
            expPeaks.PrecursorMZ     = 1000.0;

            var sr = factory.Create <IIdentifiedPeptideResult>();

            sr.Setup(x => x.Peptide).Returns("K.S*Y*R.F");
            sr.Setup(x => x.ExperimentalPeakList).Returns(expPeaks);

            matcher.Match(sr.Object);

            AssertPeak(expPeaks[0], "[MH-H3PO4]", 902.023104375);
            AssertPeak(expPeaks[1], "[MH-HPO3]", 920.033669075);
            AssertPeak(expPeaks[2], "[MH-H3PO4-HPO3]", 822.05677345);
            AssertPeak(expPeaks[3], "[MH-H3PO4-H2O]", 884.012539675);
            AssertPeak(expPeaks[4], "[MH-H3PO4-NH3]", 884.99655527);
            AssertPeak(expPeaks[5], "[MH-HPO3-NH3]", 903.00711997);
        }
        public void TestMatch()
        {
            PrecursorNeutralLossMatcher matcher = new PrecursorNeutralLossMatcher(0.5, 0.0);
            var factory = new MockRepository(MockBehavior.Strict);

            var sr = factory.Create <IIdentifiedPeptideResult>();

            sr.Setup(x => x.Peptide).Returns("K.S*R.A");

            PeakList <MatchedPeak> expPeaks = new PeakList <MatchedPeak>()
            {
                new MatchedPeak(964.96, 1, 1),
                new MatchedPeak(981.99, 1, 1),
                new MatchedPeak(982.97, 1, 1)
            };

            expPeaks.PrecursorCharge = 1;
            expPeaks.PrecursorMZ     = 1000.0;

            sr.Setup(x => x.ExperimentalPeakList).Returns(expPeaks);

            matcher.Match(sr.Object);

            Assert.AreEqual("[MH-H2O-NH3]", expPeaks[0].DisplayName);
            Assert.AreEqual("[MH-H2O]", expPeaks[1].DisplayName);
            Assert.AreEqual("[MH-NH3]", expPeaks[2].DisplayName);
        }
        public void TestGetPeakList()
        {
            PeakList <Peak> pkl = reader.GetPeakList(1);

            Assert.AreEqual(397, pkl.Count);
            Assert.AreEqual(301.1257, pkl[0].Mz, 0.0001);
        }
        public static int GuessPrecursorCharge <T>(PeakList <T> pkl, double precursorMz) where T : IPeak
        {
            double fSumTotal = 0.0;
            double fSumBelow = 0.0;

            foreach (T peak in pkl)
            {
                if (peak.Mz < precursorMz)
                {
                    fSumBelow += peak.Intensity;
                }

                fSumTotal += peak.Intensity;
            }

            /*
             * If greater than 95% signal is below precursor, then
             * it looks like singly charged peptide.
             */
            if (fSumTotal == 0.0 || fSumBelow / fSumTotal > 0.95)
            {
                return(1);
            }

            return(0);
        }
        public RetentionTimePeak ReadFromFile(string fileName)
        {
            var result = new RetentionTimePeak();

            var root = XElement.Load(fileName);

            result.Mz             = MyConvert.ToDouble(root.Element("Mz").Value);
            result.Charge         = Convert.ToInt32(root.Element("Charge").Value);
            result.Intensity      = MyConvert.ToDouble(root.Element("Intensity").Value);
            result.MzTolerance    = MyConvert.ToDouble(root.Element("MzTolerance").Value);
            result.RententionTime = MyConvert.ToDouble(root.Element("RententionTime").Value);
            result.Initialize();

            var chro = root.Element("Chro");

            foreach (var scan in chro.Elements("Scan"))
            {
                PeakList <Peak> pkl = new PeakList <Peak>(
                    (from p in scan.Elements("Peak")
                     let mz = MyConvert.ToDouble(p.Attribute("m").Value)
                              let intensity = MyConvert.ToDouble(p.Attribute("i").Value)
                                              select new Peak(mz, intensity)).ToList());

                pkl.ScanTimes.Add(new ScanTime(
                                      Convert.ToInt32(scan.Attribute("s").Value),
                                      MyConvert.ToDouble(scan.Attribute("r").Value)));

                result.Chromotographs.Add(pkl);
            }

            return(result);
        }
    public void TestMatch()
    {
      var factory = new MockRepository(MockBehavior.Strict);

      PeakList<MatchedPeak> expPeaks = new PeakList<MatchedPeak>()
      {
        new MatchedPeak(902.02, 1,1),
        new MatchedPeak(920.03, 1,1),
        new MatchedPeak(822.06, 1,1),
        new MatchedPeak(884.01, 1,1),
        new MatchedPeak(885, 1,1),
        new MatchedPeak(903, 1,1)
      };
      expPeaks.PrecursorCharge = 1;
      expPeaks.PrecursorMZ = 1000.0;

      var sr = factory.Create<IIdentifiedPeptideResult>();
      sr.Setup(x => x.Peptide).Returns("K.S*Y*R.F");
      sr.Setup(x => x.ExperimentalPeakList).Returns(expPeaks);

      matcher.Match(sr.Object);

      AssertPeak(expPeaks[0], "[MH-H3PO4]", 902.023104375);
      AssertPeak(expPeaks[1], "[MH-HPO3]", 920.033669075);
      AssertPeak(expPeaks[2], "[MH-H3PO4-HPO3]", 822.05677345);
      AssertPeak(expPeaks[3], "[MH-H3PO4-H2O]", 884.012539675);
      AssertPeak(expPeaks[4], "[MH-H3PO4-NH3]", 884.99655527);
      AssertPeak(expPeaks[5], "[MH-HPO3-NH3]", 903.00711997);
    }
    public void TestMatch()
    {
      PrecursorNeutralLossMatcher matcher = new PrecursorNeutralLossMatcher(0.5, 0.0);
      var factory = new MockRepository(MockBehavior.Strict);

      var sr = factory.Create<IIdentifiedPeptideResult>();
      sr.Setup(x => x.Peptide).Returns("K.S*R.A");

      PeakList<MatchedPeak> expPeaks = new PeakList<MatchedPeak>()
      {
        new MatchedPeak(964.96, 1,1),
        new MatchedPeak(981.99, 1,1),
        new MatchedPeak(982.97, 1,1)
      };
      expPeaks.PrecursorCharge = 1;
      expPeaks.PrecursorMZ = 1000.0;

      sr.Setup(x => x.ExperimentalPeakList).Returns(expPeaks);

      matcher.Match(sr.Object);

      Assert.AreEqual("[MH-H2O-NH3]", expPeaks[0].DisplayName);
      Assert.AreEqual("[MH-H2O]", expPeaks[1].DisplayName);
      Assert.AreEqual("[MH-NH3]", expPeaks[2].DisplayName);
    }
예제 #11
0
        /// <summary>
        /// 合并集合中来自相同scan的离子列表,保留第一个,将precursorCharge设置为0
        /// </summary>
        /// <param name="pklList">离子列表集合</param>
        public static void MergeSameScan(List <PeakList <Peak> > pklList)
        {
            pklList.Sort((m1, m2) =>
            {
                int result = m1.Experimental.CompareTo(m2.Experimental);

                if (0 == result)
                {
                    result = m1.FirstScan - m2.FirstScan;
                }

                if (0 == result)
                {
                    result = m1.PrecursorCharge - m2.PrecursorCharge;
                }

                return(result);
            });

            for (int i = pklList.Count - 1; i > 0; i--)
            {
                PeakList <Peak> iPkl = pklList[i];
                PeakList <Peak> jPkl = pklList[i - 1];
                if (iPkl.Experimental.Equals(jPkl.Experimental) && iPkl.FirstScan == jPkl.FirstScan && iPkl.FirstScan != 0)
                {
                    jPkl.PrecursorCharge = 0;
                    pklList.RemoveAt(i);
                }
            }
        }
예제 #12
0
        public static PeakList <Peak> ReadElementPeakList(XElement ions, bool isPeakInWindow)
        {
            var result = new PeakList <Peak>();

            foreach (var p in ions.FindElements("Peak"))
            {
                var mz        = double.Parse(p.FindAttribute("mz").Value);
                var intensity = double.Parse(p.FindAttribute("intensity").Value);
                var charge    = int.Parse(p.FindAttribute("charge").Value);
                var peak      = new Peak(mz, intensity, charge);
                if (isPeakInWindow)
                {
                    peak.Tag = int.Parse(p.FindAttribute("tag").Value);
                }
                result.Add(peak);
            }

            if (isPeakInWindow)
            {
                var precursor = ions.FindElement("Precursor");
                var dic       = precursor.ToDictionary();
                result.Precursor.MasterScan       = int.Parse(dic["MasterScan"].Value);
                result.Precursor.MonoIsotopicMass = double.Parse(dic["MonoIsotopicMass"].Value);
                result.Precursor.IsolationMass    = double.Parse(dic["IsolationMass"].Value);
                result.Precursor.IsolationWidth   = double.Parse(dic["IsolationWidth"].Value);
                result.Precursor.Charge           = int.Parse(dic["Charge"].Value);
                result.Precursor.Intensity        = double.Parse(dic["Intensity"].Value);
            }

            return(result);
        }
예제 #13
0
        public PeakList <T> Process(PeakList <T> t)
        {
            int[] checkCharges;
            if (0 == t.PrecursorCharge)
            {
                if (0 == this.defaultCharges.Length)
                {
                    return(t);
                }

                checkCharges = this.defaultCharges;
            }
            else
            {
                checkCharges = new[] { t.PrecursorCharge };
            }

            foreach (int charge in checkCharges)
            {
                double dMass = t.PrecursorMZ * charge;
                if (dMass >= this.minMass && dMass <= this.maxMass)
                {
                    return(t);
                }
            }
            return(null);
        }
 public QuanEnvelope(PeakList <Peak> source)
 {
     this.Enabled    = true;
     this.IsSelected = false;
     this.AddRange(source);
     this.ScanTimes.AddRange(source.ScanTimes);
 }
        public static PeakList <Peak> GetPeakInIsolationWindow(this IRawFile2 RawReader, int scan, double defaultIsolationWidth)
        {
            PeakList <Peak> result = new PeakList <Peak>();

            var precursor = RawReader.GetPrecursorPeakWithMasterScan(scan);

            if (precursor.MasterScan == 0)
            {
                return(result);
            }

            if (0 == precursor.IsolationWidth || precursor.IsolationWidth > 5.0)
            {
                precursor.IsolationWidth = defaultIsolationWidth;
            }

            var isolationWidth = precursor.IsolationWidth /= 2;

            var minMz = precursor.IsolationMass - isolationWidth;
            var maxMz = precursor.IsolationMass + isolationWidth;

            result           = RawReader.GetPeakList(precursor.MasterScan, minMz, maxMz);
            result.Precursor = precursor;

            return(result);
        }
예제 #16
0
        protected PeakList <T> FindEnvelope(PeakList <T> t, T peak, double mzTolerance)
        {
            IsotopicType itype = IsotopicType.NONE;
            var          env   = t.FindEnvelope(peak, mzTolerance, true);

            if (env.Count <= 2)
            {
                return(env);
            }

            for (int i = 1; i < env.Count; i++)
            {
                if (env[i].Intensity >= env[i - 1].Intensity) //递增
                {
                    if (itype == IsotopicType.DECREASING)     //如果前面是递减,则这次递增无效。
                    {
                        env.RemoveRange(i, env.Count - i);
                        break;
                    }
                }
                else//递减
                {
                    itype = IsotopicType.DECREASING;
                }
            }

            return(env);
        }
예제 #17
0
        public static PeakList <Peak> ReadElementPeakList(XmlReader reader, string pklName, bool isPeakInWindow)
        {
            var result = new PeakList <Peak>();

            reader.MoveToElement(pklName);
            reader.ReadStartElement();
            while (reader.LocalName.Equals("Peak"))
            {
                Peak p = new Peak();
                p.Mz        = reader.ReadAttributeAsDouble("mz");
                p.Intensity = reader.ReadAttributeAsDouble("intensity");
                p.Charge    = reader.ReadAttributeAsInt("charge");
                if (isPeakInWindow)
                {
                    p.Tag = reader.ReadAttributeAsInt("tag");
                }
                result.Add(p);
                reader.Read();
            }

            if (isPeakInWindow)
            {
                reader.MoveToElement("Precursor");
                reader.ReadStartElement("Precursor");
                result.Precursor.MasterScan       = reader.ReadElementAsInt("MasterScan");
                result.Precursor.MonoIsotopicMass = reader.ReadElementAsDouble("MonoIsotopicMass");
                result.Precursor.IsolationMass    = reader.ReadElementAsDouble("IsolationMass");
                result.Precursor.IsolationWidth   = reader.ReadElementAsDouble("IsolationWidth");
                result.Precursor.Charge           = reader.ReadElementAsInt("Charge");
                result.Precursor.Intensity        = reader.ReadElementAsDouble("Intensity");
            }

            return(result);
        }
        /// <summary>
        /// Find peak with exact charge or no charge information available
        /// </summary>
        /// <param name="lst"></param>
        /// <param name="mz"></param>
        /// <param name="charge"></param>
        /// <param name="mzTolerance"></param>
        /// <returns></returns>
        private List <T> FindPeakConsideringCharge(PeakList <T> lst, double mz, int charge, double mzTolerance)
        {
            var result = new List <T>();

            double minMz = mz - mzTolerance;
            double maxMz = mz + mzTolerance;

            foreach (var p in lst)
            {
                if (p.Mz < minMz)
                {
                    continue;
                }

                if (p.Mz > maxMz)
                {
                    break;
                }

                if (p.Charge == charge || p.Charge == 0)
                {
                    result.Add(p);
                }
            }

            return(result);
        }
예제 #19
0
        private O18QuanEnvelope GetCorrespondingEnvelope(IRawFile rawFile, double theoreticalMz, int charge, double mzTolerance, int scan)
        {
            PeakList <Peak> pkl = rawFile.GetPeakList(scan);

            if (pkl.ScanTimes.Count == 0)
            {
                pkl.ScanTimes.Add(new ScanTime(scan, rawFile.ScanToRetentionTime(scan)));
            }

            PeakList <Peak> O16 = pkl.FindEnvelopeDirectly(theoreticalMz, charge, mzTolerance, 4, () => new Peak());

            PeakList <Peak> O181 = pkl.FindEnvelopeDirectly(theoreticalMz + chargeGapMap1[charge], charge, mzTolerance, 2, () => new Peak());

            for (int i = 2; i < 4; i++)
            {
                if (O16[i].Intensity < O181[i - 2].Intensity)
                {
                    O16[i].Mz        = O181[i - 2].Mz;
                    O16[i].Intensity = O181[i - 2].Intensity;
                }
            }

            PeakList <Peak> O182 = pkl.FindEnvelopeDirectly(theoreticalMz + chargeGapMap2[charge], charge, mzTolerance, 2, () => new Peak());

            O16.AddRange(O182);

            return(new O18QuanEnvelope(O16));
        }
예제 #20
0
        public static void Alignment <T, U>(PeakList <T> lst1, PeakList <U> lst2, double ppmTolerance)
            where T : Peak
            where U : Peak
        {
            //Initialize score matrix
            var scores = new double[lst1.Count, lst2.Count];

            for (int i = 0; i < lst1.Count; i++)
            {
                var mz    = lst1[i].Mz;
                var delta = PrecursorUtils.ppm2mz(mz, ppmTolerance);
                var minMz = mz - delta;
                var maxMz = mz + delta;
                for (int j = 0; j < lst2.Count; j++)
                {
                    if (lst2[j].Mz < minMz)
                    {
                        scores[i, j] = 0;
                        continue;
                    }

                    if (lst2[j].Mz > maxMz)
                    {
                        for (int k = j; k < lst2.Count; k++)
                        {
                            scores[i, k] = 0;
                        }
                        break;
                    }

                    scores[i, j] = lst1[i].Intensity * lst2[j].Intensity;
                }
            }
        }
        protected override void DoWritePeakList(IRawFile rawReader, PeakList <Peak> pkl, string rawFileName, List <string> result)
        {
            var sw   = GetStreamWriter(rawReader, pkl.ScanMode, pkl.MsLevel, rawFileName);
            var scan = pkl.ScanTimes[0].Scan;

            if (pkl.MsLevel == 1)
            {
                sw.Flush();

                sw1Index.Write("{0}\t{1}\n", scan, sw.BaseStream.Position);

                sw.Write("S\t{0}\t{0}\n", scan);
                sw.Write("I\tRetTime\t{0:0.####}\n", pkl.ScanTimes[0].RetentionTime);

                foreach (Peak p in pkl)
                {
                    sw.Write("{0:0.#####} {1:0.#} {2}\n", p.Mz, p.Intensity, p.Charge);
                }
            }
            else
            {
                sw.WriteLine("S\t{0}\t{1}\t{2}", scan, scan, pkl.PrecursorMZ);
                int[] charges = 0 != pkl.PrecursorCharge ? new[] { pkl.PrecursorCharge } : new[] { 2, 3 };
                foreach (var charge in charges)
                {
                    sw.WriteLine("Z\t{0}\t{1:0.#####}", charge, PrecursorUtils.MzToMH(pkl.PrecursorMZ, charge, true));
                }
                foreach (var peak in pkl)
                {
                    sw.WriteLine("{0:0.#####}\t{1:0.#}", peak.Mz, peak.Intensity);
                }
            }
        }
        private void AddIonSeries(GraphPane peakPane, GraphPane ppmPane, PeakList <MatchedPeak> mgf, double mzTolerance, double minIntensity, IPeptideFragmentationBuilder <MatchedPeak> builder, string sequence, Color tagColor)
        {
            MatchedPeakUtils.Match(mgf, builder.Build(sequence), mzTolerance, minIntensity);

            var ionType     = builder.SeriesType.ToString();
            var matchedIons = (from m in mgf
                               where m.Matched && m.PeakType == builder.SeriesType
                               select m).ToList();

            var ppl = new PointPairList();

            foreach (var m in matchedIons)
            {
                ppl.Add(new PointPair(m.Mz, m.Intensity, m.Information));
            }

            peakPane.AddIndividualLine("", ppl, Color.Black, tagColor);

            if (ppmPane != null)
            {
                var diff = new PointPairList();
                foreach (var m in matchedIons)
                {
                    if (isPPM)
                    {
                        diff.Add(new PointPair(m.Mz, PrecursorUtils.mz2ppm(m.Mz, m.Mz - m.MatchedMZ)));
                    }
                    else
                    {
                        diff.Add(new PointPair(m.Mz, m.Mz - m.MatchedMZ));
                    }
                }
                ppmPane.AddPoints(diff, tagColor);
            }
        }
        public void TestDeisotopic()
        {
            var peaks = new PeakList <Peak>();

            peaks.Add(new Peak(101.0000, 10, 1));
            peaks.Add(new Peak(101.2000, 3, 0));
            peaks.Add(new Peak(102.0034, 20, 1));
            peaks.Add(new Peak(103.0067, 10, 1));
            peaks.Add(new Peak(104.0101, 20, 1));
            peaks.Add(new Peak(105.0134, 10, 1));

            //peaks.ForEach(m => Console.WriteLine(m));

            var cur = this.Process(peaks);

            Assert.AreEqual(4, cur.Count);

            //no charge
            Assert.AreEqual(101.2000, peaks[1].Mz, 0.1);

            //first envelope
            Assert.AreEqual(101.0000, peaks[0].Mz, 0.1);
            Assert.AreEqual(102.0034, peaks[2].Mz, 0.1);

            //second envelope
            Assert.AreEqual(104.0101, peaks[3].Mz, 0.1);
        }
예제 #24
0
        public PeakList <T> Process(PeakList <T> t)
        {
            var shiftMz = PrecursorUtils.ppm2mz(t.PrecursorMZ, ShiftPPM);

            t.PrecursorMZ = t.PrecursorMZ + shiftMz;
            return(t);
        }
        protected void AppendScan(List <IsobaricItem> result, int scan, string mode, double isolationWidth)
        {
            IsobaricItem item = new IsobaricItem();

            PeakList <Peak> pkl = RawReader.GetPeakList(scan, MinMz, MaxMz);

            if (pkl.Count < MinPeakCount)
            {
                return;
            }

            var recordScan = GetIdentificationScan(scan);

            if (pkl.ScanTimes.Count == 0)
            {
                pkl.ScanTimes.Add(RawReader.GetScanTime(recordScan));
            }

            item.ScanMode = mode;
            item.RawPeaks = pkl;
            item.PeakInIsolationWindow = RawReader.GetPeakInIsolationWindow(scan, isolationWidth);
            item.PlexType = this.PlexType;

            result.Add(item);
        }
        private double DoCalculateCorrelation(PeakList <Peak> Light, List <Peak> lightProfile)
        {
            double[] real = (from p in Light
                             select p.Intensity).ToArray();
            double[] theo = (from p in lightProfile
                             select p.Intensity).ToArray();

            return(StatisticsUtils.CosineAngle(real, theo));

            //double sumReal = real.Sum();

            //if (sumReal == 0)
            //{
            //  return 0;
            //}

            //real = (from r in real
            //        let s = r / sumReal
            //        select s).ToArray();

            //double[] pro = theo.Take(Light.Count).ToArray();
            //double sumPro = pro.Sum();
            //pro = (from p in pro
            //       let s = p / sumPro
            //       select s).ToArray();

            //return ScienceUtils.Correl(real, pro);
        }
        public PeakList <Peak> GetMassListFromScanNum(int scan, bool centroid)
        {
            var result = new PeakList <Peak>();

            if (IsBadDataScan(scan))
            {
                return(result);
            }

            object varMassList = null;
            object varFlags    = null;
            int    curScan     = scan;
            int    arraySize   = 0;

            int centroidResult = centroid ? 1 : 0;

            if (IsCentroidScanForScanNum(scan))
            {
                centroidResult = 0;
            }
            double centroidWidth = 0.0;

            try
            {
                this.rawFile.GetMassListFromScanNum(
                    ref curScan,
                    null,
                    0,
                    0,
                    0,
                    centroidResult,
                    ref centroidWidth,
                    ref varMassList,
                    ref varFlags,
                    ref arraySize);
            }
            catch
            {
                Console.WriteLine("reading from scan {0} of {1} error, skipped.", scan, FileName);
                WriteIgnoreScan(curScan);
                return(result);
            }

            CheckErrorCode("GetMassListFromScanNum  of " + scan.ToString() + " Error");

            if (varMassList == null)
            {
                return(result);
            }

            var datas = (double[, ])varMassList;

            for (int inx = 0; inx < arraySize; inx++)
            {
                result.Add(new Peak(datas[0, inx], datas[1, inx], 0));
            }

            return(result);
        }
        public void TestReadFromFile()
        {
            PeakList <Peak> spectrum = this.dtaFormat.ReadFromFile(this.testDtaFile);

            Assert.AreEqual(1736.6228, spectrum.PrecursorMZ, 0.001);
            Assert.AreEqual(2, spectrum.PrecursorCharge);
            Assert.AreEqual(23, spectrum.Count);
        }
예제 #29
0
 private XElement GetPeakListElement(string elementName, PeakList <Peak> pkl)
 {
     return(new XElement(elementName,
                         from peak in pkl
                         select new XElement("Peak",
                                             new XAttribute("Mz", MyConvert.Format("{0:0.0000}", peak.Mz)),
                                             new XAttribute("Intensity", MyConvert.Format("{0:0.0}", peak.Intensity)))));
 }
        public void TestGetPeakList()
        {
            PeakList <Peak> pkl = reader.GetPeakList(2);

            Assert.AreEqual(19, pkl.Count);
            Assert.AreEqual(149.0103, pkl[0].Mz, 0.0001);
            Assert.AreEqual(11918.0, pkl[0].Intensity, 0.1);
        }
        protected List <PeakList <Peak> > MergePeakList(List <PeakList <Peak> > pklList)
        {
            int index = 0;

            Progress.SetRange(0, pklList.Count);
            Progress.Begin();
            try
            {
                while (index < pklList.Count)
                {
                    if (Progress.IsCancellationPending())
                    {
                        throw new UserTerminatedException();
                    }
                    Progress.SetPosition(index);

                    PeakList <Peak> currentPkl = pklList[index];
                    double          maxGap     = PrecursorUtils.ppm2mz(currentPkl.PrecursorMZ, this.ppmPrecursorTolerance);

                    int next = index + 1;
                    while (next < pklList.Count)
                    {
                        PeakList <Peak> nextPkl          = pklList[next];
                        double          retentionTimeGap = nextPkl.ScanTimes[0].RetentionTime -
                                                           currentPkl.ScanTimes[0].RetentionTime;
                        if (retentionTimeGap > this.retentionTimeTolerance)
                        {
                            break;
                        }

                        if (nextPkl.PrecursorCharge != currentPkl.PrecursorCharge)
                        {
                            next++;
                            continue;
                        }

                        double precursorMzGap = Math.Abs(nextPkl.PrecursorMZ - currentPkl.PrecursorMZ);
                        if (precursorMzGap < maxGap)
                        {
                            currentPkl.MergeByMZFirst(nextPkl, this.ppmPeakTolerance);
                            pklList.RemoveAt(next);
                            continue;
                        }

                        next++;
                    }
                    index++;
                }
                Progress.SetPosition(pklList.Count);
            }
            finally
            {
                Progress.End();
            }

            return(pklList);
        }
 private bool IsWiff(PeakList <T> pkl)
 {
     if (pkl.Annotations.ContainsKey(MascotGenericFormatConstants.TITLE_TAG))
     {
         var title = (String)pkl.Annotations[MascotGenericFormatConstants.TITLE_TAG];
         return(title.ToLower().Contains(".wiff"));
     }
     return(false);
 }
예제 #33
0
    public void TestGetTitle()
    {
      var pkl = new PeakList<Peak>();
      pkl.ScanTimes.Add(new ScanTime(4135, 58.89));
      pkl.PrecursorMZ = 717.87;
      pkl.PrecursorIntensity = 10000;

      string actual = new TitleFormatCmpd().Build(pkl);
      Assert.AreEqual("Cmpd 4135, +MSn(717.87), 58.89 min", actual);
    }
예제 #34
0
    public void TestGetTitle()
    {
      var format = new TitleFormatSequest();
      var pkl = new PeakList<Peak>();
      pkl.Experimental = "TEST";
      pkl.ScanTimes.Add(new ScanTime(4135, 58.89));
      pkl.PrecursorCharge = 2;

      Assert.AreEqual("TEST.4135.4135.2.dta", format.Build(pkl));
    }
    public void TestProcess()
    {
      var peaks = new PeakList<Peak>();
      peaks.Add(new Peak(1.0, 1.0));
      peaks.Add(new Peak(2.0, 1.0));

      var processor = new PeakListMinIonCountProcessor<Peak>(3);
      Assert.AreSame(null, processor.Process(peaks));

      peaks.Add(new Peak(3.0, 1.0));
      Assert.AreSame(peaks, processor.Process(peaks));
    }
    public void TestProcess()
    {
      var peaks = new PeakList<Peak>();
      peaks.Add(new Peak(1.0, 10.0));
      peaks.Add(new Peak(2.0, 100.0));

      var processor1 = new PeakListMinTotalIonIntensityProcessor<Peak>(50.0);
      Assert.AreSame(peaks, processor1.Process(peaks));

      var processor2 = new PeakListMinIonIntensityProcessor<Peak>(150.0);
      Assert.AreSame(null, processor2.Process(peaks));
    }
 public void TestUpdatePrecursor()
 {
   var pkl = new PeakList<Peak>();
   pkl.Precursor = new PrecursorPeak(new Peak(1000.0, 1.0, 4));
   pkl.FirstScan = 620;
   pkl.Annotations["TITLE"] = "TCGA-AA-A01F-01A-23_W_VU_20120727_A0218_1B_R_FR04.620.620.4.dta";
   var titleFormat = TitleParserUtils.FindByName("DTA");
   MascotGenericFormatShiftPrecursorProcessor.UpdatePrecursor(titleFormat, pkl, -10.0, 10000);
   Assert.AreEqual(10620, pkl.FirstScan);
   Assert.AreEqual("TCGA-AA-A01F-01A-23_W_VU_20120727_A0218_1B_R_FR04.10620.10620.4.dta", pkl.Annotations["TITLE"]);
   Assert.AreEqual(997.5, pkl.PrecursorMZ, 0.1);
 }
예제 #38
0
    public void SetUp()
    {
      pl = new PeakList<Peak>();
      pl.Add(new Peak(430.0884, 43875.5, 1));

      pl.Add(new Peak(445.1205, 335180.5, 1));
      pl.Add(new Peak(446.1185, 51638.0, 1));
      pl.Add(new Peak(446.1255, 129918.6, 1));
      pl.Add(new Peak(447.1170, 30164.7, 1));

      pl.Add(new Peak(491.9578, 442529.3, 3));
      pl.Add(new Peak(492.2919, 206717.3, 3));
      pl.Add(new Peak(492.6270, 137434.5, 3));
      pl.Add(new Peak(492.9613, 26216.6, 3));

      pl.Add(new Peak(531.2642, 129351.8, 4));

      pl.Add(new Peak(631.2642, 129351.8, 0));
    }
    public void TestProcess()
    {
      var peaks = new PeakList<Peak>();
      peaks.PrecursorMZ = 1000;
      peaks.PrecursorCharge = 1;

      var processor = new PeakListMassRangeProcessor<Peak>(800, 1200, new[] {2, 3});
      Assert.AreSame(peaks, processor.Process(peaks));

      peaks.PrecursorCharge = 0;
      Assert.AreSame(null, processor.Process(peaks));

      peaks.PrecursorMZ = 500;
      Assert.AreSame(peaks, processor.Process(peaks));

      peaks.PrecursorMZ = 300;
      Assert.AreSame(peaks, processor.Process(peaks));

      var processor2 = new PeakListMassRangeProcessor<Peak>(800, 1200, new int[] {});
      Assert.AreSame(peaks, processor2.Process(peaks));
    }
예제 #40
0
    public void TestMatch()
    {
      PeakIonSeriesMatcher matcher = new PeakIonSeriesMatcher(IonType.B, 0.5);

      var factory = new MockRepository(MockBehavior.Strict);

      var dic = new Dictionary<IonType, List<MatchedPeak>>();
      dic[IonType.B] = new List<MatchedPeak>();
      dic[IonType.B].Add(new MatchedPeak(100, 0.0, 1) { PeakType = IonType.B, PeakIndex = 1 });
      dic[IonType.B].Add(new MatchedPeak(200, 0.0, 1) { PeakType = IonType.B, PeakIndex = 2 });

      PeakList<MatchedPeak> expPeaks = new PeakList<MatchedPeak>()
      {
        new MatchedPeak(100.03, 1,1),
        new MatchedPeak(200.02, 1,1),
        new MatchedPeak(300, 1,1)
      };
      expPeaks.PrecursorCharge = 1;

      var sr = factory.Create<IIdentifiedPeptideResult>();
      sr.Setup(x => x.Peptide).Returns("K.S*R.F");
      sr.Setup(x => x.GetIonSeries()).Returns(dic);
      sr.Setup(x => x.ExperimentalPeakList).Returns(expPeaks);

      matcher.Match(sr.Object);

      Assert.AreEqual(null, expPeaks[0].DisplayName);
      Assert.AreEqual(IonType.B, expPeaks[0].PeakType);
      Assert.AreEqual(1, expPeaks[0].PeakIndex);

      Assert.AreEqual(null, expPeaks[1].DisplayName);
      Assert.AreEqual(IonType.B, expPeaks[1].PeakType);
      Assert.AreEqual(2, expPeaks[1].PeakIndex);

      Assert.AreEqual(null, expPeaks[2].DisplayName);
      Assert.AreEqual(IonType.UNKNOWN, expPeaks[2].PeakType);
      Assert.AreEqual(0, expPeaks[2].PeakIndex);
    }
예제 #41
0
    public void TestMatch()
    {
      var factory = new MockRepository(MockBehavior.Strict);

      PeakList<MatchedPeak> expPeaks = new PeakList<MatchedPeak>()
      {
        new MatchedPeak(165.00, 1,1),
        new MatchedPeak(182.40, 1,1),
        new MatchedPeak(982.5, 1,1)
      };
      expPeaks.PrecursorCharge = 1;

      var sr = factory.Create<IIdentifiedPeptideResult>();
      sr.Setup(x => x.GetIonSeries()).Returns(dic);
      sr.Setup(x => x.Peptide).Returns("K.S*R.F");
      sr.Setup(x => x.ExperimentalPeakList).Returns(expPeaks);

      matcher.Match(sr.Object);

      PeakList<MatchedPeak> annotatedPeaks = sr.Object.ExperimentalPeakList;
      AssertPeak(annotatedPeaks[0], "[b2-H2O-NH3]", 165);
      AssertPeak(annotatedPeaks[1], "[b2-H2O]", 182.40);
      AssertPeak(annotatedPeaks[2], "[y1-NH3]", 982.5);
    }
예제 #42
0
    public void TestGetPeakListInfo()
    {
      var pkl = new PeakList<Peak>();

      this.fullRawFile.GetPeakListInfo(2968, pkl);
      Assert.AreEqual(726.3757, pkl.PrecursorMZ, 0.0001);
      Assert.AreEqual(1, pkl.PrecursorCharge);

      this.fullRawFile.GetPeakListInfo(4310, pkl);
      Assert.AreEqual(555.8007, pkl.PrecursorMZ, 0.0001);
      Assert.AreEqual(2, pkl.PrecursorCharge);

      this.fullRawFile.GetPeakListInfo(4372, pkl);
      Assert.AreEqual(671.84, pkl.PrecursorMZ, 0.01);
      Assert.AreEqual(0, pkl.PrecursorCharge);
    }
    public void TestMatch()
    {
      var factory = new MockRepository(MockBehavior.Strict);

      PeakList<MatchedPeak> expPeaks = new PeakList<MatchedPeak>()
      {
        new MatchedPeak(102.0, 1,1),
        new MatchedPeak(220, 1,1),
        new MatchedPeak(1003, 1,1)
      };
      expPeaks.PrecursorCharge = 1;
      expPeaks.PrecursorMZ = 1000.0;

      var dic = new Dictionary<IonType, List<MatchedPeak>>();
      dic[IonType.B] = new List<MatchedPeak>();
      dic[IonType.B].Add(new MatchedPeak(200, 0.0, 1) { PeakIndex = 1, PeakType = IonType.B });
      dic[IonType.B].Add(new MatchedPeak(300, 0.0, 1) { PeakIndex = 2, PeakType = IonType.B });
      dic[IonType.Y] = new List<MatchedPeak>();
      dic[IonType.Y].Add(new MatchedPeak(1000, 0.0, 1) { PeakIndex = 1, PeakType = IonType.Y });
      dic[IonType.Y].Add(new MatchedPeak(1100, 0.0, 1) { PeakIndex = 2, PeakType = IonType.Y });

      var sr = factory.Create<IIdentifiedPeptideResult>();
      sr.Setup(x => x.GetIonSeries()).Returns(dic);
      sr.Setup(x => x.Peptide).Returns("K.S*Y*R.F");
      sr.Setup(x => x.ExperimentalPeakList).Returns(expPeaks);

      matcher.Match(sr.Object);

      //expPeaks.ForEach(p => Console.WriteLine(p.DisplayName + "---" + p.Mz));

      PeakList<MatchedPeak> annotatedPeaks = sr.Object.ExperimentalPeakList;
      AssertPeak(annotatedPeaks[0], "[b1-H3PO4]", 102);
      AssertPeak(annotatedPeaks[1], "[b2-HPO3]", 220);
      AssertPeak(annotatedPeaks[2], "[y2-HPO3-NH3]", 1003);
    }
예제 #44
0
    public void TestMergeWith()
    {
      PeakList<Peak> pl1 = new PeakList<Peak>();
      pl1.Add(new Peak(420, 10, 1));
      pl1.Add(new Peak(445, 10, 1));

      PeakList<Peak> pl2 = new PeakList<Peak>();
      pl2.Add(new Peak(420.004, 30, 2));
      pl2.Add(new Peak(445.004, 30, 1));

      pl1.MergeByMZFirst(pl2, 50);

      Assert.AreEqual(3, pl1.Count);
      Assert.AreEqual(420, pl1[0].Mz, 0.001);
      Assert.AreEqual(1, pl1[0].Charge);
      Assert.AreEqual(420.004, pl1[1].Mz, 0.001);
      Assert.AreEqual(2, pl1[1].Charge);
      Assert.AreEqual(445.003, pl1[2].Mz, 0.001);
      Assert.AreEqual(1, pl1[2].Charge);

      Assert.AreEqual(10, pl1[0].Intensity);
      Assert.AreEqual(30, pl1[1].Intensity);
      Assert.AreEqual(40, pl1[2].Intensity);
    }