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); }
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); }