public void TryStitch_NoXC_Stitchable() { //Reads without XC tags that do overlap should be added as one merged read in basic stitcher var basicStitcher = StitcherTestHelpers.GetStitcher(10); var alignmentSet = StitcherTestHelpers.GetOverlappingReadSet(); basicStitcher.TryStitch(alignmentSet); Assert.Equal(1, alignmentSet.ReadsForProcessing.Count); }
public static void TestSuccesfullyStitchedRead(Read read1, Read read2, int minQscore, string xcTag, Action <Read> assertions, bool nifyDisagreements = false, bool useSoftclippedBases = true, bool ignoreProbeSoftclips = true) { var alignmentSet = new AlignmentSet(read1, read2); var stitcher = StitcherTestHelpers.GetStitcher(minQscore, nifyDisagreements: nifyDisagreements, useSoftclippedBases: useSoftclippedBases, ignoreProbeSoftclips: ignoreProbeSoftclips); stitcher.TryStitch(alignmentSet); // ----------------------------------------------- // Basic Stitcher, No XC tag // ----------------------------------------------- CheckMergedRead(xcTag, assertions, alignmentSet); }
public void TryStitch_CalculateStitchedCigar() { // ----------------------------------------------- // Read position maps disagree // ----------------------------------------------- // Should throw out the pair var read1 = DomainTestHelper.CreateRead("chr1", "ATCGATCG", 12345, new CigarAlignment("2M2D3M1D3M"), qualityForAll: 30); //Within the overlap, we have a deletion so there will be a shifting of positions from that point on var read2 = DomainTestHelper.CreateRead("chr1", "ATCGATCG", 12349, new CigarAlignment("8M"), qualityForAll: 30); var stitcher = StitcherTestHelpers.GetStitcher(10); var alignmentSet = new AlignmentSet(read1, read2); Assert.True(!alignmentSet.ReadsForProcessing.Any()); // ----------------------------------------------- // When calculating stitched cigar, stitched cigar should have // - everything from read1 before the overlap // - everything from read2 starting from the overlap // But since we ensure that the position maps agree in the overlap region, it's really not a matter of one taking precedence over the other // 1234... 1 - - 2 3 4 5 6 - - 7 8 9 0 // Read1 X X X X X X X X - - - - - // Read1 M I I M M M M M - - - - - // Read2 - - - X X X X X X X X - - // Read2 - - - M M M M M I M M - - // ----------------------------------------------- // Stitched cigar should have R1's insertion from before the overlap and R2's insertion from after the overlap read1 = DomainTestHelper.CreateRead("chr1", "ATCGATCG", 12341, new CigarAlignment("1M2I5M"), qualityForAll: 30); read2 = DomainTestHelper.CreateRead("chr1", "ATCGATCG", 12342, new CigarAlignment("5M1I2M"), qualityForAll: 30); stitcher = StitcherTestHelpers.GetStitcher(10); alignmentSet = new AlignmentSet(read1, read2); stitcher.TryStitch(alignmentSet); Assert.Equal("1M2I5M1I2M", StitcherTestHelpers.GetMergedRead(alignmentSet).CigarData.ToString()); }
public void TryStitch_MergeReadsSmall() { //Migrated from old Pisces: Originally called Pisces_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 = ReadTestHelper.CreateRead("chr1", "CATAT", 1, new CigarAlignment("5M"), new byte[] { 1, 2, 3, 4, 5 }, 4); StitcherTestHelpers.SetReadDirections(read1, DirectionType.Forward); var read2 = ReadTestHelper.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, nifyDisagreements: false); stitcher.TryStitch(alignmentSet); TestSuccesfullyStitchedRead(read1, read2, 0, "8M", (mergedRead) => { Assert.Equal(mergedRead.Sequence, "CATATAGG"); StitcherTestHelpers.CompareQuality(new byte[] { 1, 2, 3, 5, 25, 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.CigarDirections.Expand().ToArray()); }); //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 = ReadTestHelper.CreateRead("chr1", "CATAG", 1, new CigarAlignment("5M"), new byte[] { 1, 2, 3, 4, 5 }, 4); StitcherTestHelpers.SetReadDirections(read1, DirectionType.Reverse); read2 = ReadTestHelper.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("CATATAGG", mergedRead.Sequence); StitcherTestHelpers.CompareQuality(new byte[] { 1, 2, 3, 5, 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.CigarDirections.Expand().ToArray()); }); //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 = ReadTestHelper.CreateRead("chr1", "CATAG", 1, new CigarAlignment("5M"), new byte[] { 50, 92, 92, 92, 92 }, 4); read2 = ReadTestHelper.CreateRead("chr1", "ATAGG", 4, new CigarAlignment("5M"), new byte[] { 2, 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("CATANAGG", mergedRead.Sequence); StitcherTestHelpers.CompareQuality(new byte[] { 50, 92, 92, 93, 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.CigarDirections.Expand().ToArray()); }, nifyDisagreements: true); }
private void ExecuteConsensusTests(bool nifyDisagreements) { // 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 T T T T T T T T - - - - - // Read2 - - - X X X X X X X X - - // Read2 - - - M M M M M I M M - - // Read2 - - - A A A A A A A A - - var r1qualities = 30; var r2qualities = 20; var read1 = DomainTestHelper.CreateRead("chr1", "TTTTTTTT", 12341, new CigarAlignment("1M2I5M"), qualityForAll: (byte)r1qualities); var read2 = DomainTestHelper.CreateRead("chr1", "AAAAAAAA", 12342, new CigarAlignment("5M1I2M"), qualityForAll: (byte)r2qualities); var stitcher = StitcherTestHelpers.GetStitcher(10, false, nifyDisagreements: nifyDisagreements); 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(nifyDisagreements? "NNNNN":"TTTTT", 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(nifyDisagreements ? "NNNNN" : read2.Sequence.Substring(0, 5), mergedRead.Sequence.Substring(overlapStart, 5)); Assert.Equal(nifyDisagreements ? "TTTNNNNNAAA" : "TTTAAAAAAAA", mergedRead.Sequence); StitcherTestHelpers.CompareQuality(nifyDisagreements ? new byte[] { 30, 30, 30, 0, 0, 0, 0, 0, 20, 19, 18 } : 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(nifyDisagreements ? "NNNNN" : read1.Sequence.Substring(3, 5), mergedRead.Sequence.Substring(overlapStart, 5)); Assert.Equal(nifyDisagreements ? "TTTNNNNNAAA" : "TTTTTTTTAAA", mergedRead.Sequence); StitcherTestHelpers.CompareQuality(nifyDisagreements ? new byte[] { 30, 30, 30, 0, 0, 0, 0, 0, 20, 19, 18 } : 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(nifyDisagreements ? "TTTNNNNNAAA" : "TTTATATAAAA", mergedRead.Sequence); StitcherTestHelpers.CompareQuality(nifyDisagreements ? new byte[] { 30, 30, 30, 0, 0, 0, 0, 0, 20, 19, 18 } : 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 = DomainTestHelper.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, 45, 50, 45, 50, 45, 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(nifyDisagreements ? "NNNNN" : read1.Sequence.Substring(3, 5), mergedRead.Sequence.Substring(overlapStart, 5)); Assert.Equal(nifyDisagreements ? "TTTNNNNNAAA" : "TTTTTTTTAAA", mergedRead.Sequence); StitcherTestHelpers.CompareQuality(nifyDisagreements ? new byte[] { 30, 30, 30, 0, 0, 0, 0, 0, 20, 19, 18 } : 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(nifyDisagreements ? "NNNNN" : read2.Sequence.Substring(0, 5), mergedRead.Sequence.Substring(overlapStart, 5)); Assert.Equal(nifyDisagreements ? "TTTNNNNNAAA" : "TTTAAAAAAAA", mergedRead.Sequence); StitcherTestHelpers.CompareQuality(nifyDisagreements ? new byte[] { 30, 30, 30, 0, 0, 0, 0, 0, 20, 19, 18 } : 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(nifyDisagreements ? "NNNNN" : read1.Sequence.Substring(3, 5), mergedRead.Sequence.Substring(overlapStart, 5)); Assert.Equal(nifyDisagreements ? "TTTNNNNNAAA" : "TTTTTTTTAAA", mergedRead.Sequence); StitcherTestHelpers.CompareQuality(nifyDisagreements ? new byte[] { 30, 30, 30, 0, 0, 0, 0, 0, 20, 19, 18 } : new byte[] { 30, 30, 30, 5, 5, 5, 5, 5, 20, 19, 18 }, mergedRead.Qualities); }
public void TryStitch_NoXC_Unstitchable() { var read1 = DomainTestHelper.CreateRead("chr1", "ATCGATCG", 12345, new CigarAlignment("8M"), qualityForAll: 30); var read2_noOverlap = DomainTestHelper.CreateRead("chr1", "A", 2384, new CigarAlignment("1M"), qualityForAll: 30); var read2_overlap = DomainTestHelper.CreateRead("chr1", "ATCGTT", 12349, new CigarAlignment("1I5M"), qualityForAll: 30); var read2_diffChrom = DomainTestHelper.CreateRead("chr2", "ATCGTT", 12349, new CigarAlignment("6M"), qualityForAll: 30); var read2_nonOverlap_border = DomainTestHelper.CreateRead("chr1", "AT", 12343, new CigarAlignment("2M"), qualityForAll: 30); var stitcher = StitcherTestHelpers.GetStitcher(10); ; // ----------------------------------------------- // Either of the partner reads is missing* // *(only read that could be missing is read 2, if read 1 was missing couldn't create alignment set) // ----------------------------------------------- // Should throw an exception var alignmentSet = new AlignmentSet(read1, null); Assert.Throws <ArgumentException>(() => stitcher.TryStitch(alignmentSet)); // ----------------------------------------------- // No overlap, reads are far away // ----------------------------------------------- // Shouldn't stitch alignmentSet = new AlignmentSet(read1, read2_noOverlap); stitcher.TryStitch(alignmentSet); Assert.Equal(2, alignmentSet.ReadsForProcessing.Count); StitcherTestHelpers.TestUnstitchableReads(read1, read2_noOverlap, 0, (unStitchableReads) => { Assert.Equal(1, unStitchableReads.Count(x => StitcherTestHelpers.VerifyReadsEqual(read1, x))); Assert.Equal(1, unStitchableReads.Count(x => StitcherTestHelpers.VerifyReadsEqual(read2_noOverlap, x))); }); // ----------------------------------------------- // No overlap, reads are directly neighboring // ----------------------------------------------- // Shouldn't stitch alignmentSet = new AlignmentSet(read1, read2_nonOverlap_border); stitcher.TryStitch(alignmentSet); Assert.Equal(2, alignmentSet.ReadsForProcessing.Count); StitcherTestHelpers.TestUnstitchableReads(read1, read2_nonOverlap_border, 0, (unStitchableReads) => { Assert.Equal(1, unStitchableReads.Count(x => StitcherTestHelpers.VerifyReadsEqual(read1, x))); Assert.Equal(1, unStitchableReads.Count(x => StitcherTestHelpers.VerifyReadsEqual(read2_nonOverlap_border, x))); }); // ----------------------------------------------- // No overlap, reads on diff chromosomes // ----------------------------------------------- // Shouldn't stitch alignmentSet = new AlignmentSet(read1, read2_diffChrom); stitcher.TryStitch(alignmentSet); Assert.Equal(2, alignmentSet.ReadsForProcessing.Count); StitcherTestHelpers.TestUnstitchableReads(read1, read2_diffChrom, 0, (unStitchableReads) => { Assert.Equal(1, unStitchableReads.Count(x => StitcherTestHelpers.VerifyReadsEqual(read1, x))); Assert.Equal(1, unStitchableReads.Count(x => StitcherTestHelpers.VerifyReadsEqual(read2_diffChrom, x))); }); // ----------------------------------------------- // Has overlap, but cigars are incompatible // ----------------------------------------------- // Shouldn't stitch alignmentSet = new AlignmentSet(read1, read2_overlap); stitcher.TryStitch(alignmentSet); Assert.Equal(2, alignmentSet.ReadsForProcessing.Count); StitcherTestHelpers.TestUnstitchableReads(read1, read2_overlap, 0, (unStitchableReads) => { Assert.Equal(1, unStitchableReads.Count(x => StitcherTestHelpers.VerifyReadsEqual(read1, x))); Assert.Equal(1, unStitchableReads.Count(x => StitcherTestHelpers.VerifyReadsEqual(read2_overlap, x))); }); // ----------------------------------------------- // Has overlap, but cigars are incompatible, but read 2 starts with SC // ----------------------------------------------- // Overlap is just S and I - should stitch // 5678----90123456789 // MMMMIIII // SSSSMMMM var read1_withIns = DomainTestHelper.CreateRead("chr1", "ATCGATCG", 12345, new CigarAlignment("4M4I"), qualityForAll: 30); var read2_withSC = DomainTestHelper.CreateRead("chr1", "ATCGATCG", 12349, new CigarAlignment("4S4M"), qualityForAll: 30); alignmentSet = new AlignmentSet(read1_withIns, read2_withSC); //stitcher.TryStitch(alignmentSet); //Assert.Equal(1, alignmentSet.ReadsForProcessing.Count); //Assert.Equal("4M4I4M", alignmentSet.ReadsForProcessing.First().CigarData.ToString()); // Overlap is S and some disagreeing ops with I - should not stitch read2_withSC = DomainTestHelper.CreateRead("chr1", "ATCGATCG", 12348, new CigarAlignment("2S1D6M"), qualityForAll: 30); alignmentSet = new AlignmentSet(read1_withIns, read2_withSC); stitcher.TryStitch(alignmentSet); Assert.Equal(2, alignmentSet.ReadsForProcessing.Count); StitcherTestHelpers.TestUnstitchableReads(read1_withIns, read2_withSC, 0, (unStitchableReads) => { Assert.Equal(1, unStitchableReads.Count(x => StitcherTestHelpers.VerifyReadsEqual(read1_withIns, x))); Assert.Equal(1, unStitchableReads.Count(x => StitcherTestHelpers.VerifyReadsEqual(read2_withSC, x))); }); }