public void TryStitch_ConsensusSequence() { // 1234... 1 - - 2 3 4 5 6 - - 7 8 9 0 //Reference Positions // Read1 X X X X X X X X - - - - - // Read1 M I I M M M M M - - - - - // Read1 A T C G A T C G - - - - - // Read2 - - - X X X X X X X X - - // Read2 - - - M M M M M I M M - - // Read2 - - - A T C G A T C G - - var r1qualities = 30; var r2qualities = 20; var read1 = TestHelper.CreateRead("chr1", "TTTTTTTT", 12341, new CigarAlignment("1M2I5M"), qualityForAll: (byte)r1qualities); var read2 = TestHelper.CreateRead("chr1", "AAAAAAAA", 12342, new CigarAlignment("5M1I2M"), qualityForAll: (byte)r2qualities); var stitcher = StitcherTestHelpers.GetStitcher(10); var alignmentSet = new AlignmentSet(read1, read2); stitcher.TryStitch(alignmentSet); // Merged A T C ? ? ? ? ? T C G - - // Merged M I I M M M M M I M M - - // Merged 0 1 2 3 4 5 6 7 8 9 0 1 2 var overlapStart = 3; var overlapEnd = 8; var overlapLength = 5; //Consensus sequence should have everything from read1 for positions before overlap var mergedRead = StitcherTestHelpers.GetMergedRead(alignmentSet); Assert.Equal("TTT", mergedRead.Sequence.Substring(0, overlapStart)); //Consensus sequence should have everything from read2 for positions after overlap Assert.Equal("AAA", mergedRead.Sequence.Substring(overlapEnd, 3)); //Consensus sequence should have an N where we have two high-quality (both above min) disagreeing bases Assert.Equal("NNNNN", mergedRead.Sequence.Substring(overlapStart, 5)); //Consensus sequence should have 0 quality where we have two high-quality (both above min) disagreeing bases Assert.True(mergedRead.Qualities.Take(overlapStart).All(q => q == r1qualities)); Assert.True(mergedRead.Qualities.Skip(overlapStart).Take(overlapLength).All(q => q == 0)); Assert.True(mergedRead.Qualities.Skip(overlapEnd).Take(mergedRead.Sequence.Length - overlapEnd).All(q => q == r2qualities)); //Consensus sequence should take higher quality base if one or more of the bases is below min quality //Read 2 trumps whole overlap read1.BamAlignment.Qualities = new byte[] { 30, 30, 30, 5, 5, 5, 5, 5 }; read2.BamAlignment.Qualities = new byte[] { 40, 40, 40, 40, 40, 20, 19, 18 }; alignmentSet = new AlignmentSet(read1, read2); stitcher.TryStitch(alignmentSet); mergedRead = StitcherTestHelpers.GetMergedRead(alignmentSet); Assert.Equal(read2.Sequence.Substring(0, 5), mergedRead.Sequence.Substring(overlapStart, 5)); Assert.Equal("TTTAAAAAAAA", mergedRead.Sequence); StitcherTestHelpers.CompareQuality(new byte[] { 30, 30, 30, 40, 40, 40, 40, 40, 20, 19, 18 }, mergedRead.Qualities); //Read 1 trumps whole overlap read1.BamAlignment.Qualities = new byte[] { 30, 30, 30, 40, 40, 40, 40, 40 }; read2.BamAlignment.Qualities = new byte[] { 5, 5, 5, 5, 5, 20, 19, 18 }; alignmentSet = new AlignmentSet(read1, read2); stitcher.TryStitch(alignmentSet); mergedRead = StitcherTestHelpers.GetMergedRead(alignmentSet); Assert.Equal(read1.Sequence.Substring(3, 5), mergedRead.Sequence.Substring(overlapStart, 5)); Assert.Equal("TTTTTTTTAAA", mergedRead.Sequence); StitcherTestHelpers.CompareQuality(new byte[] { 30, 30, 30, 40, 40, 40, 40, 40, 20, 19, 18 }, mergedRead.Qualities); //Little bit of each read1.BamAlignment.Qualities = new byte[] { 30, 30, 30, 5, 45, 5, 45, 5 }; read2.BamAlignment.Qualities = new byte[] { 40, 5, 40, 5, 40, 20, 19, 18 }; alignmentSet = new AlignmentSet(read1, read2); stitcher.TryStitch(alignmentSet); mergedRead = StitcherTestHelpers.GetMergedRead(alignmentSet); Assert.Equal("TTTATATAAAA", mergedRead.Sequence); StitcherTestHelpers.CompareQuality(new byte[] { 30, 30, 30, 40, 45, 40, 45, 40, 20, 19, 18 }, mergedRead.Qualities); //Consensus sequence should take base and assign the higher quality if both bases agree var read2_agreeingBases = TestHelper.CreateRead("chr1", "TTTTTTTT", 12342, new CigarAlignment("5M1I2M"), new byte[] { 40, 5, 40, 5, 40, 20, 19, 18 }); read1.BamAlignment.Qualities = new byte[] { 30, 30, 30, 5, 45, 5, 45, 5 }; alignmentSet = new AlignmentSet(read1, read2_agreeingBases); stitcher.TryStitch(alignmentSet); mergedRead = StitcherTestHelpers.GetMergedRead(alignmentSet); Assert.Equal("TTTTTTTTTTT", mergedRead.Sequence); StitcherTestHelpers.CompareQuality(new byte[] { 30, 30, 30, 40, 45, 40, 45, 40, 20, 19, 18 }, mergedRead.Qualities); //Bases disagree and both are below minimum quality, read1>read2 : take base/q from read1 read1.BamAlignment.Qualities = new byte[] { 30, 30, 30, 8, 8, 8, 8, 8 }; read2.BamAlignment.Qualities = new byte[] { 5, 5, 5, 5, 5, 20, 19, 18 }; alignmentSet = new AlignmentSet(read1, read2); stitcher.TryStitch(alignmentSet); mergedRead = StitcherTestHelpers.GetMergedRead(alignmentSet); Assert.Equal(read1.Sequence.Substring(3, 5), mergedRead.Sequence.Substring(overlapStart, 5)); Assert.Equal("TTTTTTTTAAA", mergedRead.Sequence); StitcherTestHelpers.CompareQuality(new byte[] { 30, 30, 30, 8, 8, 8, 8, 8, 20, 19, 18 }, mergedRead.Qualities); //Bases disagree and both are below minimum quality, read2>read1 : take base/q from read2 read1.BamAlignment.Qualities = new byte[] { 30, 30, 30, 5, 5, 5, 5, 5 }; read2.BamAlignment.Qualities = new byte[] { 8, 8, 8, 8, 8, 20, 19, 18 }; alignmentSet = new AlignmentSet(read1, read2); stitcher.TryStitch(alignmentSet); mergedRead = StitcherTestHelpers.GetMergedRead(alignmentSet); Assert.Equal(read2.Sequence.Substring(0, 5), mergedRead.Sequence.Substring(overlapStart, 5)); Assert.Equal("TTTAAAAAAAA", mergedRead.Sequence); StitcherTestHelpers.CompareQuality(new byte[] { 30, 30, 30, 8, 8, 8, 8, 8, 20, 19, 18 }, mergedRead.Qualities); //Bases disagree and both are below minimum quality, read1==read2 : take base/q from read1 read1.BamAlignment.Qualities = new byte[] { 30, 30, 30, 5, 5, 5, 5, 5 }; read2.BamAlignment.Qualities = new byte[] { 5, 5, 5, 5, 5, 20, 19, 18 }; alignmentSet = new AlignmentSet(read1, read2); stitcher.TryStitch(alignmentSet); mergedRead = StitcherTestHelpers.GetMergedRead(alignmentSet); Assert.Equal(read1.Sequence.Substring(3, 5), mergedRead.Sequence.Substring(overlapStart, 5)); Assert.Equal("TTTTTTTTAAA", mergedRead.Sequence); StitcherTestHelpers.CompareQuality(new byte[] { 30, 30, 30, 5, 5, 5, 5, 5, 20, 19, 18 }, mergedRead.Qualities); }
public void TryStitch_MergeReadsSmall() { //Migrated from old Pisces: Originally called CallSomaticVariants_MergeReadsSmall //test1: happy path //0 1 2 3 4 5 6 7 8 9 //- C A T A T //- - - - A T A G G var read1 = TestHelper.CreateRead("chr1", "CATAT", 1, new CigarAlignment("5M"), new byte[] { 1, 2, 3, 4, 5 }, 4); StitcherTestHelpers.SetReadDirections(read1, DirectionType.Forward); var read2 = TestHelper.CreateRead("chr1", "ATAGG", 4, new CigarAlignment("5M"), new byte[] { 1, 20, 30, 40, 50 }, 1); StitcherTestHelpers.SetReadDirections(read2, DirectionType.Reverse); var alignmentSet = new AlignmentSet(read1, read2); var stitcher = StitcherTestHelpers.GetStitcher(10); stitcher.TryStitch(alignmentSet); TestSuccesfullyStitchedRead(read1, read2, 0, "8M", (mergedRead) => { Assert.Equal(mergedRead.Sequence, "CATATAGG"); StitcherTestHelpers.CompareQuality(new byte[] { 1, 2, 3, 4, 20, 30, 40, 50 }, mergedRead.Qualities); var expectedDirections = StitcherTestHelpers.BuildDirectionMap(new List <IEnumerable <DirectionType> > { StitcherTestHelpers.BuildDirectionSegment(DirectionType.Forward, 3), StitcherTestHelpers.BuildDirectionSegment(DirectionType.Stitched, 2), StitcherTestHelpers.BuildDirectionSegment(DirectionType.Reverse, 3) }); StitcherTestHelpers.VerifyDirectionType(expectedDirections, mergedRead.DirectionMap); }); //test2: different bases, one with low Q //0 1 2 3 4 5 6 7 8 9 //- C A T A G //- - - - A T A G G read1 = TestHelper.CreateRead("chr1", "CATAG", 1, new CigarAlignment("5M"), new byte[] { 1, 2, 3, 4, 5 }, 4); StitcherTestHelpers.SetReadDirections(read1, DirectionType.Reverse); read2 = TestHelper.CreateRead("chr1", "ATAGG", 4, new CigarAlignment("5M"), new byte[] { 1, 20, 30, 40, 50 }, 1); StitcherTestHelpers.SetReadDirections(read2, DirectionType.Forward); TestSuccesfullyStitchedRead(read1, read2, 10, "8M", (mergedRead) => { Assert.NotNull(mergedRead); Assert.Equal(mergedRead.Sequence, "CATATAGG"); StitcherTestHelpers.CompareQuality(new byte[] { 1, 2, 3, 4, 20, 30, 40, 50 }, mergedRead.Qualities); var expectedDirections = StitcherTestHelpers.BuildDirectionMap(new List <IEnumerable <DirectionType> > { StitcherTestHelpers.BuildDirectionSegment(DirectionType.Reverse, 3), StitcherTestHelpers.BuildDirectionSegment(DirectionType.Stitched, 2), StitcherTestHelpers.BuildDirectionSegment(DirectionType.Forward, 3) }); StitcherTestHelpers.VerifyDirectionType(expectedDirections, mergedRead.DirectionMap); }); //test3: different bases, both with high Q //0 1 2 3 4 5 6 7 8 9 //- C A T A G //- - - - A T A G G read1 = TestHelper.CreateRead("chr1", "CATAG", 1, new CigarAlignment("5M"), new byte[] { 100, 200, 200, 200, 200 }, 4); read2 = TestHelper.CreateRead("chr1", "ATAGG", 4, new CigarAlignment("5M"), new byte[] { 1, 20, 30, 40, 50 }, 1); StitcherTestHelpers.SetReadDirections(read1, DirectionType.Forward); StitcherTestHelpers.SetReadDirections(read2, DirectionType.Reverse); TestSuccesfullyStitchedRead(read1, read2, 10, "8M", (mergedRead) => { Assert.NotNull(mergedRead); Assert.Equal(mergedRead.Sequence, "CATANAGG"); StitcherTestHelpers.CompareQuality(new byte[] { 100, 200, 200, 200, 0, 30, 40, 50 }, mergedRead.Qualities); var expectedDirections = StitcherTestHelpers.BuildDirectionMap(new List <IEnumerable <DirectionType> > { StitcherTestHelpers.BuildDirectionSegment(DirectionType.Forward, 3), StitcherTestHelpers.BuildDirectionSegment(DirectionType.Stitched, 2), StitcherTestHelpers.BuildDirectionSegment(DirectionType.Reverse, 3) }); StitcherTestHelpers.VerifyDirectionType(expectedDirections, mergedRead.DirectionMap); }); }