public void AreaTest() { NGlycanTheoryPeaksBuilder builder = new NGlycanTheoryPeaksBuilder(); builder.SetBuildType(true, false, false); List <IGlycanPeak> glycans = builder.Build(); ISpectrumReader spectrumReader = new ThermoRawSpectrumReader(); spectrumReader.Init(@"C:\Users\iruiz\Downloads\GUI\compare\data\HBS1_dextrinspkd_C18_10252018.raw"); List <double> ions = new List <double>(); ions.Add(Calculator.proton); Calculator.To.SetChargeIons(ions); using (StreamWriter file = new(@"C:\Users\iruiz\Downloads\GUI\compare\data\WriteLines2.csv")) { file.WriteLine("glycan,mass,mz,charge,score,area"); //for (int scan = spectrumReader.GetFirstScan(); scan <= spectrumReader.GetLastScan(); scan++) //{ int scan = 2931; // 3943; if (spectrumReader.GetMSnOrder(scan) != 1) { return; } ISpectrum spectrum = spectrumReader.GetSpectrum(scan); IResultFactory factory = new NGlycanResultFactory(); EnvelopeProcess envelopeProcess = new EnvelopeProcess(10, ToleranceBy.PPM); MonoisotopicSearcher monoisotopicSearcher = new MonoisotopicSearcher(factory); IProcess spectrumProcess = new LocalNeighborPicking(); ISpectrumSearch spectrumSearch = new NGlycanSpectrumSearch(glycans, spectrumProcess, envelopeProcess, monoisotopicSearcher); List <IResult> results = spectrumSearch.Search(spectrum); //IAreaCalculator areaCalculator = new TrapezoidalRule(); IXIC xicer = new TIQ3XIC(spectrumReader, 0.01, ToleranceBy.Dalton); //IXIC xicer = new PeakXIC(areaCalculator, spectrumReader, 0.01, ToleranceBy.Dalton); foreach (IResult r in results) { double area = xicer.Area(r); string output = r.Glycan().GetGlycan().Name() + "," + r.Glycan().GetGlycan().Mass().ToString() + "," + r.GetMZ().ToString() + "," + r.GetCharge().ToString() + "," + r.Score().ToString() + "," + area.ToString(); file.WriteLine(output); } //} } Assert.Pass(); }
public void NGlycanSearch() { IResultFactory factory = new NGlycanResultFactory(); EnvelopeProcess envelopeProcess = new EnvelopeProcess(10, ToleranceBy.PPM); MonoisotopicSearcher monoisotopicSearcher = new MonoisotopicSearcher(factory); NGlycanTheoryPeaksBuilder builder = new NGlycanTheoryPeaksBuilder(); builder.SetBuildType(true, false, false); List <IGlycanPeak> glycans = builder.Build(); IProcess spectrumProcess = new LocalNeighborPicking(); ISpectrumSearch spectrumSearch = new NGlycanSpectrumSearch(glycans, spectrumProcess, envelopeProcess, monoisotopicSearcher); ISpectrumReader spectrumReader = new ThermoRawSpectrumReader(); spectrumReader.Init(@"C:\Users\iruiz\Downloads\Serum_dextrinspiked_C18_10162018_2.raw"); for (int scan = spectrumReader.GetFirstScan(); scan <= spectrumReader.GetLastScan(); scan++) { if (spectrumReader.GetMSnOrder(scan) != 1) { continue; } ISpectrum spectrum = spectrumReader.GetSpectrum(scan); List <IResult> results = spectrumSearch.Search(spectrum); foreach (IResult r in results) { Console.WriteLine(r.Glycan().GetGlycan().Name() + ": " + r.Glycan().GetGlycan().Mass().ToString()); List <double> mzList = Calculator.To.ComputeMZ(r.Glycan().HighestPeak(), 3); Console.WriteLine(string.Join(",", mzList)); Console.WriteLine(r.Score()); foreach (IPeak pk in r.Matches()) { Console.WriteLine(pk.GetMZ() + " " + pk.GetIntensity()); } Console.WriteLine(); } break; } Assert.Pass(); }
static List <GUI> Init(ref ICurveFitting Fitter, ISpectrumReader reader) { double ppm = 5; object resultLock = new object(); List <double> Retention = new List <double>(); List <double> Guis = new List <double>(); IGUIFinder finder = new BinarySearchFinder(ppm); IProcess picking = new LocalNeighborPicking(); Dictionary <int, List <GUI> > pointMaps = new Dictionary <int, List <GUI> >(); int start = reader.GetFirstScan(); int end = reader.GetLastScan(); Parallel.For(start, end, (i) => { if (reader.GetMSnOrder(i) < 2) { ISpectrum spectrum = picking.Process(reader.GetSpectrum(i)); lock (resultLock) { pointMaps[i] = finder.FindGlucoseUnits(spectrum); } } }); List <List <GUI> > points = pointMaps.OrderBy(p => p.Key).Select(p => p.Value).ToList(); IGUISequencer sequencer = new DynamicProgrammingSequencer(); List <GUI> GuiPoints = sequencer.Choose(points); Fitter = new PolynomialFitting(); Dictionary <int, GUI> guiSelected = new Dictionary <int, GUI>(); foreach (GUI gui in GuiPoints) { if (guiSelected.ContainsKey(gui.Unit)) { if (guiSelected[gui.Unit].Peak.GetIntensity() < gui.Peak.GetIntensity()) { guiSelected[gui.Unit] = gui; } } else { guiSelected[gui.Unit] = gui; } } Retention.Clear(); Guis.Clear(); List <GUI> guiChoice = guiSelected.Values.OrderBy(g => g.Scan).ToList(); foreach (GUI gui in guiChoice) { int scan = gui.Scan; double time = reader.GetRetentionTime(scan); Retention.Add(time); Guis.Add(gui.Unit); } Fitter.Fit(Retention, Guis); return(GuiPoints); }
static void Main(string[] args) { string dir = @"C:\Users\iruiz\Downloads\GUI\compare\data"; string[] files = Directory.GetFiles(dir); List <double> ions = new List <double>(); ions.Add(Calculator.proton); Calculator.To.SetChargeIons(ions); foreach (string path in files) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); NGlycanTheoryPeaksBuilder builder = new NGlycanTheoryPeaksBuilder(); builder.SetBuildType(true, false, false); List <IGlycanPeak> glycans = builder.Build(); IResultFactory factory = new NGlycanResultFactory(); EnvelopeProcess envelopeProcess = new EnvelopeProcess(10, ToleranceBy.PPM); MonoisotopicSearcher monoisotopicSearcher = new MonoisotopicSearcher(factory); IProcess spectrumProcess = new LocalNeighborPicking(); ISpectrumSearch spectrumSearch = new NGlycanSpectrumSearch(glycans, spectrumProcess, envelopeProcess, monoisotopicSearcher); ISpectrumReader spectrumReader = new ThermoRawSpectrumReader(); spectrumReader.Init(path); ICurveFitting Fitter = new PolynomialFitting(); IResultSelect resultSelect = new ResultMaxSelect(); List <GUI> GuiPoints = Init(ref Fitter, spectrumReader); List <IResult> final = new List <IResult>(); for (int scan = spectrumReader.GetFirstScan(); scan <= spectrumReader.GetLastScan(); scan++) { if (spectrumReader.GetMSnOrder(scan) != 1) { continue; } ISpectrum spectrum = spectrumReader.GetSpectrum(scan); List <IResult> results = spectrumSearch.Search(spectrum); resultSelect.Add(results); final.AddRange(results); } // original List <string> outputString = new List <string>(); foreach (IResult present in final) { int scan = present.GetScan(); double rt = present.GetRetention(); double index = Math.Round(Normalize(Fitter, rt), 2); TIQ3XIC xicer = new TIQ3XIC(spectrumReader); double area = xicer.OneArea(present); List <string> output = new List <string>() { scan.ToString(), rt.ToString(), index > 0? index.ToString():"0", present.Glycan().GetGlycan().Name(), present.GetMZ().ToString(), area.ToString(), }; outputString.Add(string.Join(",", output)); } string outputPath = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path) + "_one_quant.csv"); using (FileStream ostrm = new FileStream(outputPath, FileMode.OpenOrCreate, FileAccess.Write)) { using (StreamWriter writer = new StreamWriter(ostrm)) { writer.WriteLine("scan,time,GUI,glycan,mz,area"); foreach (string output in outputString) { writer.WriteLine(output); } writer.Flush(); } } // merged List <string> outputStringMerge = new List <string>(); Dictionary <string, List <SelectResult> > resultContainer = resultSelect.Produce(); foreach (string name in resultContainer.Keys) { //if (name == "5-6-1-2-0") // Console.WriteLine("here"); List <SelectResult> selectResults = resultContainer[name]; foreach (SelectResult select in selectResults) { if (select.Results.Count == 0) { continue; } IResult present = select.Present; int scan = present.GetScan(); double rt = present.GetRetention(); double index = Math.Round(Normalize(Fitter, rt), 2); IXIC xicer = new TIQ3XIC(spectrumReader); double area = xicer.Area(select); List <string> output = new List <string>() { scan.ToString(), rt.ToString(), index > 0? index.ToString():"0", name, present.GetMZ().ToString(), area.ToString() }; outputStringMerge.Add(string.Join(",", output)); } } string outputPathMerge = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path) + "_quant.csv"); using (FileStream ostrm = new FileStream(outputPathMerge, FileMode.OpenOrCreate, FileAccess.Write)) { using (StreamWriter writer = new StreamWriter(ostrm)) { writer.WriteLine("scan,time,GUI,glycan,mz,area"); foreach (string output in outputStringMerge) { writer.WriteLine(output); } writer.Flush(); } } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Console.WriteLine("RunTime " + elapsedTime); } }
public void Run(string path, Counter counter) { ISpectrumReader reader = new ThermoRawSpectrumReader(); reader.Init(path); IGUIFinder finder = new BinarySearchFinder(PPM); IProcess picking = new LocalNeighborPicking(); Dictionary <int, List <GUI> > pointMaps = new Dictionary <int, List <GUI> >(); int start = reader.GetFirstScan(); int end = reader.GetLastScan(); Parallel.For(start, end, (i) => { if (reader.GetMSnOrder(i) < 2) { ISpectrum spectrum = picking.Process(reader.GetSpectrum(i)); lock (resultLock) { pointMaps[i] = finder.FindGlucoseUnits(spectrum); } } counter.Add(end - start); }); List <List <GUI> > points = pointMaps.OrderBy(p => p.Key).Select(p => p.Value).ToList(); IGUISequencer sequencer = new DynamicProgrammingSequencer(); List <GUI> guiPoints = sequencer.Choose(points); Dictionary <int, GUI> guiSelected = new Dictionary <int, GUI>(); foreach (GUI gui in guiPoints) { if (guiSelected.ContainsKey(gui.Unit)) { if (guiSelected[gui.Unit].Peak.GetIntensity() < gui.Peak.GetIntensity()) { guiSelected[gui.Unit] = gui; } } else { guiSelected[gui.Unit] = gui; } } Retention.Clear(); Guis.Clear(); List <GUI> looped = guiSelected.Values.OrderBy(g => g.Scan).ToList(); string output = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path) + ".csv"); using (FileStream ostrm = new FileStream(output, FileMode.OpenOrCreate, FileAccess.Write)) { using (StreamWriter writer = new StreamWriter(ostrm)) { writer.WriteLine("scan,time,gui,peak,intensity"); foreach (GUI gui in looped) { int scan = gui.Scan; double time = reader.GetRetentionTime(scan); Retention.Add(time); Guis.Add(gui.Unit); writer.WriteLine(scan.ToString() + "," + time.ToString() + "," + gui.Unit.ToString() + "," + gui.Peak.GetMZ().ToString() + "," + gui.Peak.GetIntensity().ToString()); } writer.Flush(); } } Fitter.Fit(Retention, Guis); }
public void Run(string path, Counter counter, ISpectrumReader spectrumReader, NormalizerEngine normalizer) { NGlycanTheoryPeaksBuilder builder = new NGlycanTheoryPeaksBuilder(); builder.SetBuildType(true, false, false); List <IGlycanPeak> glycans = builder.Build(); spectrumReader.Init(path); IResultSelect resultSelect = new ResultMaxSelect(SearchingParameters.Access.Threshold, SearchingParameters.Access.PeakCutoff); List <IResult> final = new List <IResult>(); int start = spectrumReader.GetFirstScan(); int end = spectrumReader.GetLastScan(); Parallel.For(start, end, (i) => { if (spectrumReader.GetMSnOrder(i) < 2) { IResultFactory factory = new NGlycanResultFactory(); EnvelopeProcess envelopeProcess = new EnvelopeProcess( SearchingParameters.Access.Tolerance, SearchingParameters.Access.ToleranceBy); MonoisotopicSearcher monoisotopicSearcher = new MonoisotopicSearcher(factory); IProcess spectrumProcess = new LocalNeighborPicking(); ISpectrumSearch spectrumSearch = new NGlycanSpectrumSearch(glycans, spectrumProcess, envelopeProcess, monoisotopicSearcher, SearchingParameters.Access.MaxCharage, SearchingParameters.Access.Cutoff); ISpectrum spectrum = spectrumReader.GetSpectrum(i); List <IResult> results = spectrumSearch.Search(spectrum); lock (resultLock) { resultSelect.Add(results); final.AddRange(results); } } counter.Add(end - start); }); //original string outputPath = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path) + "_one_quant.csv"); List <string> outputString = new List <string>(); foreach (IResult present in final.OrderBy(r => r.GetRetention())) { int scan = present.GetScan(); double rt = present.GetRetention(); double index = Math.Round(normalizer.Normalize(rt), 2); TIQ3XIC xicer = new TIQ3XIC(spectrumReader); double area = xicer.OneArea(present); List <string> output; if (!normalizer.Initialized()) { output = new List <string>() { scan.ToString(), rt.ToString(), present.Glycan().GetGlycan().Name(), present.GetMZ().ToString(), area.ToString(), }; } else { output = new List <string>() { scan.ToString(), rt.ToString(), index > 0? index.ToString():"0", present.Glycan().GetGlycan().Name(), present.GetMZ().ToString(), area.ToString(), }; } outputString.Add(string.Join(",", output)); } using (FileStream ostrm = new FileStream(outputPath, FileMode.OpenOrCreate, FileAccess.Write)) { using (StreamWriter writer = new StreamWriter(ostrm)) { if (!normalizer.Initialized()) { writer.WriteLine("scan,time,glycan,mz,area"); } else { writer.WriteLine("scan,time,GUI,glycan,mz,area"); } foreach (string output in outputString) { writer.WriteLine(output); } writer.Flush(); } } // merged string outputPathMerge = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path) + "_quant.csv"); List <string> outputStringMerge = new List <string>(); Dictionary <string, List <SelectResult> > resultContainer = resultSelect.Produce(); foreach (string name in resultContainer.Keys) { List <SelectResult> selectResults = resultContainer[name]; foreach (SelectResult select in selectResults) { IResult present = select.Present; int scan = present.GetScan(); double rt = present.GetRetention(); double index = Math.Round(normalizer.Normalize(rt), 2); IXIC xicer = new TIQ3XIC(spectrumReader); double area = xicer.Area(select); List <string> output; if (!normalizer.Initialized()) { output = new List <string>() { scan.ToString(), rt.ToString(), name, present.GetMZ().ToString(), area.ToString(), }; } else { output = new List <string>() { scan.ToString(), rt.ToString(), index.ToString(), name, present.GetMZ().ToString(), area.ToString(), }; } outputStringMerge.Add(string.Join(",", output)); } } using (FileStream ostrm = new FileStream(outputPathMerge, FileMode.OpenOrCreate, FileAccess.Write)) { using (StreamWriter writer = new StreamWriter(ostrm)) { if (!normalizer.Initialized()) { writer.WriteLine("scan,time,glycan,mz,area"); } else { writer.WriteLine("scan,time,GUI,glycan,mz,area"); } foreach (string output in outputStringMerge) { writer.WriteLine(output); } writer.Flush(); } } }
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; } } }