private void RunTagBasedSearch(SortedSet <DatabaseSequenceSpectrumMatch>[] matches, FastaDatabase db, CancellationToken?cancellationToken = null, IProgress <ProgressData> progress = null) { _tagSearchEngine.SetDatabase(db); //var ms2ScanNums = _run.GetScanNumbers(2); var progData = new ProgressData(progress) { Status = "Tag-based Searching for matches" }; var sw = new Stopwatch(); long estimatedProteins = _tagMs2ScanNum.Length; Console.WriteLine(@"Number of spectra containing sequence tags: " + estimatedProteins); var numProteins = 0; var lastUpdate = DateTime.MinValue; // Force original update of 0% sw.Reset(); sw.Start(); var pfeOptions = new ParallelOptions { MaxDegreeOfParallelism = MaxNumThreads, CancellationToken = cancellationToken ?? CancellationToken.None }; Parallel.ForEach(_tagMs2ScanNum, pfeOptions, ms2ScanNum => { var tagSeqMatches = _tagSearchEngine.RunSearch(ms2ScanNum); foreach (var tagSequenceMatch in tagSeqMatches) { var offset = _tagSearchEngine.FastaDatabase.GetOffset(tagSequenceMatch.ProteinName); if (offset == null) { continue; } var sequence = tagSequenceMatch.Sequence; var numNTermCleavages = tagSequenceMatch.TagMatch.StartIndex; var seqObj = Sequence.CreateSequence(sequence, tagSequenceMatch.TagMatch.ModificationText, AminoAcidSet); var precursorIon = new Ion(seqObj.Composition + Composition.H2O, tagSequenceMatch.TagMatch.Charge); var prsm = new DatabaseSequenceSpectrumMatch(sequence, tagSequenceMatch.Pre, tagSequenceMatch.Post, ms2ScanNum, (long)offset, numNTermCleavages, tagSequenceMatch.TagMatch.Modifications, precursorIon, tagSequenceMatch.TagMatch.Score, db.IsDecoy) { ModificationText = tagSequenceMatch.TagMatch.ModificationText, }; AddMatch(matches, ms2ScanNum, prsm); } SearchProgressReport(ref numProteins, ref lastUpdate, estimatedProteins, sw, progData, "spectra"); }); Console.WriteLine(@"Collected candidate matches: {0}", GetNumberOfMatches(matches)); progData.StatusInternal = string.Empty; progData.Report(100.0); }