public void CalculateSpeciesAbundanceByLinearRegression() { var mergedPeaks = MergeEnvelopes(); int maxLength = Math.Min(PeptideProfile.Count + 4, mergedPeaks.Count); double[][] a = GetProfileMatrix(maxLength); double[] x; this.SpeciesAbundance = CalculateSpeciesAbundance(maxLength, a, mergedPeaks, out x); double[] theoreticalIntensities = GetTheoreticalIntensities(maxLength, x); double[] observedIntensities = GetObservedIntensities(maxLength, mergedPeaks); double corr = StatisticsUtils.PearsonCorrelation(theoreticalIntensities, observedIntensities); this.SpeciesAbundance.RegressionCorrelation = corr; this.SpeciesAbundance.RegressionItems.Clear(); int pepCharge = GetCharge(); var gap = (Atom.O18.MonoMass - Atom.O.MonoMass) / pepCharge; var gapC = (Atom.C13.MonoMass - Atom.C.MonoMass) / pepCharge; double mzO16 = TheoreticalO16Mz; double mzO181 = TheoreticalO16Mz + gap; double mzO182 = mzO181 + gap; double[] mzs = { mzO16, mzO16 + gapC, mzO181, mzO181 + gapC, mzO182, mzO182 + gapC }; for (int i = 0; i < maxLength && i < mzs.Length; i++) { var ri = new SpeciesRegressionItem(); ri.Mz = mzs[i]; ri.ObservedIntensity = observedIntensities[i]; ri.RegressionIntensity = theoreticalIntensities[i]; this.SpeciesAbundance.RegressionItems.Add(ri); } var calc = this.GetCalculator(); this.SampleAbundance = calc.Calculate(this.SpeciesAbundance); }
public O18QuantificationSummaryItem ReadFromFile(string filename) { var result = new O18QuantificationSummaryItem(); var root = XElement.Load(filename); result.RawFilename = root.Element("RawFilename").Value; var ele = root.Element("SoftwareVersion"); if (ele != null) { result.SoftwareVersion = ele.Value; } result.PeptideSequence = root.Element("PeptideSequence").Value; result.AdditionalFormula = root.Element("AdditionalFormula").Value; result.PeptideAtomComposition = root.Element("PeptideAtomComposition").Value; result.PurityOfO18Water = MyConvert.ToDouble(root.Element("PurityOfO18Water").Value); result.IsPostDigestionLabelling = bool.Parse(root.Element("IsPostDigestionLabelling").Value); if (root.Element("TheoreticalO16Mz") != null) { result.TheoreticalO16Mz = MyConvert.ToDouble(root.Element("TheoreticalO16Mz").Value); result.Charge = Convert.ToInt32(root.Element("Charge").Value); } result.PeptideProfile = (from x in root.Element("PeptideProfile").Elements() let mzEle = x.Attribute("Mz") let mz = mzEle == null ? 0.0 : MyConvert.ToDouble(mzEle.Value) let intensity = MyConvert.ToDouble(x.Value) select new Peak(mz, intensity)).ToList(); if (result.PeptideProfile[0].Mz == 0.0) { var pkls = IsotopicBuilderFactory.GetBuilder().GetProfile(new AtomComposition(result.PeptideAtomComposition), result.Charge, 10); for (int i = 0; i < Math.Min(result.PeptideProfile.Count, pkls.Count); i++) { result.PeptideProfile[i].Mz = pkls[i].Mz; result.PeptideProfile[i].Intensity = pkls[i].Intensity; } } var observed = root.Element("ObservedEnvelopes"); result.ObservedEnvelopes = new List <O18QuanEnvelope>(); foreach (var pkl in observed.Elements()) { var peakList = new O18QuanEnvelope(); int scan = int.Parse(pkl.Attribute("Scan").Value); double retentiontime = MyConvert.ToDouble(pkl.Attribute("Retentiontime").Value); peakList.Enabled = bool.Parse(pkl.Attribute("Enabled").Value); peakList.IsIdentified = bool.Parse(pkl.Attribute("Identified").Value); peakList.ScanTimes.Add(new ScanTime(scan, retentiontime)); foreach (var peak in pkl.Elements()) { double mz = MyConvert.ToDouble(peak.Attribute("Mz").Value); double intensity = MyConvert.ToDouble(peak.Attribute("Intensity").Value); var p = new Peak(mz, intensity); peakList.Add(p); } result.ObservedEnvelopes.Add(peakList); } var species = root.Element("SpeciesAbundance"); result.SpeciesAbundance.O16 = MyConvert.ToDouble(species.Element("O16").Value); result.SpeciesAbundance.O181 = MyConvert.ToDouble(species.Element("O181").Value); result.SpeciesAbundance.O182 = MyConvert.ToDouble(species.Element("O182").Value); var regression = species.Element("Regression"); result.SpeciesAbundance.RegressionCorrelation = MyConvert.ToDouble(regression.Attribute("Correlation").Value); result.SpeciesAbundance.RegressionItems.Clear(); foreach (var item in regression.Elements()) { var ritem = new SpeciesRegressionItem(); ritem.Mz = MyConvert.ToDouble(item.Attribute("Mz").Value); ritem.ObservedIntensity = MyConvert.ToDouble(item.Attribute("Observed").Value); ritem.RegressionIntensity = MyConvert.ToDouble(item.Attribute("Regression").Value); result.SpeciesAbundance.RegressionItems.Add(ritem); } var samples = root.Element("SampleAbundance"); result.SampleAbundance.LabellingEfficiency = MyConvert.ToDouble(samples.Attribute("LabellingEfficiency").Value); result.SampleAbundance.Ratio = MyConvert.ToDouble(samples.Attribute("Ratio").Value); result.SampleAbundance.O16 = MyConvert.ToDouble(samples.Element("O16").Value); result.SampleAbundance.O18 = MyConvert.ToDouble(samples.Element("O18").Value); return(result); }