public ReadPair TryPair(BamAlignment alignment)
        {
            if (_readsProcessed % 100000 == 0)
            {
                LogStatus(alignment.RefID + ":" + alignment.Position);
            }

            _readsProcessed++;

            LastRefId = alignment.RefID;

            var readIndexer = ReadIndexer(alignment);

            // Check if this read should be blacklisted
            if (ShouldBlacklistReadIndexer(alignment))
            {
                _blacklistedReads.Add(readIndexer);
            }

            // If this read is in the blacklist, or is a read that should be "aggressively" skipped, skip the read. If we've already started tracking a mate, remove it from the mate lookup.
            if (ShouldSkipAndRemoveWaitingMates(alignment) || _blacklistedReads.Contains(readIndexer))
            {
                _readsAggressivelySkipped++;

                if (_readsWaitingForMate.ContainsKey(readIndexer))
                {
                    _readsWaitingForMate.Remove(readIndexer);
                }
                return(null);
            }

            if (ShouldSkipRead(alignment))
            {
                _readsSkipped++;
                return(null);
            }

            if (!_readsWaitingForMate.ContainsKey(readIndexer))
            {
                // TODO do we really need to create a new copy here? I think we're already doing it later
                _readsWaitingForMate.Add(readIndexer, new ReadPair(new BamAlignment(alignment), readIndexer, GetReadNumber(alignment)));
                return(null);
            }
            else
            {
                var readPair = _readsWaitingForMate[readIndexer];
                readPair.AddAlignment(alignment, GetReadNumber(alignment));

                if (!readPair.IsComplete(_requireSupplementaries) || _pairEvaluator.TreatReadPairAsIncomplete(readPair))
                {
                    return(null);
                }

                _pairsProcessed++;

                // Check pair and either skip or return pair
                var shouldSkip = ShouldSkipPair(readPair);

                if (!shouldSkip || _removeFailedPairs)
                {
                    _readsWaitingForMate.Remove(readIndexer); // If succeeded, no longer waiting for mate; if failed and we're being strict on failures, remove
                }
                if (ShouldWhitelistReadIndexer(alignment, shouldSkip))
                {
                    _whitelistedReads.Add(readIndexer);
                }

                if (shouldSkip)
                {
                    _pairsSkipped++;
                }
                else
                {
                    _pairsPaired++;
                }

                return(shouldSkip ? null : readPair);
            }
        }
Esempio n. 2
0
        public ReadPair TryPair(BamAlignment alignment)
        {
            if (_readsProcessed % 100000 == 0)
            {
                OnLog(string.Format("At {6}:{7}. Processed {0} reads and {4} pairs so far. {1} skipped, {2} pairs skipped, {5} pairs paired, {3} currently waiting for mate",
                                    _readsProcessed, _readsSkipped, _pairsSkipped, _readsWaitingForMate.Keys.Count, _pairsProcessed, _pairsPaired, alignment.RefID, alignment.Position));
            }

            _readsProcessed++;

            LastRefId = alignment.RefID;

            // Check if this read should be blacklisted
            if (ShouldBlacklistReadIndexer(alignment))
            {
                _blacklistedReads.Add(ReadIndexer(alignment));
            }

            // If this read is in the blacklist, skip the read. If we've already started tracking a mate, remove it from the mate lookup.
            if (_blacklistedReads.Contains(ReadIndexer(alignment)))
            {
                _readsSkipped++;
                if (_readsWaitingForMate.ContainsKey(ReadIndexer(alignment)))
                {
                    _readsWaitingForMate.Remove(ReadIndexer(alignment));
                }
                return(null);
            }

            if (ShouldSkipRead(alignment))
            {
                _readsSkipped++;
                return(null);
            }

            if (!_readsWaitingForMate.ContainsKey(ReadIndexer(alignment)))
            {
                _readsWaitingForMate.Add(ReadIndexer(alignment), new ReadPair(new BamAlignment(alignment), ReadIndexer(alignment), GetReadNumber(alignment)));
                return(null);
            }
            else
            {
                var readPair = _readsWaitingForMate[ReadIndexer(alignment)];
                readPair.AddAlignment(alignment, GetReadNumber(alignment));

                if (!readPair.IsComplete() || _pairEvaluator.TreatReadPairAsIncomplete(readPair))
                {
                    return(null);
                }

                _pairsProcessed++;

                // Check pair and either skip or return pair
                var shouldSkip = ShouldSkipPair(readPair);

                if (!shouldSkip || _removeFailedPairs)
                {
                    _readsWaitingForMate.Remove(ReadIndexer(alignment)); // If succeeded, no longer waiting for mate; if failed and we're being strict on failures, remove
                }
                if (ShouldWhitelistReadIndexer(alignment, shouldSkip))
                {
                    _whitelistedReads.Add(ReadIndexer(alignment));
                }

                if (shouldSkip)
                {
                    _pairsSkipped++;
                }
                else
                {
                    _pairsPaired++;
                }

                return(shouldSkip ? null : readPair);
            }
        }