/// <summary> /// 读取fasta文件,进行数据处理。 /// </summary> /// <param name="fileName"></param> /// <returns></returns> public override IEnumerable <string> Process(string fastaFile) { HashSet <string> result = new HashSet <string>(); var ff = new FastaFormat(); using (StreamReader sr = new StreamReader(fastaFile)) { Progress.SetRange(0, sr.BaseStream.Length); var aas = new Aminoacids(); Predicate <string> aaFilter = m => { foreach (var aa in ignoreAminoacids) { if (m.Contains(aa)) { return(false); } } return(true); }; Predicate <string> lengthFilter = m => m.Length >= minLength; Predicate <string> massFilter = m => { var mass = aas.MonoPeptideMass(m); return(mass >= minMass && mass <= maxMass); }; Predicate <string> filter = m => aaFilter(m) && lengthFilter(m) && massFilter(m); List <Digest> digs = new List <Digest>(); foreach (var protease in proteases) { var dig = new Digest(); dig.DigestProtease = protease; dig.MaxMissedCleavages = maxMissCleavage; digs.Add(dig); } Sequence seq; Progress.SetMessage("Digesting sequences ..."); while ((seq = ff.ReadSequence(sr)) != null) { Progress.SetPosition(sr.GetCharpos()); if (Progress.IsCancellationPending()) { throw new UserTerminatedException(); } HashSet <string> curseqs = new HashSet <string>(); curseqs.Add(seq.SeqString); foreach (var dig in digs) { var last = curseqs; curseqs = new HashSet <string>(); foreach (var curseq in last) { var pro = new Sequence(curseq, curseq); dig.ProteinSequence = pro; dig.AddDigestFeatures(); var infos = pro.GetDigestPeptideInfo(); infos.ForEach(m => { if (filter(m.PeptideSeq)) { curseqs.Add(m.PeptideSeq); } }); } } result.UnionWith(curseqs); } } Progress.SetMessage("Sorting sequences ..."); var peps = new List <string>(result); peps.Sort((m1, m2) => { var res = m1.Length.CompareTo(m2.Length); if (res == 0) { res = m1.CompareTo(m2); } return(res); }); var resultFile = fastaFile + ".pep"; using (StreamWriter sw = new StreamWriter(resultFile)) { peps.ForEach(m => sw.WriteLine(m)); } return(new[] { resultFile }); }
private void iIdentifiedSpectrumDataGridView_SelectionChanged(object sender, EventArgs e) { CurrencyManager cm = (CurrencyManager)this.BindingContext[peptides]; var spectrum = cm.Current as IIdentifiedSpectrum; if (spectrum.Annotations.ContainsKey("PepMutation")) { zgcPeaks.MasterPane.Title.Text = string.Format("MH={0:0.00000},PPM={1:0.0},SEQ={2},MUT={3},COUNT={4}", spectrum.TheoreticalMH, PrecursorUtils.mz2ppm(spectrum.TheoreticalMH, spectrum.TheoreticalMinusExperimentalMass), spectrum.Sequence, spectrum.Annotations["PepMutation"], (from a in spectrum.Annotations where a.Key.EndsWith("_PepCount") select Convert.ToInt32(a.Value)).Sum()); } else { zgcPeaks.MasterPane.Title.Text = string.Format("MH={0:0.00000},PPM={1:0.0},SEQ={2}", spectrum.TheoreticalMH, PrecursorUtils.mz2ppm(spectrum.TheoreticalMH, spectrum.TheoreticalMinusExperimentalMass), spectrum.Sequence); } var mass = aas.MonoPeptideMass(PeptideUtils.GetMatchedSequence(spectrum.Sequence)); if (Math.Abs(mass - spectrum.TheoreticalMass) > 0.1) { MessageBox.Show(string.Format("Error : {0} - {1}", mass, spectrum.TheoreticalMass)); return; } var name = string.Format("{0}_{1}", spectrum.Query.FileScan.Experimental, spectrum.Query.FileScan.FirstScan); var peakPane = zgcPeaks.MasterPane.PaneList[0]; peakPane.ClearData(); var ppmPane = zgcPeaks.MasterPane.PaneList[1]; ppmPane.ClearData(); if (!mgfMap.ContainsKey(name)) { MessageBox.Show("Cannot find peak list {0}", name); return; } var mgf = mgfMap[name]; var maxIntensity = mgf.Max(m => m.Intensity); var maxMz = Math.Min(2000, mgf.Max(m => m.Mz)); var mzTolerance = 0.02; var minIntensity = maxIntensity * 0.05; AddIonSeries(peakPane, ppmPane, mgf, mzTolerance, minIntensity, yBuilder, spectrum.Sequence, Color.Red); AddIonSeries(peakPane, ppmPane, mgf, mzTolerance, minIntensity, bBuilder, spectrum.Sequence, Color.Blue); if (spectrum.Charge > 2) { AddIonSeries(peakPane, ppmPane, mgf, mzTolerance, minIntensity, y2Builder, spectrum.Sequence, Color.Brown); AddIonSeries(peakPane, ppmPane, mgf, mzTolerance, minIntensity, b2Builder, spectrum.Sequence, Color.GreenYellow); } AddUnmatchedIons(peakPane, mgf); foreach (var pane in zgcPeaks.MasterPane.PaneList) { pane.XAxis.Scale.Min = 0; pane.XAxis.Scale.Max = maxMz; } zgcPeaks.UpdateGraph(); }
private void DrawSpectrum(IIdentifiedSpectrum spectrum) { if (spectrum.Annotations.ContainsKey("PepMutation")) { zgcPeaks.MasterPane.PaneList[0].Title.Text = string.Format("MH={0:0.00000},PPM={1:0.0},SEQ={2},MUT={3},COUNT={4}", spectrum.TheoreticalMH, PrecursorUtils.mz2ppm(spectrum.TheoreticalMH, spectrum.TheoreticalMinusExperimentalMass), spectrum.Sequence, spectrum.Annotations["PepMutation"], (from a in spectrum.Annotations where a.Key.EndsWith("_PepCount") select Convert.ToInt32(a.Value)).Sum()); } else { zgcPeaks.MasterPane.PaneList[0].Title.Text = string.Format("MH={0:0.00000},PPM={1:0.0},SEQ={2}", spectrum.TheoreticalMH, PrecursorUtils.mz2ppm(spectrum.TheoreticalMH, spectrum.TheoreticalMinusExperimentalMass), spectrum.Sequence); } var mass = aas.MonoPeptideMass(PeptideUtils.GetMatchedSequence(spectrum.Sequence)); if (Math.Abs(mass - spectrum.TheoreticalMass) > 0.1) { MessageBox.Show(string.Format("Error : {0} - {1}", mass, spectrum.TheoreticalMass)); return; } var name = string.Format("{0}_{1}", spectrum.Query.FileScan.Experimental, spectrum.Query.FileScan.FirstScan); var peakPane = zgcPeaks.MasterPane.PaneList[0]; peakPane.ClearData(); var ppmPane = zgcPeaks.MasterPane.PaneList[1]; ppmPane.ClearData(); if (!mgfMap.ContainsKey(name)) { MessageBox.Show("Cannot find peak list {0}", name); return; } var mgf = mgfMap[name]; var maxIntensity = mgf.Max(m => m.Intensity); var maxMz = Math.Min(2000, mgf.Max(m => m.Mz)); var productTolerance = productIonPPM; var minIntensity = maxIntensity * 0.05; AddIonSeries(peakPane, ppmPane, mgf, productTolerance, minIntensity, yBuilder, spectrum.Sequence, Color.Red); AddIonSeries(peakPane, ppmPane, mgf, productTolerance, minIntensity, bBuilder, spectrum.Sequence, Color.Blue); if (spectrum.Charge > 2) { AddIonSeries(peakPane, ppmPane, mgf, productTolerance, minIntensity, y2Builder, spectrum.Sequence, Color.Brown); AddIonSeries(peakPane, ppmPane, mgf, productTolerance, minIntensity, b2Builder, spectrum.Sequence, Color.GreenYellow); } AddUnmatchedIons(peakPane, mgf); foreach (var pane in zgcPeaks.MasterPane.PaneList) { pane.XAxis.Scale.Min = 0; pane.XAxis.Scale.Max = maxMz; } zgcPeaks.UpdateGraph(); var targetpngfile = GetTargetFile(targetDir, spectrum); zgcPeaks.GetImage().Save(targetpngfile, ImageFormat.Png); }