public void test2() { string path = @"C:\Users\Rui Zhang\Downloads\Serum_1_C18_03292019_Ali.raw"; ISpectrumReader reader = new ThermoRawSpectrumReader(); reader.Init(path); RidgeLineFinder coeffMatrix = new RidgeLineFinder(1.0, 2, 1, 2); IProcess processer = new PeakPickingCWT(coeffMatrix); //for (int i = reader.GetFirstScan(); i < reader.GetLastScan(); i++) int i = 347; { if (reader.GetMSnOrder(i) < 2) { ISpectrum spectrum = reader.GetSpectrum(i); List <IPeak> peaks = spectrum.GetPeaks(); spectrum = processer.Process(spectrum); IAreaCalculator calculator = new TrapezoidalRule(); IBounder bounder = new PerpendicularDrop(); PeakAreaCalculator areaCalculator = new PeakAreaCalculator(calculator, bounder); areaCalculator.Init(peaks); foreach (IPeak peak in spectrum.GetPeaks()) { Console.WriteLine(peak.GetMZ() + " : " + areaCalculator.Area(peak).ToString()); } } } }
public ISpectrum Process(ISpectrum spectrum) { List <IPeak> peaks = spectrum.GetPeaks(); double[] signal = peaks.Select(p => p.GetIntensity()).ToArray(); SortedDictionary <double, List <double> > matrix = new SortedDictionary <double, List <double> >(); for (double a = 1.0; a <= maxScale; a += steps) { double[] processed = Algorithm.CWT.Transform(signal, a); matrix[a] = processed.ToList(); } List <RidgeLine> lines = finder.Find( spectrum.GetPeaks().Select(p => p.GetMZ()).ToList(), matrix); HashSet <double> mz = new HashSet <double>(lines.Select(p => p.Pos).ToList()); List <IPeak> processedPeaks = peaks.Where(p => mz.Contains(p.GetMZ())).ToList(); ISpectrum newSpectrum = spectrum.Clone(); newSpectrum.SetPeaks(processedPeaks); return(newSpectrum); }
public ISpectrum Process(ISpectrum spectrum) { if (spectrum.GetPeaks().Count == 0) { return(spectrum); } // insert pseudo peaks for large gap List <IPeak> peaks = new List <IPeak>(); double mz = spectrum.GetPeaks().First().GetMZ(); peaks.Add(new GeneralPeak(mz - precision, 0)); foreach (IPeak peak in spectrum.GetPeaks()) { if (peak.GetMZ() - mz > precision) { double middle = (mz + peak.GetMZ()) / 2; peaks.Add(new GeneralPeak(middle, 0)); } peaks.Add(peak); mz = peak.GetMZ(); } peaks.Add(new GeneralPeak(mz + precision, 0)); List <IPeak> processedPeaks = new List <IPeak>(); int index = 1; int end = peaks.Count - 1; int head = index + 1; while (index < end) { if (peaks[index - 1].GetIntensity() < peaks[index].GetIntensity()) { head = index + 1; } while (head < end && peaks[head].GetIntensity() == peaks[index].GetIntensity()) { head++; } if (peaks[head].GetIntensity() < peaks[index].GetIntensity()) { processedPeaks.Add(peaks[index]); index = head; } index++; } ISpectrum newSpectrum = spectrum.Clone(); newSpectrum.SetPeaks(processedPeaks); return(newSpectrum); }
public List <IGlycoPeptideScore> MatchSpectrum(ISpectrum spectrum, List <IGlycoPeptide> glycoPeptides) { List <IGlycoPeptideScore> results = new List <IGlycoPeptideScore>(); foreach (IAccumulatedGlycoPeptideMassProxy glyco in glycoPeptides) { double score = 0.0; List <double> massList = glyco.GetMass(); foreach (IPeak peak in spectrum.GetPeaks()) { if (MatchPeakGlycoPeptideMass(peak, (spectrum as ISpectrumMSn).GetParentCharge(), massList)) { score += (alpha * peak.GetIntensity() + beta) * 1000.0; } } if (score > 0) { results.Add(new GeneralGlycoPeptideScore(glyco, score)); } } return(results); }
public List <GUI> FindGlucoseUnits(ISpectrum spectrum) { List <GUI> units = new List <GUI>(); List <IPeak> peaks = spectrum.GetPeaks(); int scan = spectrum.GetScanNum(); for (int i = 0; i < Glucose.Length; i++) { double mass = Glucose[i]; double bestIntensity = 0; IPeak bestPeak = null; List <double> mzCandidates = Calculator.To.ComputeMZ(mass, maxCharge); foreach (double mz in mzCandidates) { int idx = BinarySearchPoints(peaks, mz); if (idx > 0 && peaks[idx].GetIntensity() > bestIntensity) { bestIntensity = peaks[idx].GetIntensity(); bestPeak = peaks[idx]; } } if (bestPeak is null) { continue; } units.Add(new GUI(i + 2, scan, bestPeak)); } return(units); }
public List <IPeptide> PeptidesFilter(ISpectrum spectrum) { List <IPeptide> peptides = new List <IPeptide>(); List <double> massList = new List <double>(); int parentCharge = (spectrum as ISpectrumMSn).GetParentCharge(); for (int i = 1; i <= parentCharge; i++) { foreach (IPeak peak in spectrum.GetPeaks()) { massList.Add(calcualtor.CalcChargeMass(peak.GetMZ(), i, option)); } } if (massList.Count > 0) { massList.Sort(); } foreach (IPeptide peptide in peptideDB) { double mass = calcualtor.CalcPeptideMass(peptide, option) + UtilMass.HexNAc; if (MassBinarySearch.FindPPM(mass, massList, matcher.GetTolerance())) { peptides.Add(peptide); } } return(peptides); }
public void test1() { var watch = new System.Diagnostics.Stopwatch(); watch.Start(); string path = @"C:\Users\Rui Zhang\Downloads\Serum_1_C18_03292019_Ali.raw"; ISpectrumReader reader = new ThermoRawSpectrumReader(); reader.Init(path); //for (int i = reader.GetFirstScan(); i < reader.GetLastScan(); i++) int i = 342; RidgeLineFinder coeffMatrix = new RidgeLineFinder(1.0, 2, 1, 2); { if (reader.GetMSnOrder(i) < 2) { ISpectrum spectrum = reader.GetSpectrum(i); List <IPeak> peaks = spectrum.GetPeaks(); double[] signal = peaks.Select(p => p.GetIntensity()).ToArray(); SortedDictionary <double, List <double> > matrix = new SortedDictionary <double, List <double> >(); for (double a = 1; a <= 120; a += 6) { double[] processed = CWT.Transform(signal, a); matrix[a] = processed.ToList(); } List <RidgeLine> lines = coeffMatrix.Find(spectrum.GetPeaks().Select(p => p.GetMZ()).ToList(), matrix); Console.WriteLine(lines.Count); Console.WriteLine(peaks.Count); foreach (RidgeLine line in lines) { Console.WriteLine(line.Pos); } } //break; } Console.WriteLine($"Execution Time: {watch.ElapsedMilliseconds} ms"); //Console.Read(); }
public static Spectrum GetMS1Spectrum(ref ThermoRawSpectrumReader reader, int scan, ref ISpectrum ms1) { // scan header Spectrum spectrum = new Spectrum { id = "scan=" + scan.ToString() }; double dLowMass = 0; double dHighMass = 0; double dTIC = 0; double dBasePeakMass = 0; double dBasePeakIntensity = 0; reader.GetScanHeaderInfoForScanNum(scan, ref dLowMass, ref dHighMass, ref dTIC, ref dBasePeakMass, ref dBasePeakIntensity); SetScanHeader(spectrum, dLowMass, dHighMass, dTIC, dBasePeakMass, dBasePeakIntensity); // binary data spectrum.binaryDataArrayList = new BinaryDataArrayList(); SetBinaryDataArrayHeader(spectrum.binaryDataArrayList); ms1 = reader.GetSpectrum(scan); //majorPeaks = picking.Process(ms1.GetPeaks()); spectrum.cvParam[0] = new Component.CVParam() { cvRef = "MS", accession = "MS:1000511", name = "ms level", value = "1", }; spectrum.binaryDataArrayList.binaryDataArray[0].binary = ms1.GetPeaks().SelectMany(p => BitConverter.GetBytes(p.GetMZ())).ToArray(); spectrum.binaryDataArrayList.binaryDataArray[1].binary = ms1.GetPeaks().SelectMany(p => BitConverter.GetBytes(p.GetIntensity())).ToArray(); spectrum.defaultArrayLength = ms1.GetPeaks().Count.ToString(); spectrum.binaryDataArrayList.binaryDataArray[0].encodedLength = Convert.ToBase64String(spectrum.binaryDataArrayList.binaryDataArray[0].binary).Length.ToString(); spectrum.binaryDataArrayList.binaryDataArray[1].encodedLength = Convert.ToBase64String(spectrum.binaryDataArrayList.binaryDataArray[1].binary).Length.ToString(); return(spectrum); }
public ISpectrum Process(ISpectrum spectrum) { List <IPeak> peaks = peakpick(spectrum.GetPeaks(), maxPeaks); peaks.Sort(); NormalizePeaks(peaks, factor); spectrum.SetPeaks(peaks); return(spectrum); }
public void Process(ISpectrum spectrum) { List <IPeak> peaks = spectrum.GetPeaks() .OrderByDescending(pk => pk.GetIntensity()) .Take(maxPeaks) .OrderBy(pk => pk.GetMZ()).ToList();; spectrum.SetPeaks(peaks); }
private void SetMatcher(ISpectrum spectrum) { List <IPoint> points = new List <IPoint>(); foreach (IPeak peaks in spectrum.GetPeaks()) { points.Add(new GeneralPoint(peaks.GetMZ())); } matcher.setData(points); }
public ISpectrum Process(ISpectrum spectrum) { ISpectrum filtered = peakPicking.Process(spectrum); List <IPeak> peaks = new List <IPeak>(); double minIntensity = filtered.GetPeaks().Min(p => p.GetIntensity()); filtered.SetPeaks( peaks.Where(p => p.GetIntensity() > ratio * minIntensity).ToList()); return(filtered); }
protected virtual List <IPeak> InsertPeaks(ISpectrum spectrum) { List <IPeak> peaks = new List <IPeak>(); double mz = spectrum.GetPeaks().First().GetMZ(); peaks.Add(new GeneralPeak(mz - precision, 0)); foreach (IPeak peak in spectrum.GetPeaks()) { if (peak.GetMZ() - mz > precision) { double middle = (mz + peak.GetMZ()) / 2; peaks.Add(new GeneralPeak(middle, 0)); } peaks.Add(peak); mz = peak.GetMZ(); } peaks.Add(new GeneralPeak(mz + precision, 0)); return(peaks); }
public DrawingVisual CreateDrawingVisual(ISpectrum spectrum, List <IResult> results, double x1 = 40, double y1 = 40, double x2 = 660, int y2 = 300) { DrawingVisual drawingVisual = new DrawingVisual(); // Create a drawing and draw it in the DrawingContext. using (DrawingContext drawingContext = drawingVisual.RenderOpen()) { double delta = 10; Pen pen = new Pen(Brushes.Black, 1); Rect rect = new Rect(new Point(x1 - delta, y1 - delta), new Point(x2 + delta, y2 + delta)); // range of (600, 260) drawingContext.DrawRectangle(Brushes.Transparent, pen, rect); // process peaks List <IPeak> peaks = spectrum.GetPeaks(); double deltaX = x2 - x1; double deltaY = y2 - y1; double minX = peaks.Min(p => p.GetMZ()); double maxX = peaks.Max(p => p.GetMZ()); List <double> x = peaks.Select(p => (p.GetMZ() - minX) / (maxX - minX) * deltaX + x1).ToList(); double maxY = peaks.Max(p => p.GetIntensity()); List <double> y = peaks.Select(p => y2 - p.GetIntensity() / maxY * deltaY).ToList(); // draw curve List <Point> points = new List <Point>(); for (int i = 0; i < x.Count; i++) { points.Add(new Point(x[i], y[i])); } Pen curve = new Pen(Brushes.Blue, 1); for (int i = 0; i < points.Count - 1; i++) { drawingContext.DrawLine(curve, points[i], points[i + 1]); } // draw points Pen p = new Pen(Brushes.Red, 3); List <double> mzList = results.Select(r => r.GetMZ()).ToList(); for (int i = 0; i < mzList.Count; i++) { double xi = (mzList[i] - minX) / (maxX - minX) * deltaX + x1; double yi = y[BinarySearchPoints(mzList, xi)]; Point point = new Point(xi, yi); drawingContext.DrawEllipse(Brushes.Red, p, point, 0.5, 0.5); } } return(drawingVisual); }
public void Process(ISpectrum spectrum) { List <IPeak> peaks = spectrum.GetPeaks(); //double sumsIntensity = Math.Log10(peaks.Sum(x => x.GetIntensity())); for (int i = 0; i < peaks.Count; i++) { peaks[i].SetIntensity(Math.Log10(peaks[i].GetIntensity()) * scale); } spectrum.SetPeaks(peaks); }
public void Run() { var watch = new System.Diagnostics.Stopwatch(); watch.Start(); var builder = new ContainerBuilder(); builder.RegisterModule(new TopPeakPickingDelegatorModule() { MaxPeaks = 100 }); builder.RegisterModule(new SpectrumProcessingModule() { ScaleFactor = 1.0 }); builder.RegisterModule(new ThermoRawSpectrumModule()); IContainer Container = builder.Build(); List <IPeak> peakA = new List <IPeak>(); List <IPeak> peakB = new List <IPeak>(); using (var scope = Container.BeginLifetimeScope()) { var spectrumFacotry = scope.Resolve <ISpectrumFactory>(); spectrumFacotry.Init(@"C:\Users\Rui Zhang\Downloads\ZC_20171218_H95_R1.raw"); ISpectrum spectrum = spectrumFacotry.GetSpectrum(8140); peakA.AddRange(spectrum.GetPeaks()); } using (var scope = Container.BeginLifetimeScope()) { var spectrumFacotry = scope.Resolve <ISpectrumFactory>(); spectrumFacotry.Init(@"C:\Users\Rui Zhang\Downloads\ZC_20171218_H68_R1.raw"); ISpectrum spectrum = spectrumFacotry.GetSpectrum(8081); peakB.AddRange(spectrum.GetPeaks()); } double cons = computeCos(peakA, peakB, 0.01); if (cons < 0.3) { Console.WriteLine("spectrum: " + cons.ToString()); Console.WriteLine(cons); } Console.WriteLine($"Execution Time: {watch.ElapsedMilliseconds} ms"); Console.Read(); }
public ISpectrum Process(ISpectrum spectrum) { ISpectrum centroid = peakPicking.Process(spectrum); List <IPeak> peaks = new List <IPeak>(); foreach (IPeak cPeak in centroid.GetPeaks()) { List <IPeak> neighbors = NeighborPeaks(cPeak, spectrum.GetPeaks()); peaks.Add(Average(cPeak, neighbors)); } centroid.SetPeaks(peaks); return(centroid); }
public double computeCos(ISpectrum spectrumA, ISpectrum spectrumB, double tol) { List <IPeak> p1 = spectrumA.GetPeaks(); List <IPeak> p2 = spectrumB.GetPeaks(); double lowerBound = Math.Min(p1.Min(x => x.GetMZ()), p2.Min(x => x.GetMZ())); double upperBound = Math.Max(p1.Max(x => x.GetMZ()), p2.Max(x => x.GetMZ())); int bucketNums = (int)Math.Ceiling((upperBound - lowerBound + 1) / tol); List <IPeak>[] q1 = new List <IPeak> [bucketNums]; List <IPeak>[] q2 = new List <IPeak> [bucketNums]; for (int i = 0; i < bucketNums; i++) { q1[i] = new List <IPeak>(); q2[i] = new List <IPeak>(); } foreach (IPeak pk in p1) { int index = (int)Math.Ceiling((pk.GetMZ() - lowerBound) / tol); q1[index].Add(pk); } foreach (IPeak pk in p2) { int index = (int)Math.Ceiling((pk.GetMZ() - lowerBound) / tol); q2[index].Add(pk); } double numerator = 0; for (int i = 0; i < bucketNums; i++) { numerator += computeDot(q1[i], q2[i]); } double denominator1 = 0; foreach (IPeak pk in p1) { denominator1 += pk.GetIntensity() * pk.GetIntensity(); } double denominator2 = 0; foreach (IPeak pk in p2) { denominator2 += pk.GetIntensity() * pk.GetIntensity(); } double denominator = Math.Sqrt(denominator1) * Math.Sqrt(denominator2); return(numerator / denominator); }
protected List <IAnnotatedPeak> GenerateMatcherResult(ISpectrum spectrum) { List <IAnnotatedPeak> peaks = new List <IAnnotatedPeak>(); foreach (IPeak peak in spectrum.GetPeaks()) { List <IGlycoPeptide> g = MatchPoints(peak, (spectrum as ISpectrumMSn).GetParentCharge()); if (g.Count > 0) { peaks.Add(new GeneralAnnotatedSpectrumPeak(peak, g)); } } return(peaks); }
private void Visualize_Click(object sender, RoutedEventArgs e) { if (path.Length == 0) { MessageBox.Show("Please input the spectrum file (*.Raw) path!"); return; } int scan; int.TryParse(ScanNumber.Text, out scan); if (scan > 0 && scan < spectrumReader.GetLastScan() && spectrumReader.GetMSnOrder(scan) == 1) { ISpectrum spectrum = spectrumProcessor.Process(spectrumReader.GetSpectrum(scan)); double rt = spectrumReader.GetRetentionTime(scan); double index = Math.Round(engine.Normalize(rt), 2); string output = "Retention time: " + Math.Round(rt, 2).ToString() + " (min) "; if (index > 0) { output += "GUI index " + index.ToString(); } RTtime.Text = output; // search List <IResult> results = spectrumSearch.Search(spectrum); //// draw curve canvas.Children.Clear(); if (spectrum.GetPeaks().Count > 0) { canvas.Children.Add(new VisualHost { Visual = visualizer.CreateDrawingVisual(spectrum, results) }); } PeakArea.Visibility = Visibility.Visible; } else { MessageBox.Show("Please input a valid scan number!"); canvas.Children.Clear(); PeakArea.Visibility = Visibility.Collapsed; return; } }
protected IDataPoints InitSpectrum(ISpectrum spectrum) { BucketSpectrumDataPoints data = new BucketSpectrumDataPoints( (parameter as DPSpectrumCIDParameter).GetBucketSize(), (parameter as DPSpectrumCIDParameter).GetMinRange()); int charge = (spectrum as ISpectrumMSn).GetParentCharge(); for (int i = 1; i <= charge; i++) { foreach (IPeak peak in spectrum.GetPeaks()) { PeakPoint pt = new PeakPoint(peak.GetIntensity(), peak.GetMZ(), i, peak.GetMZ().ToString()); data.Add(pt); } } return(data); }
// assume the spectrum read sequentially public double GetMonoMass(ISpectrum spectrum) { if (spectrum.GetMSnOrder() == 1) { List <IPoint> points = new List <IPoint>(); foreach (IPeak pk in spectrum.GetPeaks()) { points.Add(new PeakPoint(pk)); } matcher.setData(points); return(0); } ISpectrumMSn spectrumMSn = spectrum as ISpectrumMSn; double mz = spectrumMSn.GetParentMZ(); double monoMass = mz; // search isotopic point on full MS spectrum int charge = spectrumMSn.GetParentCharge(); int isotopic = 0; while (isotopic < maxIsotopic) { double target = mz - Proton / charge * (isotopic + 1); if (!matcher.Found(new GeneralPoint(target))) { break; } isotopic++; } // get max intensity peak if (isotopic == 0) { return(monoMass); } double isoMZ = mz - Proton / charge * isotopic; List <IPoint> matched = matcher.Search(new GeneralPoint(isoMZ)); return(matched.OrderBy(x => Math.Abs((x as PeakPoint).MZ - isoMZ)).First().GetValue()); }
public ISpectrum Process(ISpectrum spectrum) { if (spectrum.GetPeaks().Count == 0) { return(spectrum); } // insert pseudo peaks for large gap List <IPeak> peaks = InsertPeaks(spectrum); List <IPeak> processedPeaks = new List <IPeak>(); int index = 1; int end = peaks.Count - 1; int head = index + 1; while (index < end) { if (peaks[index - 1].GetIntensity() < peaks[index].GetIntensity()) { head = index + 1; } while (head < end && peaks[head].GetIntensity() == peaks[index].GetIntensity()) { head++; } if (peaks[head].GetIntensity() < peaks[index].GetIntensity()) { processedPeaks.Add(peaks[index]); index = head; } index++; } ISpectrum newSpectrum = spectrum.Clone(); newSpectrum.SetPeaks(processedPeaks); return(newSpectrum); }
public void test1() { string path = @"C:\Users\Rui Zhang\Downloads\ZC_20171218_C16_R1.raw"; ThermoRawSpectrumReader reader = new ThermoRawSpectrumReader(); reader.Init(path); ISpectrum ms2 = reader.GetSpectrum(7638); //IProcess processer = new LocalNeighborPicking(); IProcess processer = new WeightedAveraging(new LocalNeighborPicking()); //RidgeLineFinder coeffMatrix = new RidgeLineFinder(1.0, 2, 1, 2); //IProcess processer = new PeakPickingCWT(coeffMatrix); ms2 = processer.Process(ms2); using (StreamWriter outputFile = new StreamWriter(@"C:\Users\Rui Zhang\Downloads\peak.csv")) { outputFile.WriteLine("mz,intensity"); foreach (IPeak pk in ms2.GetPeaks()) { outputFile.WriteLine(pk.GetMZ().ToString() + "," + pk.GetIntensity().ToString()); } } }
public int FindGlucoseUnits(ISpectrum spectrum) { List <IPeak> peaks = spectrum.GetPeaks(); double bestIntensity = 0; int units = 0; for (int i = 0; i < Glucose.Length; i++) { double mass = Glucose[i]; List <double> mzCandidates = IonMassCalc.Instance.ComputeMZ(mass); foreach (double mz in mzCandidates) { int idx = BinarySearchPoints(peaks, mz); if (idx > 0 && peaks[idx].GetIntensity() > bestIntensity) { bestIntensity = peaks[idx].GetIntensity(); units = i + 2; } } } return(units); }
public void test2() { string path = @"C:\Users\Rui Zhang\Downloads\Serum_1_C18_03292019_Ali.raw"; ISpectrumReader reader = new ThermoRawSpectrumReader(); reader.Init(path); RidgeLineFinder coeffMatrix = new RidgeLineFinder(1.0, 2, 1, 2); IProcess processer = new PeakPickingCWT(coeffMatrix); //for (int i = reader.GetFirstScan(); i < reader.GetLastScan(); i++) int i = 342; { if (reader.GetMSnOrder(i) < 2) { ISpectrum spectrum = reader.GetSpectrum(i); spectrum = processer.Process(spectrum); foreach (var peak in spectrum.GetPeaks()) { Console.WriteLine(peak.GetMZ().ToString() + ": " + peak.GetIntensity().ToString()); } } } }
public void ParallelRun(string path, string outputDir, AveragineType type, ChargerType chargerType) { string file = Path.GetFileNameWithoutExtension(path) + ".mgf"; string output = Path.Combine(outputDir, file); ThermoRawSpectrumReader reader = new ThermoRawSpectrumReader(); LocalMaximaPicking picking = new LocalMaximaPicking(ms1PrcisionPPM); reader.Init(path); Dictionary <int, List <int> > scanGroup = new Dictionary <int, List <int> >(); int current = -1; int start = reader.GetFirstScan(); int end = reader.GetLastScan(); for (int i = start; i < end; i++) { if (reader.GetMSnOrder(i) == 1) { current = i; scanGroup[i] = new List <int>(); } else if (reader.GetMSnOrder(i) == 2) { scanGroup[current].Add(i); } } List <MS2Info> ms2Infos = new List <MS2Info>(); Parallel.ForEach(scanGroup, (scanPair) => { if (scanPair.Value.Count > 0) { ISpectrum ms1 = reader.GetSpectrum(scanPair.Key); foreach (int i in scanPair.Value) { double mz = reader.GetPrecursorMass(i, reader.GetMSnOrder(i)); List <IPeak> ms1Peaks = FilterPeaks(ms1.GetPeaks(), mz, searchRange); if (ms1Peaks.Count() == 0) { continue; } // insert pseudo peaks for large gap List <IPeak> peaks = new List <IPeak>(); double precision = 0.02; double last = ms1Peaks.First().GetMZ(); foreach (IPeak peak in ms1Peaks) { if (peak.GetMZ() - last > precision) { peaks.Add(new GeneralPeak(last + precision / 2, 0)); peaks.Add(new GeneralPeak(peak.GetMZ() - precision / 2, 0)); } peaks.Add(peak); last = peak.GetMZ(); } List <IPeak> majorPeaks = picking.Process(peaks); ICharger charger = new Patterson(); if (chargerType == ChargerType.Fourier) { charger = new Fourier(); } else if (chargerType == ChargerType.Combined) { charger = new PattersonFourierCombine(); } int charge = charger.Charge(peaks, mz - searchRange, mz + searchRange); // find evelope cluster EnvelopeProcess envelope = new EnvelopeProcess(); var cluster = envelope.Cluster(majorPeaks, mz, charge); if (cluster.Count == 0) { continue; } // find monopeak Averagine averagine = new Averagine(type); BrainCSharp braincs = new BrainCSharp(); MonoisotopicSearcher searcher = new MonoisotopicSearcher(averagine, braincs); MonoisotopicScore result = searcher.Search(mz, charge, cluster); double precursorMZ = result.GetMZ(); // write mgf ISpectrum ms2 = reader.GetSpectrum(i); IProcess processer = new WeightedAveraging(new LocalNeighborPicking()); ms2 = processer.Process(ms2); MS2Info ms2Info = new MS2Info { PrecursorMZ = result.GetMZ(), PrecursorCharge = charge, Scan = ms2.GetScanNum(), Retention = ms2.GetRetention(), Peaks = ms2.GetPeaks() }; lock (resultLock) { ms2Infos.Add(ms2Info); } } } readingProgress.Add(scanGroup.Count); }); ms2Infos = ms2Infos.OrderBy(m => m.Scan).ToList(); using (FileStream ostrm = new FileStream(output, FileMode.OpenOrCreate, FileAccess.Write)) { using (StreamWriter writer = new StreamWriter(ostrm)) { foreach (MS2Info ms2 in ms2Infos) { WriteMGF(writer, path + ",SCANS=" + ms2.Scan.ToString() + ",PRECURSOR=" + ms2.PrecursorMZ, ms2.PrecursorMZ, ms2.PrecursorCharge, ms2.Scan, ms2.Retention * 60, reader.GetActivation(ms2.Scan), ms2.Peaks); writer.Flush(); } } } // update progress progress.Add(); }
public void Init(ISpectrum spectrum) { searcher.Init(spectrum.GetPeaks() .Select(p => new Point <IPeak>(p.GetMZ(), p)).ToList()); }
public void Test1() { string path = @"C:\Users\Rui Zhang\Downloads\ZC_20171218_C16_R1.raw"; string fasta = @"C:\Users\Rui Zhang\Downloads\haptoglobin.fasta"; // peptides IProteinReader proteinReader = new FastaReader(); List <IProtein> proteins = proteinReader.Read(fasta); List <IProtein> decoyProteins = new List <IProtein>(); foreach (IProtein protein in proteins) { IProtein p = new BaseProtein(); p.SetSequence(Reverse(protein.Sequence())); decoyProteins.Add(p); } List <Proteases> proteases = new List <Proteases>() { Proteases.Trypsin, Proteases.GluC }; HashSet <string> peptides = new HashSet <string>(); ProteinDigest proteinDigest = new ProteinDigest(2, 5, proteases[0]); foreach (IProtein protein in decoyProteins) { peptides.UnionWith(proteinDigest.Sequences(protein.Sequence(), ProteinPTM.ContainsNGlycanSite)); } for (int i = 1; i < proteases.Count; i++) { proteinDigest.SetProtease(proteases[i]); List <string> peptidesList = peptides.ToList(); foreach (string seq in peptidesList) { peptides.UnionWith(proteinDigest.Sequences(seq, ProteinPTM.ContainsNGlycanSite)); } } Assert.True(peptides.Contains("KDNLTYVGDGETR")); // build glycan GlycanBuilder glycanBuilder = new GlycanBuilder(); glycanBuilder.Build(); // search List <SearchResult> searchResults = new List <SearchResult>(); ThermoRawSpectrumReader reader = new ThermoRawSpectrumReader(); LocalMaximaPicking picking = new LocalMaximaPicking(); IProcess process = new LocalNeighborPicking(); reader.Init(path); double searchRange = 2; ISpectrum ms1 = null; List <IPeak> majorPeaks = new List <IPeak>(); ISearch <string> oneSearcher = new BucketSearch <string>(ToleranceBy.PPM, 10); PrecursorMatch precursorMatcher = new PrecursorMatch(oneSearcher); precursorMatcher.Init(peptides.ToList(), glycanBuilder.GlycanMaps()); ISearch <string> moreSearcher = new BucketSearch <string>(ToleranceBy.Dalton, 0.01); SequenceSearch sequenceSearcher = new SequenceSearch(moreSearcher); ISearch <int> extraSearcher = new BucketSearch <int>(ToleranceBy.Dalton, 0.01); GlycanSearch glycanSearcher = new GlycanSearch(extraSearcher, glycanBuilder.GlycanMaps()); SearchAnalyzer searchAnalyzer = new SearchAnalyzer(); for (int i = reader.GetFirstScan(); i < reader.GetLastScan(); i++) { if (reader.GetMSnOrder(i) < 2) { ms1 = reader.GetSpectrum(i); majorPeaks = picking.Process(ms1.GetPeaks()); } else { double mz = reader.GetPrecursorMass(i, reader.GetMSnOrder(i)); if (ms1.GetPeaks() .Where(p => p.GetMZ() > mz - searchRange && p.GetMZ() < mz + searchRange) .Count() == 0) { continue; } Patterson charger = new Patterson(); int charge = charger.Charge(ms1.GetPeaks(), mz - searchRange, mz + searchRange); // find evelope cluster EnvelopeProcess envelope = new EnvelopeProcess(); var cluster = envelope.Cluster(majorPeaks, mz, charge); if (cluster.Count == 0) { continue; } // find monopeak Averagine averagine = new Averagine(AveragineType.GlycoPeptide); BrainCSharp braincs = new BrainCSharp(); MonoisotopicSearcher searcher = new MonoisotopicSearcher(averagine, braincs); MonoisotopicScore result = searcher.Search(mz, charge, cluster); double precursorMZ = result.GetMZ(); // search ISpectrum ms2 = reader.GetSpectrum(i); ms2 = process.Process(ms2); //precursor match var pre_results = precursorMatcher.Match(precursorMZ, charge); if (pre_results.Count == 0) { continue; } // spectrum search var peptide_results = sequenceSearcher.Search(ms2.GetPeaks(), charge, pre_results); if (peptide_results.Count == 0) { continue; } var glycan_results = glycanSearcher.Search(ms2.GetPeaks(), charge, pre_results); if (glycan_results.Count == 0) { continue; } var temp_results = searchAnalyzer.Analyze(i, ms2.GetPeaks(), peptide_results, glycan_results); break; } } }
public void Test1() { string path = @"D:\Raw\ZC_20171218_N14_R2.raw"; ISpectrumReader reader = new ThermoRawSpectrumReader(); LocalMaximaPicking picking = new LocalMaximaPicking(10); reader.Init(path); Dictionary <int, int> scanMap = new Dictionary <int, int>(); int current = -1; int start = reader.GetFirstScan(); int end = reader.GetLastScan(); for (int i = start; i < end; i++) { if (reader.GetMSnOrder(i) == 1) { current = i; } else if (reader.GetMSnOrder(i) == 2) { scanMap[i] = current; } } double searchRange = 1; int scan_num = 6223; if (scanMap.ContainsKey(scan_num)) { int paranet_scan = scanMap[scan_num]; ISpectrum ms1 = reader.GetSpectrum(paranet_scan); double mz = reader.GetPrecursorMass(scan_num, reader.GetMSnOrder(scan_num)); List <IPeak> ms1Peaks = FilterPeaks(ms1.GetPeaks(), mz, searchRange); if (ms1Peaks.Count() == 0) { return; } // insert pseudo peaks for large gap List <IPeak> peaks = new List <IPeak>(); double precision = 0.02; double last = ms1Peaks.First().GetMZ(); foreach (IPeak peak in ms1Peaks) { if (peak.GetMZ() - last > precision) { peaks.Add(new GeneralPeak(last + precision / 2, 0)); peaks.Add(new GeneralPeak(peak.GetMZ() - precision / 2, 0)); } peaks.Add(peak); last = peak.GetMZ(); } List <IPeak> majorPeaks = picking.Process(peaks); //Console.WriteLine("mz,intensity"); //foreach (IPeak pk in peaks) //{ // Console.WriteLine(pk.GetMZ().ToString() + "," + pk.GetIntensity().ToString()); //} Fourier charger = new Fourier(); int charge = charger.Charge(peaks, mz - searchRange, mz + searchRange); Patterson charger2 = new Patterson(); PattersonFourierCombine charger3 = new PattersonFourierCombine(); Console.WriteLine(charge.ToString() + " " + charger2.Charge(peaks, mz - searchRange, mz + searchRange).ToString() + " " + charger3.Charge(peaks, mz - searchRange, mz + searchRange).ToString()); } }