public void TryStitch_NoXC_Stitchable() { var xcStitcherXcRequired = GetXCStitcher(); //Reads without XC tags that do overlap should be added separately in XC stitcher when xc is required var alignmentSet = StitcherTestHelpers.GetOverlappingReadSet(); StitcherTestHelpers.TryStitchAndAssertFailed(xcStitcherXcRequired, alignmentSet); }
public void TryStitch_NoXC_Unstitchable() { var read1 = TestHelper.CreateRead("chr1", "ATCGATCG", 12345, new CigarAlignment("8M"), qualityForAll: 30); var read2_noOverlap = TestHelper.CreateRead("chr1", "A", 2384, new CigarAlignment("1M"), qualityForAll: 30); var read2_overlap = TestHelper.CreateRead("chr1", "ATCGTT", 12349, new CigarAlignment("6M"), qualityForAll: 30); var read2_diffChrom = TestHelper.CreateRead("chr2", "ATCGTT", 12349, new CigarAlignment("6M"), qualityForAll: 30); var read2_nonOverlap_border = TestHelper.CreateRead("chr1", "AT", 12343, new CigarAlignment("2M"), qualityForAll: 30); var stitcher = StitcherTestHelpers.GetStitcher(10, true); // ----------------------------------------------- // 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); StitcherTestHelpers.TryStitchAndAssertFailed(stitcher, alignmentSet); // ----------------------------------------------- // No overlap, reads are directly neighboring // ----------------------------------------------- // Shouldn't stitch alignmentSet = new AlignmentSet(read1, read2_nonOverlap_border); StitcherTestHelpers.TryStitchAndAssertFailed(stitcher, alignmentSet); // ----------------------------------------------- // No overlap, reads on diff chromosomes // ----------------------------------------------- // Should throw exception alignmentSet = new AlignmentSet(read1, read2_diffChrom); var ex = Assert.Throws <ArgumentException>(() => stitcher.TryStitch(alignmentSet)); Assert.Contains("Partner reads are from different chromosomes", ex.Message, StringComparison.InvariantCultureIgnoreCase); // This is brittle but since a variety of exceptions can happen in this process want to make sure it's this specific one }
public static void TestSuccesfullyStitchedRead(Read read1, Read read2, int minQscore, string xcTag, Action <Read> assertions) { var alignmentSet = new AlignmentSet(read1, read2); var stitcher = StitcherTestHelpers.GetStitcher(minQscore); stitcher.TryStitch(alignmentSet); // ----------------------------------------------- // Basic Stitcher, No XC tag // ----------------------------------------------- CheckMergedRead(xcTag, assertions, alignmentSet); // ----------------------------------------------- // XC Stitcher (XC Req), No XC tag // ----------------------------------------------- alignmentSet = new AlignmentSet(read1, read2); stitcher = StitcherTestHelpers.GetStitcher(minQscore, true); StitcherTestHelpers.TryStitchAndAssertFailed(stitcher, alignmentSet); // ----------------------------------------------- // Basic Stitcher, With XC tag // ----------------------------------------------- read1.StitchedCigar = new CigarAlignment(xcTag); read2.StitchedCigar = new CigarAlignment(xcTag); alignmentSet = new AlignmentSet(read1, read2); stitcher = StitcherTestHelpers.GetStitcher(minQscore); stitcher.TryStitch(alignmentSet); CheckMergedRead(xcTag, assertions, alignmentSet); // ----------------------------------------------- // XC Stitcher (XC Req), With XC tag // ----------------------------------------------- alignmentSet = new AlignmentSet(read1, read2); stitcher = StitcherTestHelpers.GetStitcher(minQscore, true); stitcher.TryStitch(alignmentSet); CheckMergedRead(xcTag, assertions, alignmentSet); }
public void TryStitch_CalculateStitchedCigar() { // ----------------------------------------------- // Read position maps disagree // ----------------------------------------------- var read1 = TestHelper.CreateRead("chr1", "ATCGATCG", 12345, new CigarAlignment("2M2D3M1D3M"), qualityForAll: 30); var read2 = TestHelper.CreateRead("chr1", "ATCGATCG", 12349, new CigarAlignment("8M"), qualityForAll: 30); // [If require XC] // We never calculate stitched cigar anyway. Bounce out to processing separately. var stitcher = GetXCStitcher(); var alignmentSet = new AlignmentSet(read1, read2); StitcherTestHelpers.TryStitchAndAssertFailed(stitcher, alignmentSet); // ----------------------------------------------- // 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 - - // ----------------------------------------------- // [If require XC] // No stitched cigar, and separate reads read1 = TestHelper.CreateRead("chr1", "ATCGATCG", 12341, new CigarAlignment("1M2I5M"), qualityForAll: 30); read2 = TestHelper.CreateRead("chr1", "ATCGATCG", 12342, new CigarAlignment("5M1I2M"), qualityForAll: 30); stitcher = GetXCStitcher(); alignmentSet = new AlignmentSet(read1, read2); StitcherTestHelpers.TryStitchAndAssertFailed(stitcher, alignmentSet); }
public void TryStitch_WithXCTag() { const string xcTagDiffFromCalculated = "4M2I4M"; const string expectedCalculatedCigar = "10M"; var xcRequiredStitcher = GetXCStitcher(); // ----------------------------------------------- // XC tag is available, and matching between R1 and R2, and expected length, // but is different from the cigar string we would have calculated // ----------------------------------------------- // [If require XC] // XC tag should be taken var alignmentSet = StitcherTestHelpers.GetOverlappingReadSet(); alignmentSet.PartnerRead1.StitchedCigar = new CigarAlignment(xcTagDiffFromCalculated); alignmentSet.PartnerRead2.StitchedCigar = new CigarAlignment(xcTagDiffFromCalculated); xcRequiredStitcher.TryStitch(alignmentSet); Assert.Equal(1, alignmentSet.ReadsForProcessing.Count); var mergedRead = alignmentSet.ReadsForProcessing.First(); Assert.Equal(xcTagDiffFromCalculated, mergedRead.CigarData.ToString()); // ----------------------------------------------- // XC tag is there, and matching between R1 and R2, but not expected length // ----------------------------------------------- // [If not require XC] //bounce back to processing separately? //alignmentSet = GetOverlappingReadSet(); //alignmentSet.PartnerRead1.StitchedCigarString = "8M"; //alignmentSet.PartnerRead2.StitchedCigarString = "8M"; //stitcher.TryStitch(alignmentSet); //Assert.Equal(2, alignmentSet.ReadsForProcessing.Count); // [If require XC] //??? // ----------------------------------------------- // XC tag is there on one read but not the other // ----------------------------------------------- // [If require XC] // should bounce back to separate processing alignmentSet = StitcherTestHelpers.GetOverlappingReadSet(); alignmentSet.PartnerRead1.StitchedCigar = new CigarAlignment("4M2I4M"); alignmentSet.PartnerRead2.StitchedCigar = null; StitcherTestHelpers.TryStitchAndAssertFailed(xcRequiredStitcher, alignmentSet); alignmentSet = StitcherTestHelpers.GetOverlappingReadSet(); alignmentSet.PartnerRead1.StitchedCigar = null; alignmentSet.PartnerRead2.StitchedCigar = new CigarAlignment("4M2I4M"); StitcherTestHelpers.TryStitchAndAssertFailed(xcRequiredStitcher, alignmentSet); // ----------------------------------------------- // XC tag is not there // ----------------------------------------------- // [If require XC] // should bounce back to separate processing alignmentSet = StitcherTestHelpers.GetOverlappingReadSet(); alignmentSet.PartnerRead1.StitchedCigar = null; alignmentSet.PartnerRead2.StitchedCigar = null; StitcherTestHelpers.TryStitchAndAssertFailed(xcRequiredStitcher, alignmentSet); // ----------------------------------------------- // XC tag does not match between read1 and read2 // ----------------------------------------------- // [If require XC] // should bounce back to separate processing alignmentSet = StitcherTestHelpers.GetOverlappingReadSet(); alignmentSet.PartnerRead1.StitchedCigar = new CigarAlignment("4M2I4M"); alignmentSet.PartnerRead2.StitchedCigar = new CigarAlignment("9M1I"); StitcherTestHelpers.TryStitchAndAssertFailed(xcRequiredStitcher, alignmentSet); }