示例#1
0
        public override IsobaricResult ReadFromFile(string fileName)
        {
            IsobaricResult result = new IsobaricResult()
            {
                Mode = ITraqResultXmlFormatReader.GetMode(fileName)
            };

            var reader = new ITraqResultXmlFormatReader()
            {
                Progress  = this.Progress,
                Accept    = this.Accept,
                ReadPeaks = this.ReadPeaks
            };

            reader.OpenFile(fileName);
            try
            {
                IsobaricItem item;
                while (null != (item = reader.Next()))
                {
                    result.Add(item);
                }
            }
            finally
            {
                reader.Close();
            }

            return(result);
        }
示例#2
0
        public void Normalize(IsobaricResult result)
        {
            if (result.Count == 0)
            {
                return;
            }

            if (ByIonInjectionTime && result.HasIonInjectionTime())
            {
                result.ForEach(m => m.MultiplyIntensityByInjectionTime());
            }

            var defs = result.First().Definition.Items;

            var sums = (from def in defs
                        select GetIonBase(result, m => m[def.Index])).ToArray();

            for (int i = 1; i < sums.Length; i++)
            {
                sums[i] = sums[0] / sums[i];
            }

            result.ForEach(m =>
            {
                for (int i = 1; i < defs.Length; i++)
                {
                    m[defs[i].Index] *= sums[i];
                }
            });

            if (ByIonInjectionTime && result.HasIonInjectionTime())
            {
                result.ForEach(m => m.DevideIntensityByInjectionTime());
            }
        }
示例#3
0
        public override IEnumerable <string> Process(string rawFileName)
        {
            IsobaricResult result = GetTraqResult(rawFileName);

            string resultFileName = GetITraqFileName(rawFileName);

            ITraqResultFileFormatFactory.GetXmlFormat().WriteToFile(resultFileName, result);

            return(new[] { resultFileName });
        }
示例#4
0
        protected List <IIdentifiedSpectrum> GetSpectra(string fileName)
        {
            Progress.SetMessage("Reading peptides ...");
            List <IIdentifiedSpectrum> spectra = format.ReadFromFile(fileName);

            Progress.SetMessage("Reading itraq ...");
            IsobaricResult itraq = ITraqResultFileFormatFactory.GetXmlFormat().ReadFromFile(rawFileName);

            Progress.SetMessage("Matching peptide and itraq ...");

            ITraqItemUtils.MatchPeptideWithItraq(itraq, spectra);

            return(spectra);
        }
        protected override double GetIonBase(IsobaricResult tr, Func <IsobaricItem, double> func)
        {
            var ions = (from item in tr
                        let intensity = func(item)
                                        where intensity != ITraqConsts.NULL_INTENSITY
                                        select intensity).ToList();

            if (ions.Count == 0)
            {
                return(ITraqConsts.NULL_INTENSITY);
            }

            return(ions.Sum());
        }
示例#6
0
        public override IsobaricResult ReadFromFile(string fileName)
        {
            XElement       root   = XElement.Load(fileName);
            IsobaricResult result = new IsobaricResult();

            foreach (var ele in root.Elements("ITraqScan"))
            {
                var item = new IsobaricItem();

                item.PlexType     = EnumUtils.StringToEnum(ele.Element("PlexType").Value, IsobaricType.PLEX4);
                item.Experimental = ele.Element("Experimental").Value;
                item.ScanMode     = ele.Element("ScanMode").Value;

                item.Scan = new ScanTime(Convert.ToInt32(ele.Element("Scan").Value),
                                         MyConvert.ToDouble(ele.Element("RetentionTime").Value));
                item.Scan.IonInjectionTime = MyConvert.ToDouble(ele.Element("IonInjectionTime").Value);

                var ppEle = ele.Element("PrecursorPercentage");
                if (null != ppEle)
                {
                    item.PrecursorPercentage = MyConvert.ToDouble(ppEle.Value);
                }

                if (!Accept(item))
                {
                    continue;
                }

                var ions = ele.Element("Ions");

                var defs = item.Definition.Items;
                foreach (var def in defs)
                {
                    item[def.Index] = MyConvert.ToDouble(ions.Element(def.Name).Value);
                }

                if (ReadPeaks)
                {
                    item.RawPeaks = ElementToPeakList(ele, "RawPeaks", false);
                    item.PeakInIsolationWindow = ElementToPeakList(ele, "PeakInIsolationWindow", true);
                }

                result.Add(item);
            }

            return(result);
        }
        public static void MatchPeptideWithItraq(IsobaricResult itraq, List <IIdentifiedSpectrum> spectra)
        {
            var itraqMap = itraq.ToDictionary(m => m.Experimental + "##" + m.Scan.Scan.ToString());

            spectra.ForEach(m =>
            {
                var key = m.Query.FileScan.Experimental + "##" + m.Query.FileScan.FirstScan.ToString();
                if (itraqMap.ContainsKey(key))
                {
                    m.SetIsobaricItem(itraqMap[key]);
                }
                else
                {
                    m.SetIsobaricItem(null);
                }
            });
        }
示例#8
0
        public override void WriteToFile(string fileName, IsobaricResult t)
        {
            using (XmlTextWriter w = XmlUtils.CreateWriter(fileName, Encoding.ASCII))
            {
                StartWriteDocument(w, t.Mode);

                foreach (var item in t)
                {
                    WriteIsobaricItem(w, item);
                }

                EndWriteDocument(w);
            }

            var indexBuilder = new ITraqResultXmlIndexBuilder(true)
            {
                Progress = this.Progress
            };

            indexBuilder.Process(fileName);
        }
示例#9
0
        public override void WriteToFile(string fileName, IsobaricResult t)
        {
            var xle = new XElement("ITraqResult",
                                   from item in t
                                   let ions = new XElement("Ions", from def in item.Definition.Items
                                                           select new XElement(def.Name, MyConvert.Format("{0:0.0}", item[def.Index])))
                                              select new XElement("ITraqScan",
                                                                  new XElement("PlexType", item.PlexType),
                                                                  new XElement("Experimental", item.Experimental),
                                                                  new XElement("ScanMode", item.ScanMode),
                                                                  new XElement("Scan", item.Scan.Scan),
                                                                  new XElement("IonInjectionTime", MyConvert.Format("{0:0.000}", item.Scan.IonInjectionTime)),
                                                                  new XElement("PrecursorPercentage", MyConvert.Format("{0:0.000}", item.PrecursorPercentage)),
                                                                  new XElement("RetentionTime", MyConvert.Format("{0:0.0}", item.Scan.RetentionTime)),
                                                                  ions,
                                                                  PeakListToElement(item.RawPeaks, "RawPeaks", false),
                                                                  PeakListToElement(item.PeakInIsolationWindow, "PeakInIsolationWindow", true)
                                                                  ));

            xle.Save(fileName);
        }
示例#10
0
        public virtual IsobaricResult GetITraqResult(List <IsobaricItem> pkls, List <MeanStandardDeviation> accs, double peakFolderTolerance, int minPeakCount)
        {
            IsobaricResult result = new IsobaricResult();

            double[]      ions           = GetIons();
            List <double> means          = new List <double>();
            List <double> peakTolerances = new List <double>();

            for (int i = 0; i < ions.Length; i++)
            {
                var ion = ions[i];
                means.Add(ion + accs[i].Mean);
                peakTolerances.Add(accs[i].StdDev * peakFolderTolerance);
            }

            List <Peak> peaks = new List <Peak>();

            foreach (var pkl in pkls)
            {
                peaks.Clear();
                int nullCount = 0;
                for (int i = 0; i < means.Count; i++)
                {
                    Peak peak = pkl.RawPeaks.FindPeak(means[i], peakTolerances[i]).FindMaxIntensityPeak();
                    CheckPeakNull(ref peak, ref nullCount);
                    peaks.Add(peak);
                }

                if (nullCount > ions.Length - minPeakCount)
                {
                    continue;
                }

                AssignItraqItem(pkl, peaks);

                result.Add(pkl);
            }
            return(result);
        }
示例#11
0
        public IsobaricResult GetTraqResult(string rawFileName)
        {
            Progress.SetMessage("Processing " + rawFileName + " ...");

            string experimental = FileUtils.ChangeExtension(new FileInfo(rawFileName).Name, "");

            string originalFileName = GetOriginalITraqFileName(rawFileName);

            string paramFileName = originalFileName + ".param";

            IsobaricResult result = null;

            ITraqFileBuilder builder = new ITraqFileBuilder(itraqReader.PlexType.GetDefinition());

            if (!CheckOriginalFile(originalFileName) || !File.Exists(paramFileName))
            {
                itraqReader.Progress = this.Progress;

                Progress.SetMessage("Reading isobaric tag channels from " + new FileInfo(rawFileName).Name + "...");
                List <IsobaricItem> pkls = itraqReader.ReadFromFile(rawFileName);
                Progress.SetMessage("Reading isobaric tag channels finished.");

                if (pkls.Count == 0)
                {
                    throw new Exception(MyConvert.Format("No isobaric tag information readed from file {0}, contact with author.", rawFileName));
                }

                var accs = builder.GetDistances(from pkl in pkls select pkl.RawPeaks);

                if (accs.Count == 0)
                {
                    throw new Exception(MyConvert.Format("No isobaric tag information readed from file {0}, contact with author.", rawFileName));
                }

                result      = builder.GetITraqResult(pkls, accs, SigmaFoldTolerance, 1);
                result.Mode = itraqReader.ToString();

                result.ForEach(m => m.Experimental = experimental);

                ITraqResultFileFormatFactory.GetXmlFormat().WriteToFile(originalFileName, result);

                using (StreamWriter sw = new StreamWriter(paramFileName))
                {
                    sw.WriteLine("Ion\tDetectedIon\tDeltaMass\tDeltaPPM\tDetectedSigma");
                    var ions = builder.Definition.Items;
                    for (int i = 0; i < ions.Length; i++)
                    {
                        sw.WriteLine("{0:0.00000}\t{1:0.00000}\t{2:0.00000}\t{3:0.00}\t{4:0.00000}", ions[i].Mass, ions[i].Mass + accs[i].Mean, accs[i].Mean, PrecursorUtils.mz2ppm(ions[i].Mass, accs[i].Mean), accs[i].StdDev);
                    }
                }
            }
            else
            {
                Progress.SetMessage("Read xml information from " + originalFileName + " ...");

                var format = ITraqResultFileFormatFactory.GetXmlFormat();
                format.Progress = this.Progress;

                result = format.ReadFromFile(originalFileName);
            }

            result.RemoveAll(m => m.PeakCount() < minPeakCount);

            result.ForEach(m => calc.Correct(m));

            result.RemoveAll(m => m.PeakCount() < minPeakCount);

            result.ForEach(m => m.PrecursorPercentage = m.PeakInIsolationWindow.GetPrecursorPercentage(this.precursorPPM));

            if (NormalizationBuilder != null)
            {
                NormalizationBuilder.Normalize(result);
            }
            return(result);
        }
示例#12
0
 protected abstract double GetIonBase(IsobaricResult tr, Func <IsobaricItem, double> func);
 public void Normalize(IsobaricResult result)
 {
 }
示例#14
0
 public abstract void WriteToFile(string fileName, IsobaricResult t);
示例#15
0
        public void Setup()
        {
            t1 = new IsobaricItem()
            {
                Experimental        = "S1",
                ScanMode            = "HCD",
                PlexType            = IsobaricType.PLEX4,
                PrecursorPercentage = 0.85,
                Scan     = new ScanTime(255, 3.4),
                RawPeaks = new PeakList <Peak>(new Peak[] { new Peak(114.1, 114.1), new Peak(115.1, 115.1), new Peak(116.1, 116.1), new Peak(117.1, 117.1) }.ToList()),
                PeakInIsolationWindow = new PeakList <Peak>(new Peak[] { new Peak(214.1, 114.1), new Peak(215.1, 115.1), new Peak(216.1, 116.1), new Peak(217.1, 117.1) }.ToList())
                {
                    Precursor = new PrecursorPeak()
                    {
                        MasterScan       = 1,
                        Charge           = 2,
                        Intensity        = 3.0,
                        IsolationMass    = 1800.1,
                        IsolationWidth   = 2.0,
                        MonoIsotopicMass = 1879.1
                    }
                }
            };

            t1[114] = 4.5;
            t1[115] = 5.5;
            t1[116] = 6.5;
            t1[117] = 7.5;

            t2 = new IsobaricItem()
            {
                Experimental        = "S2",
                ScanMode            = "ETD",
                PlexType            = IsobaricType.PLEX8,
                PrecursorPercentage = 0.33,
                Scan     = new ScanTime(355, 4.4),
                RawPeaks = new PeakList <Peak>(new Peak[] { new Peak(114.1, 1114.1), new Peak(115.1, 1115.1), new Peak(116.1, 1116.1), new Peak(117.1, 1117.1) }.ToList()),
                PeakInIsolationWindow = new PeakList <Peak>(new Peak[] { new Peak(1214.1, 114.1), new Peak(1215.1, 115.1), new Peak(1216.1, 116.1), new Peak(1217.1, 117.1) }.ToList())
                {
                    Precursor = new PrecursorPeak()
                    {
                        MasterScan       = 3,
                        Charge           = 3,
                        Intensity        = 4.0,
                        IsolationMass    = 2800.1,
                        IsolationWidth   = 3.0,
                        MonoIsotopicMass = 2879.1
                    }
                }
            };

            t2[113] = 3.5;
            t2[114] = 4.5;
            t2[115] = 5.5;
            t2[116] = 6.5;
            t2[117] = 7.5;
            t2[118] = 8.5;
            t2[119] = 9.5;
            t2[121] = 11.5;

            tr      = new IsobaricResult();
            tr.Mode = "PQD";
            tr.Add(t1);
            tr.Add(t2);
        }