示例#1
0
        public virtual IChrRealigner CreateRealigner(ChrReference chrReference, string bamFilePath, IRealignmentWriter writer)
        {
            var knownIndels = _knownVariants == null || !_knownVariants.ContainsKey(chrReference.Name) ?
                              null : _knownVariants[chrReference.Name];

            AlignmentScorer alignmentScorer = null;

            if (_options.UseAlignmentScorer)
            {
                alignmentScorer = new AlignmentScorer()
                {
                    AnchorLengthCoefficient = _options.AnchorLengthCoefficient,
                    MismatchCoefficient     = _options.MismatchCoefficient,
                    IndelCoefficient        = _options.IndelCoefficient,
                    NonNSoftclipCoefficient = _options.SoftclipCoefficient,
                    IndelLengthCoefficient  = _options.IndelLengthCoefficient
                };
            }

            return(new ChrRealigner(chrReference,
                                    CreateAlignmentExtractor(bamFilePath, chrReference.Name),
                                    CreateAlignmentExtractor(bamFilePath, chrReference.Name),
                                    CreateCandidateFinder(),
                                    CreateRanker(),
                                    CreateCaller(),
                                    new RealignStateManager(_options.MinimumBaseCallQuality, _options.RealignWindowSize),
                                    writer,
                                    knownIndels,
                                    _options.MaxIndelSize,
                                    _options.TryThree,
                                    skipDuplicates: _options.SkipDuplicates,
                                    skipAndRemoveDuplicates: _options.SkipAndRemoveDuplicates,
                                    remaskSoftclips: _options.RemaskSoftclips, maskPartialInsertion: _options.MaskPartialInsertion, minimumUnanchoredInsertionLength: _options.MinimumUnanchoredInsertionLength, allowRescoringOrig0: _options.AllowRescoringOrigZero,
                                    maxRealignShift: _options.MaxRealignShift,
                                    tryRealignCleanSoftclippedReads: _options.TryRealignSoftclippedReads,
                                    alignmentScorer: alignmentScorer,
                                    debug: _options.Debug

                                    ));
        }
示例#2
0
        public ChrRealigner(ChrReference chrReference, IAlignmentExtractor extractorForCandidates,
                            IAlignmentExtractor extractorForRealign, IIndelCandidateFinder indelFinder, IIndelRanker indelRanker,
                            ITargetCaller caller, RealignStateManager stateManager, IRealignmentWriter writer,
                            List <CandidateAllele> knownIndels   = null, int maxIndelSize         = 25, bool tryThree                   = false,
                            int anchorSizeThreshold              = 10, bool skipDuplicates        = false, bool skipAndRemoveDuplicates = false, bool remaskSoftclips = true, bool maskPartialInsertion = false, int minimumUnanchoredInsertionLength = 0,
                            bool tryRealignCleanSoftclippedReads = true, bool allowRescoringOrig0 = true, int maxRealignShift           = 250, AlignmentScorer alignmentScorer = null, bool debug       = false)
        {
            _chrReference           = chrReference;
            _extractorForCandidates = extractorForCandidates;
            _extractorForRealign    = extractorForRealign;
            _indelFinder            = indelFinder;
            _indelRanker            = indelRanker;
            _caller                          = caller;
            _stateManager                    = stateManager;
            _writer                          = writer;
            _knownIndels                     = knownIndels == null ? null : knownIndels.Select(i => new CandidateIndel(i)).ToList();
            _maxIndelSize                    = maxIndelSize;
            _anchorSizeThreshold             = anchorSizeThreshold;
            _skipDuplicates                  = skipDuplicates;
            _skipAndRemoveDuplicates         = skipAndRemoveDuplicates;
            _allowRescoringOrig0             = allowRescoringOrig0;
            _maxRealignShift                 = maxRealignShift;
            _tryRealignCleanSoftclippedReads = tryRealignCleanSoftclippedReads;
            _alignmentScorer                 = alignmentScorer;
            _debug = debug;

            if (alignmentScorer != null)
            {
                _alignmentComparer = new ScoredAlignmentComparer(alignmentScorer);
            }
            else
            {
                _alignmentComparer = new BasicAlignmentComparer();
            }

            _readRealigner = new ReadRealigner(_alignmentComparer, tryThree, remaskSoftclips, maskPartialInsertion, minimumUnanchoredInsertionLength);
        }
        public void AlignmentScorer()
        {
            var scorer = new AlignmentScorer();

            var perfect  = new AlignmentSummary();
            var oneIndel = new AlignmentSummary()
            {
                NumIndels = 1
            };
            var twoIndels = new AlignmentSummary()
            {
                NumIndels = 2,
            };
            var oneMismatch = new AlignmentSummary()
            {
                NumMismatches = 1
            };
            var twoMismatches = new AlignmentSummary()
            {
                NumMismatches = 2,
            };
            var oneIndelOneMismatch = new AlignmentSummary()
            {
                NumIndels     = 1,
                NumMismatches = 1
            };
            var everything = new AlignmentSummary()
            {
                NumIndels        = 1,
                NumMismatches    = 1,
                NumIndelBases    = 1,
                NumNonNSoftclips = 1,
                AnchorLength     = 1
            };

            // By default, everything is 0
            Assert.Equal(0, scorer.GetAlignmentScore(perfect));
            Assert.Equal(0, scorer.GetAlignmentScore(oneIndel));
            Assert.Equal(0, scorer.GetAlignmentScore(twoIndels));
            Assert.Equal(0, scorer.GetAlignmentScore(oneIndelOneMismatch));

            // Count against mismatches: -1 score for each
            scorer = new AlignmentScorer()
            {
                MismatchCoefficient = -1
            };
            Assert.Equal(-1, scorer.GetAlignmentScore(oneMismatch));
            Assert.Equal(-1, scorer.GetAlignmentScore(oneIndelOneMismatch));
            Assert.Equal(-2, scorer.GetAlignmentScore(twoMismatches));
            Assert.Equal(0, scorer.GetAlignmentScore(oneIndel));
            Assert.Equal(0, scorer.GetAlignmentScore(twoIndels));

            // Count against indels: -1 score for each
            scorer = new AlignmentScorer()
            {
                IndelCoefficient = -1
            };
            Assert.Equal(0, scorer.GetAlignmentScore(oneMismatch));
            Assert.Equal(-1, scorer.GetAlignmentScore(oneIndelOneMismatch));
            Assert.Equal(0, scorer.GetAlignmentScore(twoMismatches));
            Assert.Equal(-1, scorer.GetAlignmentScore(oneIndel));
            Assert.Equal(-2, scorer.GetAlignmentScore(twoIndels));

            // Count against indels and mismatches
            scorer = new AlignmentScorer()
            {
                IndelCoefficient = -3, MismatchCoefficient = -1
            };
            Assert.Equal(-1, scorer.GetAlignmentScore(oneMismatch));
            Assert.Equal(-4, scorer.GetAlignmentScore(oneIndelOneMismatch));
            Assert.Equal(-2, scorer.GetAlignmentScore(twoMismatches));
            Assert.Equal(-3, scorer.GetAlignmentScore(oneIndel));
            Assert.Equal(-6, scorer.GetAlignmentScore(twoIndels));

            // Make sure the other stuff is working
            scorer = new AlignmentScorer()
            {
                IndelLengthCoefficient = 1
            };
            Assert.Equal(1, scorer.GetAlignmentScore(everything));
            scorer.IndelCoefficient = 1;
            Assert.Equal(2, scorer.GetAlignmentScore(everything));
            scorer.MismatchCoefficient = 1;
            Assert.Equal(3, scorer.GetAlignmentScore(everything));
            scorer.NonNSoftclipCoefficient = 1;
            Assert.Equal(4, scorer.GetAlignmentScore(everything));
            scorer.AnchorLengthCoefficient = 1;
            Assert.Equal(5, scorer.GetAlignmentScore(everything));
        }