Beispiel #1
0
        public ChromatographProfile ReadFromFile(string fileName)
        {
            var result = new ChromatographProfile();
            var root   = XElement.Load(fileName);

            result.Experimental   = root.GetAttributeValue("Experimental", string.Empty);
            result.Sequence       = root.GetAttributeValue("Sequence", string.Empty);
            result.Charge         = root.GetAttributeValue("Charge", 0);
            result.IdentifiedScan = root.GetAttributeValue("IdentifiedScan", 0);
            result.ObservedMz     = root.GetAttributeValue("ObservedMz", 0.0);
            result.TheoreticalMz  = root.GetAttributeValue("TheoreticalMz", 0.0);

            List <IsotopicIon> ions = new List <IsotopicIon>();

            foreach (var ionEle in root.Element("IsotopicIons").Elements("Ion"))
            {
                var ion = new IsotopicIon();
                ion.Mz        = ionEle.GetAttributeValue("Mz", 0.0);
                ion.Intensity = ionEle.GetAttributeValue("Intensity", 0.0);
                ions.Add(ion);
            }
            result.IsotopicIons = ions.ToArray();

            foreach (var proEle in root.Element("ProfileScans").Elements("ProfileScan"))
            {
                var pscan = new ChromatographProfileScan();
                result.Profiles.Add(pscan);
                pscan.Identified    = proEle.GetAttributeValue("Identified", false);
                pscan.RetentionTime = proEle.GetAttributeValue("RetentionTime", 0.0);
                pscan.Scan          = proEle.GetAttributeValue("Scan", 0);
                foreach (var scanEle in proEle.Elements("Peak"))
                {
                    var peak = new ChromatographProfileScanPeak();
                    pscan.Add(peak);
                    peak.Isotopic    = scanEle.GetAttributeValue("Isotopic", 0);
                    peak.Mz          = scanEle.GetAttributeValue("Mz", 0.0);
                    peak.Intensity   = scanEle.GetAttributeValue("Intensity", 0.0);
                    peak.Noise       = scanEle.GetAttributeValue("Noise", 0.0);
                    peak.PPMDistance = scanEle.GetAttributeValue("PPMDistance", 0.0);
                }

                pscan.RawPeaks = new List <Peak>();
                var rawPeaksELe = proEle.Element("RawPeaks");
                foreach (var rawPeakEle in rawPeaksELe.Elements("RawPeak"))
                {
                    var peak = new Peak();
                    pscan.RawPeaks.Add(peak);
                    peak.Mz        = rawPeakEle.GetAttributeValue("Mz", 0.0);
                    peak.Intensity = rawPeakEle.GetAttributeValue("Intensity", 0.0);
                    peak.Noise     = rawPeakEle.GetAttributeValue("Noise", 0.0);
                }
            }

            return(result);
        }
        private ChromatographProfileScan FindEnvelope(PeakList <Peak> curPeaks, IsotopicIon[] isotopicIons, double mzTolerancePPM)
        {
            var result = new ChromatographProfileScan();

            result.Scan          = curPeaks.FirstScan;
            result.RetentionTime = curPeaks.ScanTimes[0].RetentionTime;
            int peakIndex = 0;

            foreach (var peak in isotopicIons)
            {
                Peak findPeak = null;
                while (peakIndex < curPeaks.Count)
                {
                    var curPeak = curPeaks[peakIndex];
                    if (curPeak.Mz < peak.MinimumMzWithinTolerance)
                    {
                        peakIndex++;
                        continue;
                    }

                    if (curPeak.Mz > peak.MaximumMzWithinTolerance)
                    {
                        break;
                    }

                    if (findPeak == null || findPeak.Intensity < curPeak.Intensity)
                    {
                        findPeak = curPeak;
                    }

                    peakIndex++;
                }

                if (findPeak == null)
                {
                    break;
                }
                else
                {
                    result.Add(new ChromatographProfileScanPeak()
                    {
                        Mz          = findPeak.Mz,
                        Intensity   = findPeak.Intensity,
                        Charge      = findPeak.Charge,
                        Noise       = findPeak.Noise,
                        PPMDistance = PrecursorUtils.mz2ppm(findPeak.Mz, findPeak.Mz - peak.Mz)
                    });
                }
            }

            return(result);
        }
        private bool AddEnvelope(ChromatographProfile chro, PeakList <Peak> curPeaks)
        {
            ChromatographProfileScan envelope = FindEnvelope(curPeaks, chro.IsotopicIons, options.MzTolerancePPM);

            if (envelope.Count < options.ProfileLength)
            {
                return(false);
            }

            if (envelope.CalculateProfileCorrelation(chro.IsotopicIons) < options.MinimumCorrelation)
            {
                return(false);
            }

            chro.Profiles.Add(envelope);
            return(true);
        }
        private bool AddEnvelope(ChromatographProfile chro, CacheRawFile rawReader, List <FullMS> fullMSList, int scanIndex)
        {
            PeakList <Peak> ms1 = ReadFullMS(rawReader, fullMSList, scanIndex);

            ChromatographProfileScan envelope = null;

            if (!profileFinder.Find(ms1, chro, options.MzTolerancePPM, options.MinimumProfileLength, ref envelope))
            {
                return(false);
            }

            if (options.MinimumProfileCorrelation > 0 && envelope.CalculateProfileCorrelation(chro.IsotopicIntensities) < options.MinimumProfileCorrelation)
            {
                return(false);
            }

            chro.Profiles.Add(envelope);
            return(true);
        }
Beispiel #5
0
        public ChromatographProfile ReadFromFile(string fileName)
        {
            var result = new ChromatographProfile();

            using (var sr = new StreamReader(fileName))
            {
                var line = sr.ReadLine();
                while ((line = sr.ReadLine()) != null)
                {
                    var parts = line.Split('\t');
                    var scan  = int.Parse(parts[0]);
                    ChromatographProfileScan profilescan;
                    if (result.Profiles.Count > 0 && result.Profiles.Last().Scan == scan)
                    {
                        profilescan = result.Profiles.Last();
                    }
                    else
                    {
                        profilescan = new ChromatographProfileScan();
                        result.Profiles.Add(profilescan);
                        profilescan.Scan          = scan;
                        profilescan.RetentionTime = double.Parse(parts[1]);
                        profilescan.Identified    = bool.Parse(parts[9]);
                    }

                    var peak = new ChromatographProfileScanPeak();
                    profilescan.Add(peak);
                    peak.Isotopic    = int.Parse(parts[2]);
                    peak.Mz          = double.Parse(parts[3]);
                    peak.Intensity   = double.Parse(parts[4]);
                    peak.PPMDistance = double.Parse(parts[5]);
                    peak.Noise       = peak.Intensity / double.Parse(parts[6]);
                }
            }
            return(result);
        }
        public bool Find(PeakList <Peak> ms1, ChromatographProfile chro, double mzTolerancePPM, int minimumProfileLength, ref ChromatographProfileScan result)
        {
            var rawPeaks = ms1.GetRange(chro.IsotopicIons[0].MinimumMzWithinTolerance, chro.IsotopicIons[chro.IsotopicIons.Length - 1].MaximumMzWithinTolerance);

            if (rawPeaks.Count < minimumProfileLength)
            {
                return(false);
            }

            List <List <Peak> > envelope = new List <List <Peak> >();
            int peakIndex = 0;

            foreach (var peak in chro.IsotopicIons)
            {
                List <Peak> findPeaks = new List <Peak>();
                while (peakIndex < rawPeaks.Count)
                {
                    var curPeak = rawPeaks[peakIndex];
                    if (curPeak.Mz < peak.MinimumMzWithinTolerance)
                    {
                        peakIndex++;
                        continue;
                    }

                    if (curPeak.Mz > peak.MaximumMzWithinTolerance)
                    {
                        break;
                    }

                    findPeaks.Add(curPeak);
                    peakIndex++;
                }

                if (findPeaks.Count == 0)
                {
                    break;
                }
                else
                {
                    envelope.Add(findPeaks);
                }
            }

            if (envelope.Count < minimumProfileLength)
            {
                return(false);
            }

            result               = new ChromatographProfileScan();
            result.Scan          = ms1.FirstScan;
            result.RetentionTime = ms1.ScanTimes[0].RetentionTime;
            result.RawPeaks      = new List <Peak>();

            List <Peak> resolved = Resolve(chro, envelope);

            foreach (var findPeak in rawPeaks)
            {
                var isotopicIndex = resolved.IndexOf(findPeak);
                if (isotopicIndex == -1)
                {
                    result.RawPeaks.Add(findPeak);
                }
                else
                {
                    var ion = chro.IsotopicIons[isotopicIndex];
                    result.Add(new ChromatographProfileScanPeak()
                    {
                        Isotopic    = isotopicIndex + 1,
                        Mz          = findPeak.Mz,
                        Intensity   = findPeak.Intensity,
                        Noise       = findPeak.Noise,
                        PPMDistance = PrecursorUtils.mz2ppm(findPeak.Mz, findPeak.Mz - ion.Mz)
                    });
                }
            }

            return(true);
        }