예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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
        }
예제 #4
0
        public void TryStitch_CalculateStitchedCigar()
        {
            // -----------------------------------------------
            // Read position maps disagree
            // -----------------------------------------------
            // Should throw out the pair
            var read1 = TestHelper.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 = TestHelper.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 = TestHelper.CreateRead("chr1", "ATCGATCG", 12341,
                                          new CigarAlignment("1M2I5M"), qualityForAll: 30);

            read2 = TestHelper.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 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);
        }
예제 #6
0
        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_SoftclipScenarios()
        {
            //Migrated from old Pisces: Originally called CallSomaticVariants_MergeRead2First
            var sequence =
                "GGGGCCACGCGGGGAGCAGCCTCTGGCATTCTGGGAGCTTCATCTGGACCTGGGTCTTCAGTGAACCATTGTTCAATATCGTCCGGGGACAGCATCAAATCATCCATTGCTTGGGACGGCAAGGGGGACTGTAGATGGGTGAAAAGAGCA";

            var read1 = TestHelper.CreateRead("chr1",
                                              sequence,
                                              7579464,
                                              new CigarAlignment("2S122M26S"),
                                              Enumerable.Repeat((byte)30, sequence.Length).ToArray(),
                                              7579464);

            StitcherTestHelpers.SetReadDirections(read1, DirectionType.Forward);

            sequence =
                "GTGTAGGAGCTGCTGGTGCAGGGGCCACGCGGGGAGCAGCCTCTGGCATTCTGGGAGCTTCATCTGGACCTGGGTCTTCAGTGAACAATTGTTCAATATCGTCCGGGGCCAGCATCAAATCATCCATTGCTTGGGACGGCAAGGGGGACT";
            var read2 = TestHelper.CreateRead("chr1",
                                              sequence,
                                              7579464,
                                              new CigarAlignment("22S122M6S"),
                                              Enumerable.Repeat((byte)30, sequence.Length).ToArray(),
                                              7579464);

            StitcherTestHelpers.SetReadDirections(read2, DirectionType.Reverse);

            string expected =
                "GTGTAGGAGCTGCTGGTGCAGGGGCCACGCGGGGAGCAGCCTCTGGCATTCTGGGAGCTTCATCTGGACCTGGGTCTTCAGTGAACNATTGTTCAATATCGTCCGGGGNCAGCATCAAATCATCCATTGCTTGGGACGGCAAGGGGGACTGTAGATGGGTGAAAAGAGCA";

            // 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(mergedRead.Sequence, expected);
            });
        }
예제 #8
0
        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);
        }
예제 #9
0
        public void TryStitch_WithXCTag()
        {
            const string xcTagDiffFromCalculated = "4M2I4M";
            const string expectedCalculatedCigar = "10M";
            var          read1 = TestHelper.CreateRead("chr1", "ATCGATCG", 12345,
                                                       new CigarAlignment("8M"), qualityForAll: 30);

            var read2_overlap = TestHelper.CreateRead("chr1", "ATCGTT", 12349,
                                                      new CigarAlignment("6M"), qualityForAll: 30);

            var stitcher = StitcherTestHelpers.GetStitcher(10);

            // -----------------------------------------------
            // XC tag is available, and matching between R1 and R2, and expected length,
            // but is different from the cigar string we would have calculated
            // -----------------------------------------------
            // XC tag should be taken
            read1.StitchedCigar         = new CigarAlignment(xcTagDiffFromCalculated);
            read2_overlap.StitchedCigar = new CigarAlignment(xcTagDiffFromCalculated);

            var alignmentSet = new AlignmentSet(read1, read2_overlap);

            stitcher.TryStitch(alignmentSet);

            var mergedRead = StitcherTestHelpers.GetMergedRead(alignmentSet);

            Assert.Equal(xcTagDiffFromCalculated, mergedRead.CigarData.ToString());

            // -----------------------------------------------
            // XC tag is there, and matching between R1 and R2, but not expected length
            // -----------------------------------------------
            // XC tag should be ignored if it is not expected length, and new cigar should be calculated
            read1.StitchedCigar         = new CigarAlignment("8M");
            read2_overlap.StitchedCigar = new CigarAlignment("8M");
            alignmentSet = new AlignmentSet(read1, read2_overlap);
            stitcher.TryStitch(alignmentSet);

            mergedRead = StitcherTestHelpers.GetMergedRead(alignmentSet);
            Assert.Equal(expectedCalculatedCigar, mergedRead.CigarData.ToString());

            // -----------------------------------------------
            // XC tag is there on one read but not the other
            // -----------------------------------------------
            // XC tag should be ignored, and new cigar should be calculated
            read1.StitchedCigar         = null;
            read2_overlap.StitchedCigar = new CigarAlignment("9M1I");
            alignmentSet = new AlignmentSet(read1, read2_overlap);
            stitcher.TryStitch(alignmentSet);

            mergedRead = StitcherTestHelpers.GetMergedRead(alignmentSet);
            Assert.Equal(expectedCalculatedCigar, mergedRead.CigarData.ToString());

            read1.StitchedCigar         = new CigarAlignment("9M1I");
            read2_overlap.StitchedCigar = null;
            alignmentSet = new AlignmentSet(read1, read2_overlap);
            stitcher.TryStitch(alignmentSet);

            mergedRead = StitcherTestHelpers.GetMergedRead(alignmentSet);
            Assert.Equal(expectedCalculatedCigar, mergedRead.CigarData.ToString());

            // -----------------------------------------------
            // XC tag is not there
            // -----------------------------------------------
            // New cigar should be calculated
            read1.StitchedCigar         = null;
            read2_overlap.StitchedCigar = null;
            alignmentSet = new AlignmentSet(read1, read2_overlap);
            stitcher.TryStitch(alignmentSet);

            mergedRead = StitcherTestHelpers.GetMergedRead(alignmentSet);
            Assert.Equal(expectedCalculatedCigar, mergedRead.CigarData.ToString());
        }
예제 #10
0
        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);
        }
예제 #11
0
 private IAlignmentStitcher GetXCStitcher()
 {
     return(StitcherTestHelpers.GetStitcher(10, true));
 }
        public void CallSomaticVariants_MergeReadsWithInsertion_BoundaryTests()
        {
            //Migrated from old Pisces: Originally called CallSomaticVariants_MergeReadsWithInsertion_BoundaryTests

            // insertion at edge of read

            //0 1 2 3 - - - 4 5 6 7 8 9
            //- C A T A T A G G
            //- - - - A T A G G T A A

            var read1 = TestHelper.CreateRead("chr1",
                                              "CATATAGG",
                                              1,
                                              new CigarAlignment("3M3I2M"),
                                              new byte[8],
                                              4);

            var read2 = TestHelper.CreateRead("chr1",
                                              "ATAGGTAA",
                                              4,
                                              new CigarAlignment("3S5M"),
                                              new byte[8],
                                              1);

            TestSuccesfullyStitchedRead(read1, read2, 0, "3M3I5M", (mergedRead) =>
            {
                Assert.NotNull(mergedRead);
                Assert.Equal(mergedRead.Sequence, "CATATAGGTAA");
            });


            //0 1 2 3 - - - 4 5 6 7 8 9
            //- C A T A T A G G
            //- - - - - T A G G T A A

            read1 = TestHelper.CreateRead("chr1", "CATATAGG", 1, new CigarAlignment("3M3I2M"),
                                          new byte[8], 4);

            read2 = TestHelper.CreateRead("chr1", "TAGGTAA", 4, new CigarAlignment("2S5M"),
                                          new byte[8], 1);

            TestSuccesfullyStitchedRead(read1, read2, 0, "3M3I5M", (mergedRead) =>
            {
                Assert.NotNull(mergedRead);
                Assert.Equal(mergedRead.Sequence, "CATATAGGTAA");
            });

            // shouldnt be able to stitch soft clipped areas only if XC tag not provided
            //0 1 2 3 - - - 4 5 6 7 8 9
            //- C A T A T A G G
            //- - - - - T A G G T A A

            read1 = TestHelper.CreateRead("chr1", "CATATAGG", 1, new CigarAlignment("3M5S"),
                                          new byte[8], 4);

            read2 = TestHelper.CreateRead("chr1", "TAGGTAA", 4, new CigarAlignment("2S5M"),
                                          new byte[8], 1);

            StitcherTestHelpers.TestUnstitchableReads(read1, read2, 0, (unStitchableReads) =>
            {
                Assert.Equal(1, unStitchableReads.Count(x => StitcherTestHelpers.VerifyReadsEqual(read1, x)));
                Assert.Equal(1, unStitchableReads.Count(x => StitcherTestHelpers.VerifyReadsEqual(read2, x)));
            });
        }
        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);
            });
        }