public override IEnumerable <string> Process(string fileName) { var summary = new O18QuantificationSummaryItem { RawFilename = _rawFilename, SoftwareVersion = SoftwareVersion, PeptideSequence = _peptide, AdditionalFormula = _additionalFormula, PeptideAtomComposition = _atomComposition.GetFormula(), PurityOfO18Water = _purityOfO18Water, PeptideProfile = _profile, ObservedEnvelopes = _envelopes, IsPostDigestionLabelling = _isPostDigestionLabelling, TheoreticalO16Mz = TheoreticalMz, Charge = Charge, ScanStartPercentage = _scanPercentageStart, ScanEndPercentage = _scanPercentageEnd }; summary.InitializeScanRange(); summary.CalculateSpeciesAbundanceByLinearRegression(); _fileFormat.WriteToFile(fileName, summary); return(new[] { fileName }); }
public void SetSummaryFilename(string o18SummaryFilename, IAnnotation parentObj) { if (this.o18SummaryFilename.Equals(o18SummaryFilename)) { return; } this.parentObj = parentObj; if (this.summary != null) { ClearAllData(); } this.fileFormat = new O18QuantificationSummaryItemXmlFormat(); this.summary = this.fileFormat.ReadFromFile(o18SummaryFilename); this.o18SummaryFilename = o18SummaryFilename; Text = o18SummaryFilename; this.calc = this.summary.GetCalculator(); this.options = new O18QuantificationSummaryViewerOptions(o18SummaryFilename); ShowSummary(false); this.btnSave.Enabled = false; }
public void WriteToStream(System.IO.StreamWriter sw, IIdentifiedSpectrum peptide) { string detailFile = this.detailDirectory + "\\" + peptide.Annotations[O18QuantificationConstants.O18_RATIO_FILE]; if (File.Exists(detailFile)) { O18QuantificationSummaryItem item = format.ReadFromFile(detailFile); var calc = item.GetCalculator(); foreach (var scan in item.ObservedEnvelopes) { if (scan.Enabled) { scan.CalculateFromProfile(item.PeptideProfile, calc); sw.Write("\t"); foreach (var func in valueFuncs) { sw.Write("\t{0}", func(scan)); } sw.WriteLine(); } } } }
public override IEnumerable <string> Process(string optionFile) { this.options = O18QuantificationFileProcessorOptions.Load(optionFile); var calc = options.GetProteinRatioCalculator(); var detailDirectory = options.GetDetailDirectory(); if (!Directory.Exists(detailDirectory)) { Directory.CreateDirectory(detailDirectory); } var format = new MascotResultTextFormat(); IIdentifiedResult mr = format.ReadFromFile(options.ProteinFile); CheckRawFilename(mr, optionFile); Dictionary <string, List <IIdentifiedSpectrum> > filePepMap = GetFilePeptideMap(mr); Dictionary <IIdentifiedPeptide, O18QuantificationSummaryItem> pepResultMap = new Dictionary <IIdentifiedPeptide, O18QuantificationSummaryItem>(); foreach (string filename in filePepMap.Keys) { Progress.SetMessage("Processing " + filename); string rawFilename = filename; if (new FileInfo(filename).Name.Equals("Cmpd.raw")) { rawFilename = FindRawFileName(options.ProteinFile); } string experimental = FileUtils.ChangeExtension(new FileInfo(rawFilename).Name, ""); using (CacheRawFile rawFile = new CacheRawFile(rawFilename)) { int firstScanNumber = rawFile.GetFirstSpectrumNumber(); int lastScanNumber = rawFile.GetLastSpectrumNumber(); List <IIdentifiedSpectrum> peps = filePepMap[filename]; Dictionary <string, DifferentRetentionTimeEnvelopes> peptideChargeMap = new Dictionary <string, DifferentRetentionTimeEnvelopes>(); Dictionary <O18QuanEnvelopes, List <IIdentifiedSpectrum> > pklMpMap = new Dictionary <O18QuanEnvelopes, List <IIdentifiedSpectrum> >(); Progress.SetRange(0, peps.Count); foreach (IIdentifiedSpectrum mphit in peps) { if (Progress.IsCancellationPending()) { throw new UserTerminatedException(); } Progress.Increment(1); IIdentifiedPeptide mp = mphit.Peptide; if (mp.Sequence.EndsWith("-")) { //it cannot be O18 labelled, just skip it continue; } int startScan = mphit.Query.FileScan.FirstScan; double theoreticalMz = GetTheoretialO16Mz(gapO18O16, mphit); int theoreticalMass = (int)(theoreticalMz * mphit.Query.Charge + 0.5); string sequenceCharge = PeptideUtils.GetPureSequence(mphit.Sequence) + "." + mphit.Query.Charge + "." + theoreticalMass; if (!peptideChargeMap.ContainsKey(sequenceCharge)) { peptideChargeMap.Add(sequenceCharge, new DifferentRetentionTimeEnvelopes()); } bool bFound = false; DifferentRetentionTimeEnvelopes pkls = peptideChargeMap[sequenceCharge]; foreach (var pklList in pkls) { if (pklList.Count == 0) { continue; } if (pklList[0].Scan > startScan) { continue; } if (pklList[pklList.Count - 1].Scan < startScan) { continue; } pklMpMap[pklList].Add(mphit); bFound = true; bool findIdentified = false; for (int i = 1; i < pklList.Count; i++) { if (pklList[i].ScanTimes[0].Scan > startScan) { pklList[i - 1].IsIdentified = true; findIdentified = true; break; } } if (!findIdentified) { pklList[pklList.Count - 1].IsIdentified = true; } } if (bFound) { continue; } double mzTolerance = PrecursorUtils.ppm2mz(theoreticalMz, options.PPMTolerance); O18QuanEnvelopes envelopes = new O18QuanEnvelopes(); bool bFirst = true; int count = 0; //backward for (int scan = startScan; scan >= firstScanNumber; scan--) { if (1 == rawFile.GetMsLevel(scan)) { O18QuanEnvelope envelope = GetCorrespondingEnvelope(rawFile, theoreticalMz, mphit.Query.Charge, mzTolerance, scan); //At most one invalid scan inside both pre or post identification scan range. if (!IsValidEnvelope(envelope, mphit.Charge)) { if (count > 0) { envelopes.RemoveAt(0); break; } else { count++; } } else { count = 0; } if (bFirst) { envelope.IsIdentified = true; bFirst = false; } envelopes.Insert(0, envelope); } } if (envelopes.Count == 0) { //If the identified scan has no quantification information ,ignore it. continue; } count = 0; //forward for (int scan = startScan + 1; scan <= lastScanNumber; scan++) { if (1 == rawFile.GetMsLevel(scan)) { var envelope = GetCorrespondingEnvelope(rawFile, theoreticalMz, mphit.Query.Charge, mzTolerance, scan); //At most one invalid scan inside both pre or post identification scan range. if (!IsValidEnvelope(envelope, mphit.Charge)) { if (count > 0) { envelopes.RemoveAt(envelopes.Count - 1); break; } else { count = 1; } } else { count = 0; } envelopes.Add(envelope); } } if (envelopes.Count == 0) { continue; } string scanCurr = envelopes.GetScanRange(); //check scan list again bFound = false; foreach (var pklList in pkls) { if (pklList.Count == 0) { continue; } string scanOld = pklList.GetScanRange(); if (scanOld.Equals(scanCurr)) { pklMpMap[pklList].Add(mphit); bFound = true; break; } } if (bFound) { continue; } pkls.Add(envelopes); pklMpMap.Add(envelopes, new List <IIdentifiedSpectrum>()); pklMpMap[envelopes].Add(mphit); } var detailFilePrefix = options.GetDetailDirectory() + "\\" + new FileInfo(options.ProteinFile).Name; foreach (string sequenceCharge in peptideChargeMap.Keys) { DifferentRetentionTimeEnvelopes pkls = peptideChargeMap[sequenceCharge]; foreach (var envelopes in pkls) { if (0 == envelopes.Count) { continue; } List <IIdentifiedSpectrum> mps = pklMpMap[envelopes]; double mzTolerance = PrecursorUtils.ppm2mz(mps[0].Query.ObservedMz, options.PPMTolerance); O18QuantificationPeptideProcessor processor = new O18QuantificationPeptideProcessor(fileFormat, options.IsPostDigestionLabelling, rawFilename, PeptideUtils.GetPureSequence(mps[0].Sequence), options.PurityOfO18Water, envelopes, mzTolerance, "", options.GetScanPercentageStart() / 100, options.GetScanPercentageEnd() / 100); processor.TheoreticalMz = GetTheoretialO16Mz(gapO18O16, mps[0]); processor.Charge = mps[0].Charge; processor.SoftwareVersion = options.SoftwareVersion; var resultFilename = MyConvert.Format("{0}.{1}.{2}.{3}.{4}.O18", detailFilePrefix, experimental, PeptideUtils.GetPureSequence(mps[0].Sequence), mps[0].Charge, envelopes.GetScanRange()); processor.Process(resultFilename); O18QuantificationSummaryItem item = fileFormat.ReadFromFile(resultFilename); int maxScoreItemIndex = FindMaxScoreItemIndex(mps); var relativeFile = Path.Combine(Path.GetFileName(options.GetDetailDirectory()), Path.GetFileName(resultFilename)); for (int i = 0; i < mps.Count; i++) { if (maxScoreItemIndex == i) { item.AssignToAnnotation(mps[i], relativeFile); } else { item.AssignDuplicationToAnnotation(mps[i], relativeFile); } } } } } } List <IIdentifiedSpectrum> peptides = mr.GetSpectra(); foreach (IIdentifiedSpectrum mphit in peptides) { if (!mphit.Annotations.ContainsKey(O18QuantificationConstants.O18_RATIO_SCANCOUNT)) { mphit.Annotations[O18QuantificationConstants.O18_RATIO_SCANCOUNT] = "-"; } mphit.SetEnabled(calc.HasPeptideRatio(mphit)); } calc.Calculate(mr, m => true); string resultFile = FileUtils.ChangeExtension(optionFile, ".O18summary"); format.InitializeByResult(mr); format.ProteinFormat = format.ProteinFormat.GetLineFormat(O18QuantificationConstants.O18_EXPORT_PROTEIN_HEADER); format.WriteToFile(resultFile, mr); Progress.SetMessage("Finished, result was saved to " + resultFile); return(new[] { resultFile }); }
public void TestWriteToFile() { var item = new O18QuantificationSummaryItem(); item.RawFilename = @"D:\sqh\Science\Project/4NLFOR.raw"; item.PeptideSequence = "AFATDITDAEEDK"; item.PeptideAtomComposition = "C60H92N14O26"; item.PurityOfO18Water = 0.95; item.PeptideProfile = IsotopicBuilderFactory.GetBuilder().GetProfile(new AtomComposition(item.PeptideAtomComposition), 1, 10); item.ObservedEnvelopes = new List <O18QuanEnvelope> (); var pkl1 = new O18QuanEnvelope(); pkl1.ScanTimes.Add(new ScanTime(6741, 12.34)); pkl1.Enabled = true; pkl1.IsIdentified = true; pkl1.Add(new Peak(713.3209, 424345.9)); pkl1.Add(new Peak(713.8254, 198378.3)); pkl1.Add(new Peak(714.3221, 246866.8)); pkl1.Add(new Peak(714.8242, 221648.0)); pkl1.Add(new Peak(715.3243, 107701.3)); pkl1.Add(new Peak(715.8316, 0.0)); item.ObservedEnvelopes.Add(pkl1); var pkl2 = new O18QuanEnvelope(); pkl2.ScanTimes.Add(new ScanTime(6746, 13.34)); pkl2.Enabled = false; pkl2.Add(new Peak(713.3209, 796597.7)); pkl2.Add(new Peak(713.8254, 530778.4)); pkl2.Add(new Peak(714.3221, 456099.6)); pkl2.Add(new Peak(714.8242, 339509.8)); pkl2.Add(new Peak(715.3243, 182812.3)); pkl2.Add(new Peak(715.8316, 0.0)); item.ObservedEnvelopes.Add(pkl2); item.SpeciesAbundance = new SpeciesAbundanceInfo(); item.SpeciesAbundance.O16 = 79184307.0; item.SpeciesAbundance.O181 = 39464386.0; item.SpeciesAbundance.O182 = 440969.4; item.SampleAbundance = new SampleAbundanceInfo(); item.SampleAbundance.LabellingEfficiency = 0.0219; item.SampleAbundance.Ratio = 50; item.SampleAbundance.O16 = 0; item.SampleAbundance.O18 = 922867772.7; item.SpeciesAbundance.RegressionCorrelation = 0.9999; item.SpeciesAbundance.RegressionItems.Clear(); item.SpeciesAbundance.RegressionItems.Add(new SpeciesRegressionItem(713.3209, 36513020.6, 36512100.5)); item.SpeciesAbundance.RegressionItems.Add(new SpeciesRegressionItem(713.8254, 26438219.2, 26447909.0)); item.SpeciesAbundance.RegressionItems.Add(new SpeciesRegressionItem(714.3221, 29639265.4, 29595148.6)); item.SpeciesAbundance.RegressionItems.Add(new SpeciesRegressionItem(714.8242, 16687280.4, 16812006.0)); item.SpeciesAbundance.RegressionItems.Add(new SpeciesRegressionItem(715.3243, 7087781.0, 6823450.3)); item.SpeciesAbundance.RegressionItems.Add(new SpeciesRegressionItem(715.8316, 1799203.9, 2164120.0)); new O18QuantificationSummaryItemXmlFormat().WriteToFile(@TestContext.CurrentContext.TestDirectory + "/../../../data//O18QuantificationInformation.xml.tmp", item); AssertUtils.AssertFileEqual(@TestContext.CurrentContext.TestDirectory + "/../../../data//O18QuantificationInformation.xml.tmp", @TestContext.CurrentContext.TestDirectory + "/../../../data//O18QuantificationInformation.xml"); new FileInfo(@TestContext.CurrentContext.TestDirectory + "/../../../data//O18QuantificationInformation.xml.tmp").Delete(); }