public void Run() { List <IPoint> points = new List <IPoint>(); for (int i = 0; i < 1200; i++) { points.Add(new MassPoint(i)); } var watch = new System.Diagnostics.Stopwatch(); watch.Start(); IComparer <IPoint> comparer = new ToleranceComparer(1.1); Console.WriteLine(comparer.Compare(new MassPoint(122), new MassPoint(123))); BinarySearch bins = new BinarySearch(comparer); bins.setData(points); List <IPoint> found = new List <IPoint>(); for (int j = 122; j < 123; j += 10) { found.AddRange(bins.Search(new MassPoint(j))); } //BucketSearch bucket = new BucketSearch(points, 1.1); //List<IPoint> result = bucket.Search(new MassPoint(3)); watch.Stop(); Console.WriteLine(found.Count); Console.WriteLine($"Execution Time: {watch.ElapsedMilliseconds} ms"); found.Clear(); watch = new System.Diagnostics.Stopwatch(); watch.Start(); //BinarySearch bins = new BinarySearch(points, 1.1); //List<IPoint> result = bins.Search(new MassPoint(3)); BucketSearch bucket = new BucketSearch(comparer, 1.1); bucket.setData(points); for (int j = 122; j < 123; j += 10) { found.AddRange(bucket.Search(new MassPoint(j))); } watch.Stop(); Console.WriteLine(found.Count); Console.WriteLine($"Execution Time: {watch.ElapsedMilliseconds} ms"); //foreach (IPoint p in result) //{ // Console.WriteLine(p.GetValue()); //} Console.ReadLine(); }
void Search() { List <SearchResult> tempResults = new List <SearchResult>(); List <SearchResult> tempDecoyResults = new List <SearchResult>(); ISearch <string> oneSearcher = new BucketSearch <string>( SearchingParameters.Access.MS1ToleranceBy, SearchingParameters.Access.MS1Tolerance); PrecursorMatch precursorMatcher = new PrecursorMatch(oneSearcher); precursorMatcher.Init(peptides, glycanBuilder.GlycanMaps()); ISearch <string> twoSearcher = new BucketSearch <string>( SearchingParameters.Access.MS1ToleranceBy, SearchingParameters.Access.MS1Tolerance); PrecursorMatch decoyPrecursorMatcher = new PrecursorMatch(twoSearcher); decoyPrecursorMatcher.Init(decoyPeptides, glycanBuilder.GlycanMaps()); ISearch <string> moreSearcher = new BucketSearch <string>( SearchingParameters.Access.MS2ToleranceBy, SearchingParameters.Access.MSMSTolerance); SequenceSearch sequenceSearcher = new SequenceSearch(moreSearcher); ISearch <int> extraSearcher = new BucketSearch <int>( SearchingParameters.Access.MS2ToleranceBy, SearchingParameters.Access.MSMSTolerance); GlycanSearch glycanSearcher = new GlycanSearch(extraSearcher, glycanBuilder.GlycanMaps(), SearchingParameters.Access.ComplexInclude, SearchingParameters.Access.HybridInclude, SearchingParameters.Access.MannoseInclude); SearchAnalyzer searchAnalyzer = new SearchAnalyzer(); SearchTask task; while ((task = TryGetTask()) != null) { ISpectrum spectrum = task.Spectrum; //precursor match var pre_results = precursorMatcher.Match(task.PrecursorMZ, task.Charge); if (pre_results.Count > 0) { // spectrum search var peptide_results = sequenceSearcher.Search(spectrum.GetPeaks(), task.Charge, pre_results); if (peptide_results.Count > 0) { var glycan_results = glycanSearcher.Search(spectrum.GetPeaks(), task.Charge, pre_results); if (glycan_results.Count > 0) { var targets = searchAnalyzer.Analyze(spectrum.GetScanNum(), spectrum.GetPeaks(), peptide_results, glycan_results); targets = searchAnalyzer.Filter(targets, glycanBuilder.GlycanMaps(), task.PrecursorMZ, task.Charge); tempResults.AddRange(targets); } } } var decoy_results = decoyPrecursorMatcher.Match(task.PrecursorMZ, task.Charge); if (decoy_results.Count > 0) { // spectrum search var peptide_results = sequenceSearcher.Search(spectrum.GetPeaks(), task.Charge, decoy_results); if (peptide_results.Count > 0) { var glycan_results = glycanSearcher.Search(spectrum.GetPeaks(), task.Charge, decoy_results); if (glycan_results.Count > 0) { var decoys = searchAnalyzer.Analyze(spectrum.GetScanNum(), spectrum.GetPeaks(), peptide_results, glycan_results); decoys = searchAnalyzer.Filter(decoys, glycanBuilder.GlycanMaps(), task.PrecursorMZ, task.Charge); tempDecoyResults.AddRange(decoys); } } } searchCounter.Add(taskSize); } UpdateTask(tempResults, tempDecoyResults); }
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 Run() { var watch = new System.Diagnostics.Stopwatch(); watch.Start(); // protein IProteinDataBuilder proteinBuilder = new GeneralFastaDataBuilder(); IProteinCreator proteinCreator = new GeneralProteinCreator(proteinBuilder); List <IProtein> proteins = proteinCreator.Create(@"C:\Users\iruiz\Desktop\app\HP.fasta"); // peptides List <IPeptideSequencesGenerator> generatorList = new List <IPeptideSequencesGenerator>(); IPeptideSequencesGeneratorParameter parameter = new GeneralPeptideGeneratorParameter(); parameter.SetProtease(Proteases.GluC); NGlycosylatedPeptideSequencesGenerator generatorGluc = new NGlycosylatedPeptideSequencesGenerator(parameter); generatorList.Add(generatorGluc); parameter = new GeneralPeptideGeneratorParameter(); parameter.SetProtease(Proteases.Trypsin); NGlycosylatedPeptideSequencesGenerator generatorTrypsin = new NGlycosylatedPeptideSequencesGenerator(parameter); generatorList.Add(generatorTrypsin); IPeptideSequencesGenerator peptideSequencesGenerator = new DoubleDigestionPeptideSequencesGeneratorProxy(generatorList); IPeptideCreator peptideCreator = new GeneralPeptideCreator(peptideSequencesGenerator); List <IPeptide> peptides = new List <IPeptide>(); HashSet <string> seen = new HashSet <string>(); foreach (IProtein protein in proteins) { foreach (IPeptide peptide in peptideCreator.Create(protein)) { if (!seen.Contains(peptide.GetSequence())) { seen.Add(peptide.GetSequence()); peptides.Add(peptide); } } } // glycans ITableNGlycanProxyGenerator tableNGlycanProxyGenerator = new GeneralTableNGlycanMassProxyGenerator(12, 12, 5, 4, 0); int[] structTable = new int[24]; structTable[0] = 1; ITableNGlycanProxy root = new GeneralTableNGlycanMassProxy(new ComplexNGlycan(structTable)); IGlycanCreator glycanCreator = new GeneralTableNGlycanCreator(tableNGlycanProxyGenerator, root); List <IGlycan> glycans = glycanCreator.Create(); // precursor List <IPoint> points = new List <IPoint>(); foreach (IGlycan glycan in glycans) { points.Add(new GlycanPoint(glycan)); } IComparer <IPoint> comparer = new ToleranceComparer(0.01); ISearch matcher = new BucketSearch(comparer, 0.01); matcher.setData(points); IGlycoPeptideProxyGenerator glycoPeptideProxyGenerator = new GeneralTableNGlycoPeptideMassProxyGenerator(); IGlycoPeptideCreator glycoPeptideCreator = new GeneralNGlycoPeptideSingleSiteCreator(glycoPeptideProxyGenerator); IPrecursorMatcher precursorMatcher = new GeneralPrecursorMatcher(matcher, glycoPeptideCreator); precursorMatcher.SetGlycans(glycans); precursorMatcher.SetPeptides(peptides); // spectrum ISpectrumReader spectrumReader = new ThermoRawSpectrumReader(); spectrumReader.Init(@"C:\Users\iruiz\Desktop\app\ZC_20171218_H95_R1.raw"); ISpectrumFactory spectrumFactory = new GeneralSpectrumFactory(spectrumReader); ISpectrum spectrum = spectrumFactory.GetSpectrum(7039); List <IGlycoPeptide> glycoPeptides = precursorMatcher.Match(spectrum); watch.Stop(); Console.WriteLine(glycoPeptides.Count); foreach (IGlycoPeptide glycoPeptide in glycoPeptides) { Console.WriteLine(glycoPeptide.GetType()); } Console.WriteLine($"Execution Time: {watch.ElapsedMilliseconds} ms"); Console.Read(); }