Пример #1
0
        public void TryReStitch_RealCases()
        {
            var read1 = TestHelpers.CreateRead("chr1", "AGCAGCAGCAGCTCCAGCACCAGCAGTCCCAGCACCAGCAGGCCCCGAAGAAGCATACCCAGCAGCAGAAGACACCTCAGCAGCTGCACCAGGTGATCGG", 14106298,
                                               new CigarAlignment("41M59S"));

            var read2 = TestHelpers.CreateRead("chr1", "GCGATCTATCAGTATTAGCTCCAGCATCAGCAGCCCGAGCATCTGCAGTTCTAGCAGCAGCAGTCCCAGCAGCAGCAGTCCCAGCAGCAGCTGCCCCAGT", 14106328,
                                               new CigarAlignment("52S48M"));

            var stitcher = new BasicStitcher(20, false,
                                             true, debug: false, nifyUnstitchablePairs: true, ignoreProbeSoftclips: true, maxReadLength: 1024, ignoreReadsAboveMaxLength: false, thresholdNumDisagreeingBases: 1000);

            var stitchedPairHandler = new PairHandler(new Dictionary <int, string>()
            {
                { 1, "chr1" }
            }, stitcher, tryStitch: true);
            var restitcher = new PostRealignmentStitcher(stitchedPairHandler, new Mock <IStatusHandler>().Object);

            var pair = new ReadPair(read1.BamAlignment);

            pair.AddAlignment(read2.BamAlignment);

            var mockNmCalculator = new Mock <INmCalculator>();
            var reads            = restitcher.GetRestitchedReads(pair, pair.Read1, pair.Read2, 1, 1, false, mockNmCalculator.Object, false);

            Assert.Equal(1.0, reads.Count);
            Assert.Equal("22S78M22S", reads.First().CigarData.ToString());
        }
Пример #2
0
        public void TestHomoPolymerScenario(Read read1, Read read2, Read mergedRead, bool useSoftClippedBases, bool expectedResult)
        {
            var alignmentSet  = new AlignmentSet(read1, read2);
            var basicStitcher = new BasicStitcher(10, useSoftclippedBases: useSoftClippedBases);

            Assert.Equal(expectedResult, basicStitcher.TryStitch(alignmentSet));
            //Assert.Equal(expectedResult, OverlapEvaluator.BridgeAnchored(mergedRead));
        }
Пример #3
0
        private PairHandler GetPairHandler(Dictionary <int, string> refIdMapping)
        {
            var stitcher = new BasicStitcher(_stitcherOptions.MinBaseCallQuality, useSoftclippedBases: _stitcherOptions.UseSoftClippedBases,
                                             nifyDisagreements: _stitcherOptions.NifyDisagreements, debug: _stitcherOptions.Debug,
                                             nifyUnstitchablePairs: _stitcherOptions.NifyUnstitchablePairs, ignoreProbeSoftclips: !_stitcherOptions.StitchProbeSoftclips,
                                             maxReadLength: _stitcherOptions.MaxReadLength, ignoreReadsAboveMaxLength: _stitcherOptions.IgnoreReadsAboveMaxLength,
                                             thresholdNumDisagreeingBases: _stitcherOptions.MaxNumDisagreeingBases, dontStitchHomopolymerBridge: _stitcherOptions.DontStitchHomopolymerBridge, minMapQuality: _stitcherOptions.FilterMinMapQuality, countNsTowardNumDisagreeingBases: _stitcherOptions.CountNsTowardDisagreeingBases);

            return(new PairHandler(refIdMapping, stitcher, tryStitch: !_geminiOptions.SkipStitching));
        }
        private BasicStitcher GetStitcher()
        {
            var stitcher = new BasicStitcher(_stitcherOptions.MinBaseCallQuality,
                                             useSoftclippedBases: false,
                                             nifyDisagreements: _stitcherOptions.NifyDisagreements, debug: _stitcherOptions.Debug,
                                             nifyUnstitchablePairs: _stitcherOptions.NifyUnstitchablePairs,
                                             ignoreProbeSoftclips: !_stitcherOptions.StitchProbeSoftclips, maxReadLength: _stitcherOptions.MaxReadLength,
                                             ignoreReadsAboveMaxLength: _stitcherOptions.IgnoreReadsAboveMaxLength,
                                             thresholdNumDisagreeingBases: _stitcherOptions.MaxNumDisagreeingBases, minMapQuality: _stitcherOptions.FilterMinMapQuality, dontStitchHomopolymerBridge: _stitcherOptions.DontStitchHomopolymerBridge, countNsTowardNumDisagreeingBases: _stitcherOptions.CountNsTowardDisagreeingBases);

            return(stitcher);
        }
Пример #5
0
        private ISomaticVariantCaller CreateMockVariantCaller(VcfFileWriter vcfWriter, ApplicationOptions options, ChrReference chrRef, MockAlignmentExtractor mae, IStrandBiasFileWriter biasFileWriter = null, string intervalFilePath = null)
        {
            var config = new AlignmentSourceConfig
            {
                MinimumMapQuality  = options.MinimumMapQuality,
                OnlyUseProperPairs = options.OnlyUseProperPairs,
            };

            IAlignmentStitcher stitcher = null;

            if (options.StitchReads)
            {
                if (options.UseXCStitcher)
                {
                    stitcher = new XCStitcher(options.MinimumBaseCallQuality);
                }
                else
                {
                    stitcher = new BasicStitcher(options.MinimumBaseCallQuality);
                }
            }

            var mateFinder      = options.StitchReads ? new AlignmentMateFinder(MAX_FRAGMENT_SIZE) : null;
            var RegionPadder    = new RegionPadder(chrRef, null);
            var alignmentSource = new AlignmentSource(mae, mateFinder, stitcher, config);
            var variantFinder   = new CandidateVariantFinder(options.MinimumBaseCallQuality, options.MaxSizeMNV, options.MaxGapBetweenMNV, options.CallMNVs);
            var alleleCaller    = new AlleleCaller(new VariantCallerConfig
            {
                IncludeReferenceCalls        = options.OutputgVCFFiles,
                MinVariantQscore             = options.MinimumVariantQScore,
                MaxVariantQscore             = options.MaximumVariantQScore,
                VariantQscoreFilterThreshold = options.FilteredVariantQScore > options.MinimumVariantQScore ? options.FilteredVariantQScore : (int?)null,
                MinCoverage                = options.MinimumCoverage,
                MinFrequency               = options.MinimumFrequency,
                EstimatedBaseCallQuality   = options.AppliedNoiseLevel == -1 ? options.MinimumBaseCallQuality : options.AppliedNoiseLevel,
                StrandBiasModel            = options.StrandBiasModel,
                StrandBiasFilterThreshold  = options.StrandBiasAcceptanceCriteria,
                FilterSingleStrandVariants = options.FilterOutVariantsPresentOnlyOneStrand,
                GenotypeModel              = options.GTModel
            });
            var stateManager = new RegionStateManager();

            return(new SomaticVariantCaller(
                       alignmentSource,
                       variantFinder,
                       alleleCaller,
                       vcfWriter,
                       stateManager,
                       chrRef,
                       RegionPadder,
                       biasFileWriter));
        }
Пример #6
0
        private void TestMerge(int pos1, string cigar1, int pos2, string cigar2, int posStitch = 0, string cigarStitch = "", string stitchDirections = "", bool shouldMerge = true, bool ignoreProbeSoftclips = true, int?maxReadLength = null)
        {
            var r1Bases = new string('A', (int)new CigarAlignment(cigar1).GetReadSpan());
            var r2Bases = new string('A', (int)new CigarAlignment(cigar2).GetReadSpan());
            var read1   = DomainTestHelper.CreateRead("chr1", r1Bases, pos1,
                                                      new CigarAlignment(cigar1));

            var read2 = DomainTestHelper.CreateRead("chr1", r2Bases, pos2,
                                                    new CigarAlignment(cigar2));

            StitcherTestHelpers.SetReadDirections(read2, DirectionType.Reverse);

            BasicStitcher stitcher;

            if (maxReadLength != null)
            {
                stitcher = new BasicStitcher(10, ignoreProbeSoftclips: ignoreProbeSoftclips,
                                             maxReadLength: maxReadLength.Value);
            }
            else
            {
                // Use the default
                stitcher = new BasicStitcher(10, ignoreProbeSoftclips: ignoreProbeSoftclips);
            }

            if (!shouldMerge)
            {
                var alignmentSet = new AlignmentSet(read1, read2);
                Assert.False(stitcher.TryStitch(alignmentSet));

                //StitcherTestHelpers.TestUnstitchableReads(read1, read2, 0, null);
            }
            else
            {
                var alignmentSet = new AlignmentSet(read1, read2);
                var didStitch    = stitcher.TryStitch(alignmentSet);
                Assert.True(didStitch);

                var mergedRead = StitcherTestHelpers.GetMergedRead(alignmentSet);
                Console.WriteLine(mergedRead.Position + " " + mergedRead.CigarData);
                Console.WriteLine("---------------");
                if (cigarStitch != "")
                {
                    Assert.Equal(posStitch, mergedRead.Position);
                    Assert.Equal(cigarStitch, mergedRead.CigarData.ToString());
                }
                if (stitchDirections != "")
                {
                    Assert.Equal(stitchDirections, mergedRead.CigarDirections.ToString());
                }
            }
        }
Пример #7
0
        private BaseStitcher.OverlapBoundary ExecuteOverlapTest(int read1Position, string read1Cigar, int read2Position, string read2Cigar)
        {
            var read1CigarAlignment = new CigarAlignment(read1Cigar);
            var read1 = TestHelper.CreateRead("chr1",
                                              string.Join(string.Empty, Enumerable.Repeat("A", (int)read1CigarAlignment.GetReadSpan())), read1Position,
                                              read1CigarAlignment);

            var read2CigarAlignment = new CigarAlignment(read2Cigar);
            var read2 = TestHelper.CreateRead("chr1",
                                              string.Join(string.Empty, Enumerable.Repeat("A", (int)read2CigarAlignment.GetReadSpan())), read2Position,
                                              read2CigarAlignment);

            var stitcher = new BasicStitcher(10);

            return(stitcher.GetOverlapBoundary(read1, read2));
        }
Пример #8
0
        private IReadPairHandler CreatePairHandler(ReadStatusCounter readStatuses)
        {
            var stitcher = new BasicStitcher(_options.MinBaseCallQuality, useSoftclippedBases: _options.UseSoftClippedBases,
                                             nifyDisagreements: _options.NifyDisagreements, debug: _options.Debug, nifyUnstitchablePairs: _options.NifyUnstitchablePairs, ignoreProbeSoftclips: !_options.StitchProbeSoftclips, maxReadLength: _options.MaxReadLength);

            var refIdMapping = new Dictionary <int, string>();

            using (var reader = new BamReader(_inBam))
            {
                foreach (var referenceName in reader.GetReferenceNames())
                {
                    refIdMapping.Add(reader.GetReferenceIndex(referenceName), referenceName);
                }
            }
            return(new PairHandler(refIdMapping, stitcher, _options.FilterUnstitchablePairs, readStatuses));
        }
Пример #9
0
        public void RunStitchingScenarios(StitchingScenario scenario, string resultFile)
        {
            Console.WriteLine(scenario.Category + " " + scenario.Id);

            bool resultLogged = false;

            try
            {
                var stitcher = new BasicStitcher(10);

                var inputRead1 = scenario.InputRead1.ToRead();
                var inputRead2 = scenario.InputRead2.ToRead();

                var alignmentSet = new AlignmentSet(inputRead1, inputRead2);
                var didStitch    = stitcher.TryStitch(alignmentSet);

                LogResult(resultFile, scenario, didStitch, alignmentSet);
                resultLogged = true;


                if (scenario.ShouldStitch)
                {
                    Assert.Equal(scenario.ShouldStitch, didStitch);
                    Assert.True(OutputDirectionsMatch(scenario, alignmentSet));
                    Assert.True(OutputCigarsMatch(scenario, alignmentSet));
                }

                if (didStitch)
                {
                    // TODO fix scenario source files so we can turn this back on.
                    Assert.True(OutputCigarsMatch(scenario, alignmentSet));
                }
            }
            catch (Exception ex)
            {
                if (!resultLogged)
                {
                    LogResult(resultFile, scenario, false, null, message: "Threw exception: " + ex.Message);
                }
                throw;
            }
        }
Пример #10
0
        private List <IReadPairHandler> CreatePairHandlers(ReadStatusCounter readStatuses, int numThreads)
        {
            var handlers = new List <IReadPairHandler>(numThreads);

            var refIdMapping = new Dictionary <int, string>();

            using (var reader = new BamReader(_inBam))
            {
                foreach (var referenceName in reader.GetReferenceNames())
                {
                    refIdMapping.Add(reader.GetReferenceIndex(referenceName), referenceName);
                }
            }

            for (int i = 0; i < numThreads; ++i)
            {
                var stitcher = new BasicStitcher(_options.MinBaseCallQuality, useSoftclippedBases: _options.UseSoftClippedBases,
                                                 nifyDisagreements: _options.NifyDisagreements, debug: _options.Debug, nifyUnstitchablePairs: _options.NifyUnstitchablePairs, ignoreProbeSoftclips: !_options.StitchProbeSoftclips, maxReadLength: _options.MaxReadLength, ignoreReadsAboveMaxLength: _options.IgnoreReadsAboveMaxLength, minMapQuality: _options.FilterMinMapQuality, dontStitchHomopolymerBridge: _options.DontStitchHomopolymerBridge);

                handlers.Add(new PairHandler(refIdMapping, stitcher, readStatuses, _options.FilterUnstitchablePairs, true));
            }

            return(handlers);
        }
Пример #11
0
        public void TryStitch_RealExamples()
        {
            // Real example from Kristina's problematic variant #73
            var read1Bases =
                "GAAGCCACACTGACGTGCCTCTCCCTCCCTCCAGGAAGCCTTCCAGGAAGCCTACGTGATGGCCAGCGTGGACAACCCCCACGTGTGCCGCCTGCTGGGCATCTGCCTCACCTCCACCGTGCAGCTCATCACGCAGCTCATGCCCTTCGG";
            var read2Bases =
                "AGGAAGCCTTCCAGGAAGCCTACGTGATGGCCAGCGTGGACAACCCCCACGTGTGCCGCCTGCTGGGCATCTGCCTCACCTCCACCGTGCAGCTCATCACGCAGCTCATGCCCTTCGGCTGCCTCCTGGACTATGTCCGGGAACACAAAG";

            var read1 = DomainTestHelper.CreateRead("chr7", read1Bases, 55248972, new CigarAlignment("20S9M12I109M"));
            var read2 = DomainTestHelper.CreateRead("chr7", read2Bases, 55248981, new CigarAlignment("9S120M21S"));

            StitcherTestHelpers.SetReadDirections(read2, DirectionType.Reverse);

            var stitcher     = new BasicStitcher(10, useSoftclippedBases: false);
            var alignmentSet = new AlignmentSet(read1, read2);

            stitcher.TryStitch(alignmentSet);
            var mergedRead = StitcherTestHelpers.GetMergedRead(alignmentSet);

            Assert.Equal("20S9M12I120M21S", mergedRead.CigarData.ToString());
            Assert.Equal("41F109S32R", mergedRead.CigarDirections.ToString());

            // Shouldn't stitch - problem Yu was having (tried to merge and then said the base at position 158 is null).
            read1Bases =
                "CGACGCTCTTGCGATCTTCAAAGCAATAGGATGGGTGATCAGGGATGTTGCTTACAAGAAAAGAACTGCCATACAGCTTCAACAACAACTTCTTCCACCCACCCCTAAAATGATGCTAAAAAGTAAGTCATCTCTGGTTCTCCCCCGATT";
            read2Bases =
                "TCAAAGCAATAGGATGGATGATCAGAGATGTTGCTTACAAGAAAAGAACTGCCATACAGCTTCAACAACAACTTCTTCCACTCCCCCCTAAAGTGATGCTAAAAAGTAAATCATCCCTGTTTCTCCCCCGTTCGCGAATTTCTACGATCG";

            read1 = DomainTestHelper.CreateRead("chr7", read1Bases, 109465121, new CigarAlignment("44S56M1I23M26S"));
            read2 = DomainTestHelper.CreateRead("chr7", read2Bases, 109465121, new CigarAlignment("27S55M1I24M43S"));
            StitcherTestHelpers.SetReadDirections(read2, DirectionType.Reverse);

            stitcher     = new BasicStitcher(10, useSoftclippedBases: true);
            alignmentSet = new AlignmentSet(read1, read2);
            Assert.False(stitcher.TryStitch(alignmentSet));
        }
Пример #12
0
        public void TryStitch_ReCo()
        {
            // Real example from ReCo, was failing to generate the correct stitched cigar
            var read1Bases =
                "GTACTCCTACAGTCCCACCCCTCCCCTATAAACCTTATGAATCCCCGTTCACTTAGATGCCAGCTTGGCAAGGAAGGGAAGTACACATCTGTTGACAGTAATGAAATATCCTTGATAAGGATTTAAATTTTGGATGTGCTG";
            var read2Bases =
                "ACCTACAGTCCCACCCCTCCCCTATAAACCTTAGGAATCCCCGTTCACTTAGATGCCAGCTTGGCAAGGAAGGGAAGTACACATCTGTTGACAGTAATGAAATATCCTTGATAAGGATTTAAATTTTGGATGTGCTGAGCT";

            // 8             9
            // 3 4 5 6 7 8 9 0 1 2
            // s s s s s M M M M M ...
            // - - - - M M M M M M ...
            // F F F F R S S S S S ... // Stitched directions if we don't allow softclip to contribute
            // F F F F S S S S S S ... // Stitched directions if we do allow softclip to contribute

            var read1 = DomainTestHelper.CreateRead("chr21", read1Bases, 16685488,
                                                    new CigarAlignment("5S136M"));

            var read2 = DomainTestHelper.CreateRead("chr21", read2Bases, 16685487,
                                                    new CigarAlignment("137M4S"));

            StitcherTestHelpers.SetReadDirections(read2, DirectionType.Reverse);

            var stitcher     = new BasicStitcher(10, useSoftclippedBases: false);
            var alignmentSet = new AlignmentSet(read1, read2);

            stitcher.TryStitch(alignmentSet);
            // Without allowing softclips to count to support, should still get a M at an M/S overlap, but it won't be stitched.
            var mergedRead = StitcherTestHelpers.GetMergedRead(alignmentSet);

            Assert.Equal("4S137M4S", mergedRead.CigarData.ToString());
            var expectedDirections = StitcherTestHelpers.BuildDirectionMap(new List <IEnumerable <DirectionType> >
            {
                StitcherTestHelpers.BuildDirectionSegment(DirectionType.Forward, 4),
                StitcherTestHelpers.BuildDirectionSegment(DirectionType.Reverse, 1),
                StitcherTestHelpers.BuildDirectionSegment(DirectionType.Stitched, 136),
                StitcherTestHelpers.BuildDirectionSegment(DirectionType.Reverse, 4)
            });

            StitcherTestHelpers.VerifyDirectionType(expectedDirections, mergedRead.CigarDirections.Expand().ToArray());

            stitcher     = new BasicStitcher(10, useSoftclippedBases: true);
            alignmentSet = new AlignmentSet(read1, read2);
            stitcher.TryStitch(alignmentSet);
            mergedRead = StitcherTestHelpers.GetMergedRead(alignmentSet);
            Assert.Equal("4S137M4S", mergedRead.CigarData.ToString());
            expectedDirections = StitcherTestHelpers.BuildDirectionMap(new List <IEnumerable <DirectionType> >
            {
                StitcherTestHelpers.BuildDirectionSegment(DirectionType.Forward, 4),
                StitcherTestHelpers.BuildDirectionSegment(DirectionType.Reverse, 1),
                StitcherTestHelpers.BuildDirectionSegment(DirectionType.Stitched, 136),
                StitcherTestHelpers.BuildDirectionSegment(DirectionType.Reverse, 4)
            });
            StitcherTestHelpers.VerifyDirectionType(expectedDirections, mergedRead.CigarDirections.Expand().ToArray());

            // If we're not ignoring probe softclips, go back to the original expected directions (1 more stitched from probe)
            stitcher     = new BasicStitcher(10, useSoftclippedBases: true, ignoreProbeSoftclips: false);
            alignmentSet = new AlignmentSet(read1, read2);
            stitcher.TryStitch(alignmentSet);
            mergedRead = StitcherTestHelpers.GetMergedRead(alignmentSet);
            Assert.Equal("4S137M4S", mergedRead.CigarData.ToString());
            expectedDirections = StitcherTestHelpers.BuildDirectionMap(new List <IEnumerable <DirectionType> >
            {
                StitcherTestHelpers.BuildDirectionSegment(DirectionType.Forward, 4),
                StitcherTestHelpers.BuildDirectionSegment(DirectionType.Stitched, 137),
                StitcherTestHelpers.BuildDirectionSegment(DirectionType.Reverse, 4)
            });
            StitcherTestHelpers.VerifyDirectionType(expectedDirections, mergedRead.CigarDirections.Expand().ToArray());
        }