public void TryStitch_SoftclipScenarios() { //Migrated from old Pisces: Originally called Pisces_MergeRead2First var sequence = "GG" + "GGCCACGCGGGGAGCAGCCTCTGGCATTCTGGGAGCTTCATCTGGACCTGGGTCTTCAGTGAACCATTGTTCAATATCGTCCGGGGACAGCATCAAATCATCCATTGCTTGGGACGGCAAGG" + "GGGACTGTAGATGGGTGAAAAGAGCA"; var read1 = ReadTestHelper.CreateRead("chr1", sequence, 7579464, new CigarAlignment("2S122M26S"), Enumerable.Repeat((byte)30, sequence.Length).ToArray(), 7579464); StitcherTestHelpers.SetReadDirections(read1, DirectionType.Forward); sequence = "GTGTAGGAGCTGCTGGTGCAGG" + "GGCCACGCGGGGAGCAGCCTCTGGCATTCTGGGAGCTTCATCTGGACCTGGGTCTTCAGTGAACAATTGTTCAATATCGTCCGGGGCCAGCATCAAATCATCCATTGCTTGGGACGGCAAGG" + "GGGACT"; var read2 = ReadTestHelper.CreateRead("chr1", sequence, 7579464, new CigarAlignment("22S122M6S"), Enumerable.Repeat((byte)30, sequence.Length).ToArray(), 7579464); StitcherTestHelpers.SetReadDirections(read2, DirectionType.Reverse); string expectedWithNify = "GTGTAGGAGCTGCTGGTGCAGG" + "GGCCACGCGGGGAGCAGCCTCTGGCATTCTGGGAGCTTCATCTGGACCTGGGTCTTCAGTGAACNATTGTTCAATATCGTCCGGGGNCAGCATCAAATCATCCATTGCTTGGGACGGCAAGG" + "GGGACTGTAGATGGGTGAAAAGAGCA"; string expectedWithNoNify = "GTGTAGGAGCTGCTGGTGCAGG" + "GGCCACGCGGGGAGCAGCCTCTGGCATTCTGGGAGCTTCATCTGGACCTGGGTCTTCAGTGAACCATTGTTCAATATCGTCCGGGGACAGCATCAAATCATCCATTGCTTGGGACGGCAAGG" + "GGGACTGTAGATGGGTGAAAAGAGCA"; // both reads have the same reference position, but read2 really starts earlier // make sure we behave properly TestSuccesfullyStitchedRead(read1, read2, 0, "22S122M26S", (mergedRead) => { Assert.NotNull(mergedRead); Assert.Equal("22R122S26F", mergedRead.CigarDirections.ToString()); Assert.Equal(expectedWithNify, mergedRead.Sequence); }, nifyDisagreements: true); // Test with allowing probe softclips to merge TestSuccesfullyStitchedRead(read1, read2, 0, "22S122M26S", (mergedRead) => { Assert.NotNull(mergedRead); Assert.Equal("20R130S20F", mergedRead.CigarDirections.ToString()); Assert.Equal(expectedWithNify, mergedRead.Sequence); }, nifyDisagreements: true, ignoreProbeSoftclips: false); //here, the Q scores where we disagree are equal (30) so we give R1 the preference (R1 usually being better than R2, if we are forced to pick one) read1.BamAlignment.SetIsFirstMate(true); read2.BamAlignment.SetIsFirstMate(false); TestSuccesfullyStitchedRead(read1, read2, 0, "22S122M26S", (mergedRead) => { Assert.NotNull(mergedRead); Assert.Equal(expectedWithNoNify, mergedRead.Sequence); }, nifyDisagreements: false); }
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 void GenerateNifiedMergedRead() { var read1 = DomainTestHelper.CreateRead("chr1", "AAAAA", 2, new CigarAlignment("1S4M")); var read2 = DomainTestHelper.CreateRead("chr1", "AAAAA", 2, new CigarAlignment("4M1S")); StitcherTestHelpers.SetReadDirections(read2, DirectionType.Reverse); var alignmentSet = new AlignmentSet(read1, read2); var stitchedRead = GetStitchedRead(alignmentSet); Assert.Equal("1S4M1S", stitchedRead.StitchedCigar.ToString()); Assert.Equal("NNNNNN", stitchedRead.Sequence); Assert.Equal("1F4S1R", stitchedRead.CigarDirections.ToString()); StitcherTestHelpers.SetReadDirections(read1, DirectionType.Reverse); StitcherTestHelpers.SetReadDirections(read2, DirectionType.Forward); stitchedRead = GetStitchedRead(alignmentSet); Assert.Equal("1S4M1S", stitchedRead.StitchedCigar.ToString()); Assert.Equal("NNNNNN", stitchedRead.Sequence); Assert.Equal("1R4S1F", stitchedRead.CigarDirections.ToString()); StitcherTestHelpers.SetReadDirections(read1, DirectionType.Forward); StitcherTestHelpers.SetReadDirections(read2, DirectionType.Reverse); // Insertion that we don't know what to do with -> Nified match read1 = DomainTestHelper.CreateRead("chr1", "AAAAA", 2, new CigarAlignment("1S3M1I")); alignmentSet = new AlignmentSet(read1, read2); stitchedRead = GetStitchedRead(alignmentSet); Assert.Equal("1S4M1S", stitchedRead.StitchedCigar.ToString()); Assert.Equal("NNNNNN", stitchedRead.Sequence); Assert.Equal("1F4S1R", stitchedRead.CigarDirections.ToString()); // Read 1 goes to end of read 2 read1 = DomainTestHelper.CreateRead("chr1", "AAAAAA", 2, new CigarAlignment("1S3M2I")); alignmentSet = new AlignmentSet(read1, read2); stitchedRead = GetStitchedRead(alignmentSet); Assert.Equal("1S5M", stitchedRead.StitchedCigar.ToString()); Assert.Equal("NNNNNN", stitchedRead.Sequence); Assert.Equal("1F5S", stitchedRead.CigarDirections.ToString()); // Read 1 goes past read 2 read1 = DomainTestHelper.CreateRead("chr1", "AAAAAAA", 2, new CigarAlignment("1S3M3I")); alignmentSet = new AlignmentSet(read1, read2); stitchedRead = GetStitchedRead(alignmentSet); Assert.Equal("1S6M", stitchedRead.StitchedCigar.ToString()); Assert.Equal("NNNNNNN", stitchedRead.Sequence); Assert.Equal("1F5S1F", stitchedRead.CigarDirections.ToString()); }
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()); } } }
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_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)); }
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))); }); }
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()); }