Exemplo n.º 1
0
        public void Pisces_MergeReadsWithInsertionTests()
        {
            //Migrated from old Pisces: Originally called Pisces_MergeReadsWithInsertionTests

            var read1 = DomainTestHelper.CreateRead("chr1",
                                                    "GAAAATGTGCAGAAGAGGATAGGCAGAAACTCAAAAAAACATATAGACAATAACACCAGCACTCCTCCAAATTGCCCAATACTATATACTAAGATTTGTA",
                                                    115251051,
                                                    new CigarAlignment("25S7M1I67M"),
                                                    new byte[100],
                                                    110);

            var read2 = DomainTestHelper.CreateRead("chr1",
                                                    "AATTGCCCAATACTATATACTAAGATTTGTAATTATGCCAAGAAACCATATGCTCACCTTGTTACATCACCACACATGGCAATCCCATACAACCCTGAGT",
                                                    115251094,
                                                    new CigarAlignment("75M25S"),
                                                    new byte[100],
                                                    88);

            TestSuccesfullyStitchedRead(read1, read2, 0, "25S7M1I111M25S", (mergedRead) =>
            {
                Assert.NotNull(mergedRead);
                Assert.Equal(mergedRead.Sequence,
                             "GAAAATGTGCAGAAGAGGATAGGCAGAAACTCAAAAAAACATATAGACAATAACACCAGCACTCCTCCAAATTGCCCAATACTATATACTAAGATTTGTAATTATGCCAAGAAACCATATGCTCACCTTGTTACATCACCACACATGGCAATCCCATACAACCCTGAGT");
            });
        }
Exemplo n.º 2
0
        public void Constructor()
        {
            var read1        = DomainTestHelper.CreateRead("chr1", "ACT", 100);
            var read2        = DomainTestHelper.CreateRead("chr1", "TCCT", 200);
            var alignmentSet = new AlignmentSet(read1, read2);

            Assert.Equal(read1, alignmentSet.PartnerRead1);
            Assert.Equal(read2, alignmentSet.PartnerRead2);
            Assert.True(alignmentSet.IsFullPair);

            // read1 must be provided
            Assert.Throws <ArgumentException>(() => new AlignmentSet(null, read1));

            // allow single read
            alignmentSet = new AlignmentSet(read1, null);
            Assert.Equal(read1, alignmentSet.PartnerRead1);
            Assert.Equal(null, alignmentSet.PartnerRead2);
            Assert.False(alignmentSet.IsFullPair);

            // make sure reads are ordered
            alignmentSet = new AlignmentSet(read2, read1);
            Assert.Equal(read1, alignmentSet.PartnerRead1);
            Assert.Equal(read2, alignmentSet.PartnerRead2);
            Assert.True(alignmentSet.IsFullPair);
        }
Exemplo n.º 3
0
        public Read GetAlignmentWithCoverageDirections(int numForward, int numStitched, int numReverse, int deletionLength, bool isDuplex = false)
        {
            var read = DomainTestHelper.CreateRead("chr1", String.Concat(Enumerable.Repeat("A", numForward + numReverse + numStitched - deletionLength)), 1);

            read.SequencedBaseDirectionMap = GetCoverageDirections(numForward, numStitched, numReverse, deletionLength);
            read.IsDuplex = isDuplex;
            return(read);
        }
Exemplo n.º 4
0
        public static AlignmentSet GetOverlappingReadSet(bool withXCTag = false)
        {
            var read1 = DomainTestHelper.CreateRead("chr1", "ATCGATCG", 12345, new CigarAlignment("8M"), qualityForAll: 30);

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

            return(new AlignmentSet(read1, read2_overlap));
        }
Exemplo n.º 5
0
        public void GetMate()
        {
            var finder = new AlignmentMateFinder();

            var read1     = CreateAlignment(100, 500, "1");
            var read1Mate = CreateAlignment(500, 100, "1");
            var read2     = CreateAlignment(200, 400, "2");
            var read2Mate = CreateAlignment(400, 200, "2");
            var read3     = CreateAlignment(201, 600, "3");
            var read3Mate = CreateAlignment(600, 201, "3");
            var read4     = CreateAlignment(1000, 2000, "4");
            var read4Mate = CreateAlignment(2000, 1000, "4");
            var read5     = CreateAlignment(2500, 3501, "5");
            var read5Mate = CreateAlignment(3501, 2500, "5");

            Assert.Equal(finder.LastClearedPosition, null);
            Assert.Equal(finder.NextMatePosition, null);

            Assert.Equal(finder.GetMate(read1), null);
            Assert.Equal(finder.LastClearedPosition, 99);
            Assert.Equal(finder.NextMatePosition, 500);

            Assert.Equal(finder.GetMate(read2), null);
            Assert.Equal(finder.LastClearedPosition, 99);
            Assert.Equal(finder.NextMatePosition, 400);

            Assert.Equal(finder.GetMate(read3), null);
            Assert.Equal(finder.LastClearedPosition, 99);

            DomainTestHelper.CompareReads(finder.GetMate(read2Mate), read2);
            Assert.Equal(finder.LastClearedPosition, 99);
            Assert.Equal(finder.NextMatePosition, 500);

            DomainTestHelper.CompareReads(finder.GetMate(read1Mate), read1);
            Assert.Equal(finder.LastClearedPosition, 200);
            Assert.Equal(finder.NextMatePosition, 600);

            DomainTestHelper.CompareReads(finder.GetMate(read3Mate), read3);
            Assert.Equal(finder.LastClearedPosition, null);

            Assert.Equal(finder.GetMate(read4), null);
            Assert.Equal(finder.LastClearedPosition, 999);

            DomainTestHelper.CompareReads(finder.GetMate(read4Mate), read4);
            Assert.Equal(finder.LastClearedPosition, null);

            Assert.Equal(finder.GetMate(read5), null);
            Assert.Equal(finder.LastClearedPosition, 2499);

            Assert.Equal(finder.GetMate(read5Mate), null); // out of window gets tossed
            Assert.Equal(finder.LastClearedPosition, null);
            Assert.Equal(finder.NextMatePosition, null);
            Assert.Equal(2, finder.ReadsUnpairable);

            Assert.Throws <ArgumentException>(() => finder.GetMate(CreateAlignment(2500, 2500, null))); // null name
            Assert.Throws <ArgumentException>(() => finder.GetMate(CreateAlignment(2500, 2500, "")));   // empty name
            Assert.Throws <ArgumentException>(() => finder.GetMate(CreateAlignment(2500, -1, null)));   // invalid mate position
        }
Exemplo n.º 6
0
        public void Pisces_MergeBugExample()
        {
            //Migrated from old Pisces: Originally called Pisces_MergeBugExample

            //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 = DomainTestHelper.CreateRead("chr1",
                                                    "TAAAGGTTTTGCTATCGGCATGCCAGTGTGCGAATTTGATATGGTTAAAGATCCAGAAGTACAGGACTTCCGCAGAAATATTTTGAACGTTTGTAAAGAA",
                                                    178917497,
                                                    new CigarAlignment("25S75M"),
                                                    new byte[]
            {
                27, 28, 11, 28, 27, 29, 20, 20, 31, 31, 31, 31, 27, 27, 32, 31, 29, 34, 34, 29, 34, 11, 12, 12, 23, 12,
                23, 12, 23, 32, 13, 22, 10, 20, 10, 32, 36, 34, 28, 31, 13, 13, 24, 32, 24, 13, 24, 32, 31, 37, 36,
                12, 31, 12, 12, 12, 13, 12, 20, 12, 12, 32, 28, 12, 12, 20, 10, 20, 32, 20, 32, 10, 10, 20, 9, 9, 20,
                36, 12, 12, 12, 34, 12, 12, 23, 27, 32, 12, 23, 23, 23, 12, 20, 10, 11, 11, 28, 20, 34, 10
            },
                                                    178917546);

            var read2 = DomainTestHelper.CreateRead("chr1",
                                                    "GAAATATTCTGAACGTTTGTAAAGAAGCTGTGGATCTTAGGGACCTCAATTCACCTCATAGTAGAACAATGTATGTCTATCCTCCAAATGTAGAATCTTC",
                                                    178917546,
                                                    new CigarAlignment("71M29S"),
                                                    new byte[]
            {
                36, 33, 37, 37, 32, 14, 33, 36, 34, 32, 36, 23, 11, 20, 30, 35, 37, 35, 28, 38, 33, 30, 32, 12, 35, 39,
                37, 37, 36, 32, 32, 23, 14, 14, 32, 32, 37, 32, 23, 12, 30, 22, 23, 12, 32, 32, 14, 32, 15, 34, 30,
                22, 14, 36, 30, 34, 31, 39, 39, 39, 38, 39, 39, 38, 34, 36, 30, 34, 34, 30, 34, 34, 34, 32, 32, 33,
                34, 37, 37, 31, 36, 37, 30, 37, 33, 30, 33, 31, 33, 33, 33, 33, 33, 33, 33, 30, 30, 30, 30, 30
            },
                                                    178917497);

            //expected overlap
            //"TAAAG GTTTT GCTAT CGGCA TGCCA GTGTG CGAAT TTGAT ATGGT TAAAG ATCCA GAAGT ACAGG ACTTC CGCAG AAATA TTTTG AACGT TTGTA AAGAA";
            //                                                                                        "G AAATA TTCTG AACGT TTGTA AAGAA GCTGT GGATCTTAGGGACCTCAATTCACCTCATAGTAGAACAATGTATGTCTATCCTCCAAATGTAGAATCTTC";
            // 0     5     10    15    20    25    30    35    40    45    50    55    60     65   70    75


            TestSuccesfullyStitchedRead(read2, read1, 0, "25S120M29S", (mergedRead) =>
            {
                Assert.NotNull(mergedRead);

                Assert.Equal(mergedRead.Sequence, "TAAAGGTTTTGCTATCGGCATGCCAGTGTGCGAATTTGATATGGTTAAAGATCCAGAAGTACAGGACTTCCGCAGAAATATTNTGAACGTTTGTAAAGAAGCTGTGGATCTTAGGGACCTCAATTCACCTCATAGTAGAACAATGTATGTCTATCCTCCAAATGTAGAATCTTC");
                Assert.Equal(mergedRead.Qualities[0], (byte)27);
                Assert.Equal(mergedRead.Qualities[1], (byte)28);
                Assert.Equal(mergedRead.Qualities[2], (byte)11);

                //overlap is "G AAATA TTTTG AACGT TTGTA AAGAA", string at index 74
                byte r1 = read1.Qualities[74];
                byte r2 = read2.Qualities[0];
                Assert.Equal(mergedRead.Qualities[74], (byte)(Convert.ToInt32(r1) + Convert.ToInt32(r2)));
            }, true);
        }
Exemplo n.º 7
0
        public void TryStitch_SoftclipScenarios()
        {
            //Migrated from old Pisces: Originally called Pisces_MergeRead2First
            var sequence =
                "GG" + "GGCCACGCGGGGAGCAGCCTCTGGCATTCTGGGAGCTTCATCTGGACCTGGGTCTTCAGTGAACCATTGTTCAATATCGTCCGGGGACAGCATCAAATCATCCATTGCTTGGGACGGCAAGG" + "GGGACTGTAGATGGGTGAAAAGAGCA";

            var read1 = DomainTestHelper.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 = DomainTestHelper.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)
            TestSuccesfullyStitchedRead(read1, read2, 0, "22S122M26S", (mergedRead) =>
            {
                Assert.NotNull(mergedRead);
                Assert.Equal(expectedWithNoNify, mergedRead.Sequence);
            }, nifyDisagreements: false);
        }
Exemplo n.º 8
0
        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());
        }
Exemplo n.º 9
0
        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());
                }
            }
        }
Exemplo n.º 10
0
 private void AddReads(List <Read> readSets, int copies, int read1Position, string read1Sequence,
                       int read2Position, string read2Sequence)
 {
     for (var i = 0; i < copies; i++)
     {
         readSets.AddRange(new List <Read>()
         {
             DomainTestHelper.CreateRead(_chrName, read1Sequence, read1Position, new CigarAlignment("6M"),
                                         qualityForAll: 30),
             DomainTestHelper.CreateRead(_chrName, read2Sequence, read2Position, new CigarAlignment("6M"),
                                         qualityForAll: 30)
         }
                           );
     }
 }
Exemplo n.º 11
0
        public void Pisces_MergeReadsWithDeletionTests()
        {
            //Migrated from old Pisces: Originally called Pisces_MergeReadsWithDeletionTests

            var read1 = DomainTestHelper.CreateRead("chr1",
                                                    "GAAAATGTGCAGAAGAGGATAGGCAGAAACTCAAAAAACATATAGACAATAACACCAGCACTCCTCCAAATTGCCCAATACTATATACTAAGATTTGTAA",
                                                    115251051,
                                                    new CigarAlignment("25S75M"),
                                                    new byte[100],
                                                    110);

            var read2 = DomainTestHelper.CreateRead("chr1",
                                                    "CCAAATTGCCCAATACTATATACTAAGATTTGTAATTATGCCAAGAAACCATATGCTCACCTTGTTACATCACACATGGCAATCCCATACAACCCTGAGT",
                                                    115251091,
                                                    new CigarAlignment("70M3D5M25S"),
                                                    new byte[100],
                                                    88);

            var action = new Action <Read>((mergedRead1) =>
            {
                Assert.NotNull(mergedRead1);
                Assert.Equal(mergedRead1.Sequence,
                             "GAAAATGTGCAGAAGAGGATAGGCAGAAACTCAAAAAACATATAGACAATAACACCAGCACTCCTCCAAATTGCCCAATACTATATACTAAGATTTGTAATTATGCCAAGAAACCATATGCTCACCTTGTTACATCACACATGGCAATCCCATACAACCCTGAGT");
            });

            TestSuccesfullyStitchedRead(read1, read2, 0, "25S110M3D5M25S", action);


            read1 = DomainTestHelper.CreateRead("chr1",
                                                "GAAAATGTGCAGAAGAGGATAGGCAGAAACTCAAAAAACATATAGACAATAACACCAGCACTCCTCCAAATTGCCCAATACTATATACTAAGATTTGTAA",
                                                115251051,
                                                new CigarAlignment("25S75M"),
                                                new byte[100],
                                                110);

            read2 = DomainTestHelper.CreateRead("chr1",
                                                "CCAAATTGCCCAATACTATATACTAAGATTTGTAATTATGCCAAGAAACCATATGCTCACCTTGTTACATCACACATGGCAATCCCATACAACCCTGAGT",
                                                115251091,
                                                new CigarAlignment("70M3D5M25S"),
                                                new byte[100],
                                                88);

            TestSuccesfullyStitchedRead(read2, read1, 0, "25S110M3D5M25S", action);
        }
Exemplo n.º 12
0
        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());
        }
Exemplo n.º 13
0
        public void ReadCollapsedCounts()
        {
            var alignment = new BamAlignment
            {
                Bases        = "ACTC",
                Position     = 5,
                MapQuality   = 343,
                MatePosition = 12312,
                Qualities    = new[] { (byte)20, (byte)21, (byte)30, (byte)40 },
                CigarData    = new CigarAlignment("1S3M")
            };

            alignment.TagData = DomainTestHelper.GetReadCountsTagData(5, 10);
            var read = new Read("chr1", alignment);

            Assert.True(read.IsDuplex);

            alignment.TagData = DomainTestHelper.GetReadCountsTagData(0, 5);  // first tag is 0
            read = new Read("chr1", alignment);
            Assert.False(read.IsDuplex);

            alignment.TagData = DomainTestHelper.GetReadCountsTagData(null, 5);  // first tag is missing
            read = new Read("chr1", alignment);
            Assert.False(read.IsDuplex);

            alignment.TagData = DomainTestHelper.GetReadCountsTagData(5, 0);  // second tag is 0
            read = new Read("chr1", alignment);
            Assert.False(read.IsDuplex);

            alignment.TagData = DomainTestHelper.GetReadCountsTagData(5, null);  // second tag is missing
            read = new Read("chr1", alignment);
            Assert.False(read.IsDuplex);

            alignment.TagData = DomainTestHelper.GetReadCountsTagData(0, 0);  // both tags 0
            read = new Read("chr1", alignment);
            Assert.False(read.IsDuplex);

            alignment.TagData = DomainTestHelper.GetReadCountsTagData(null, null);  // both tags missing
            read = new Read("chr1", alignment);
            Assert.False(read.IsDuplex);
        }
Exemplo n.º 14
0
        public void Reset()
        {
            var alignment = new BamAlignment
            {
                Bases        = "ACTC",
                Position     = 5,
                MapQuality   = 343,
                MatePosition = 12312,
                Qualities    = new[] { (byte)20, (byte)21, (byte)30, (byte)40 },
                CigarData    = new CigarAlignment("1S3M")
            };

            alignment.SetIsUnmapped(false);
            alignment.SetIsSecondaryAlignment(false);
            alignment.SetIsDuplicate(true);
            alignment.SetIsProperPair(true);

            var read = new Read("chr1", alignment);

            read.StitchedCigar             = new CigarAlignment("7M");
            read.SequencedBaseDirectionMap = new[] { DirectionType.Forward, DirectionType.Reverse, DirectionType.Stitched, DirectionType.Reverse };

            alignment.SetIsDuplicate(false);
            alignment.MatePosition = 555;

            read.Reset("chr2", alignment);
            Assert.Equal(556, read.MatePosition);
            Assert.False(read.IsPcrDuplicate);
            Assert.Equal("chr2", read.Chromosome);

            var stitchedCigar = "1S3M1S";

            alignment.TagData = DomainTestHelper.GetXCTagData(stitchedCigar);
            read.Reset("chr3", alignment);
            Assert.Equal(556, read.MatePosition);
            Assert.False(read.IsPcrDuplicate);
            Assert.Equal("chr3", read.Chromosome);
            Assert.Equal(stitchedCigar, read.StitchedCigar.ToString());
        }
Exemplo n.º 15
0
        public void BamAlignment_Constructor()
        {
            //Happy Path
            var alignment = new BamAlignment
            {
                AlignmentFlag  = 1,
                Bases          = "AGGGGGGGGTTTTTTCACACACA",
                Bin            = 3,
                CigarData      = new CigarAlignment("11M5I9M7D25M"),
                FragmentLength = 9,
                MapQuality     = 50,
                MatePosition   = 5,
                MateRefID      = 5,
                RefID          = 1,
                Name           = "test",
                Position       = 11,
                TagData        = DomainTestHelper.GetXCTagData("11M5I9M7D25M"),
                Qualities      = new byte[] { 10, 30, 50 },
            };

            var newAlignment = new BamAlignment(alignment);

            Assert.Equal(alignment.AlignmentFlag, newAlignment.AlignmentFlag);
            Assert.Equal(alignment.Bases, newAlignment.Bases);
            Assert.Equal(alignment.Bin, newAlignment.Bin);
            Assert.Equal(alignment.CigarData, newAlignment.CigarData);
            Assert.Equal(alignment.FragmentLength, newAlignment.FragmentLength);
            Assert.Equal(alignment.MapQuality, newAlignment.MapQuality);
            Assert.Equal(alignment.MateRefID, newAlignment.MateRefID);
            Assert.Equal(alignment.MatePosition, newAlignment.MatePosition);
            Assert.Equal(alignment.RefID, newAlignment.RefID);
            Assert.Equal(alignment.Name, newAlignment.Name);
            Assert.Equal(alignment.Position, newAlignment.Position);
            Assert.Equal(alignment.Qualities, newAlignment.Qualities);
            Assert.Equal(alignment.TagData, newAlignment.TagData);
            Assert.Equal(alignment.Qualities, newAlignment.Qualities);
        }
Exemplo n.º 16
0
        public Tuple <BamAlignment, BamAlignment> CreateNewReads(int readLength, string stitchedCigar, string sequence)
        {
            var reverseCigar = TestHelper.GetReadCigarFromStitched(stitchedCigar, readLength, true);
            var reversePos   = ChrOffset + (int)new CigarAlignment(stitchedCigar).GetReferenceSpan() - (int)reverseCigar.GetReferenceSpan();

            var read1 = new BamAlignment()
            {
                RefID      = 1,
                Position   = ChrOffset,
                CigarData  = TestHelper.GetReadCigarFromStitched(stitchedCigar, readLength, false),
                Bases      = sequence.Substring(0, readLength),
                TagData    = DomainTestHelper.GetXCTagData(stitchedCigar),
                Qualities  = new byte[readLength],
                MapQuality = 50
            };

            var read2 = new BamAlignment()
            {
                RefID      = 1,
                Position   = reversePos,
                CigarData  = reverseCigar,
                Bases      = sequence.Substring(sequence.Length - readLength),
                TagData    = DomainTestHelper.GetXCTagData(stitchedCigar),
                Qualities  = new byte[readLength],
                MapQuality = 50
            };

            for (int i = 0; i < read1.Qualities.Length; i++)
            {
                read1.Qualities[i] = 30;
                read2.Qualities[i] = 30;
            }

            SetPairedEndAttributes(read1, read2);

            return(new Tuple <BamAlignment, BamAlignment>(read1, read2));
        }
Exemplo n.º 17
0
        public void DeepCopy()
        {
            var alignment = new BamAlignment
            {
                Bases        = "ACTC",
                Position     = 5,
                MapQuality   = 343,
                MatePosition = 12312,
                Qualities    = new[] { (byte)20, (byte)21, (byte)30, (byte)40 },
                CigarData    = new CigarAlignment("1S3M")
            };

            alignment.SetIsUnmapped(false);
            alignment.SetIsSecondaryAlignment(false);
            alignment.SetIsDuplicate(true);
            alignment.SetIsProperPair(true);

            var read = new Read("chr1", alignment);

            read.StitchedCigar             = new CigarAlignment("7M");
            read.SequencedBaseDirectionMap = new[] { DirectionType.Forward, DirectionType.Reverse, DirectionType.Stitched, DirectionType.Reverse };
            var clonedRead = read.DeepCopy();

            DomainTestHelper.CompareReads(read, clonedRead);

            // verify the arrays are deep copies
            read.PositionMap[0] = 1000;
            Assert.False(clonedRead.PositionMap[0] == 1000);
            read.SequencedBaseDirectionMap[0] = DirectionType.Stitched;
            Assert.False(clonedRead.SequencedBaseDirectionMap[0] == DirectionType.Stitched);
            read.Qualities[0] = 11;
            Assert.False(clonedRead.Qualities[0] == 11);

            read.CigarData.Reverse();
            Assert.False(((Read)clonedRead).CigarData.ToString() == read.CigarData.ToString());
        }
Exemplo n.º 18
0
        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));
        }
Exemplo n.º 19
0
        public void CigarData()
        {
            var read = DomainTestHelper.CreateRead("chr4", "ACCGACTAAC", 4, new CigarAlignment("10M"));

            Verify(new[] { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }, read.PositionMap);

            read = DomainTestHelper.CreateRead("chr4", "ACCGACTAAC", 4, new CigarAlignment("2S1M4I5D2M1S"));
            Verify(new[] { -1, -1, 4, -1, -1, -1, -1, 10, 11, -1 }, read.PositionMap);

            read = DomainTestHelper.CreateRead("chr1", "ACTTCCCAAAAT", 100, new CigarAlignment("12M"));

            for (var i = 0; i < read.PositionMap.Length; i++)
            {
                Assert.Equal(read.PositionMap[i], read.Position + i);
            }

            read = DomainTestHelper.CreateRead("chr1", "ACTTCCCAAAAT", 100, new CigarAlignment("2S5M4I10D1M"));
            Verify(new[]
            {
                -1, -1, 100, 101, 102, 103, 104, -1, -1, -1, -1, 115
            }, read.PositionMap);

            Assert.Throws <Exception>(() => DomainTestHelper.CreateRead("chr1", "ACTTCCCAAAAT", 100, new CigarAlignment("100M")));
        }
Exemplo n.º 20
0
        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 = DomainTestHelper.CreateRead("chr1", "CATAT", 1, new CigarAlignment("5M"), new byte[] { 1, 2, 3, 4, 5 }, 4);

            StitcherTestHelpers.SetReadDirections(read1, DirectionType.Forward);

            var read2 = DomainTestHelper.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 = DomainTestHelper.CreateRead("chr1", "CATAG", 1, new CigarAlignment("5M"), new byte[] { 1, 2, 3, 4, 5 }, 4);
            StitcherTestHelpers.SetReadDirections(read1, DirectionType.Reverse);

            read2 = DomainTestHelper.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 = DomainTestHelper.CreateRead("chr1", "CATAG", 1, new CigarAlignment("5M"), new byte[] { 100, 200, 200, 200, 200 }, 4);
            read2 = DomainTestHelper.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, 201, 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());
            }, true);
        }
Exemplo n.º 21
0
        public void AddAndGetAlleleCounts_Deletions()
        {
            // make sure deletions get padded
            int minQuality = 25;

            var stateManager = new RegionStateManager(false, minQuality);

            var alignmentSet = TestHelper.CreateTestReads(
                DomainTestHelper.CreateRead("chr1", "TTTTTTTTT", 1001, new CigarAlignment("5M4D4M")),              // forward counts for 1001 - 1013
                DomainTestHelper.CreateRead("chr1", "AAAAAAAAA", 1005, new CigarAlignment("1M2D8M")), minQuality); // reverse counts for 1005 - 1115

            var read1 = alignmentSet[0];
            var read2 = alignmentSet[1];

            for (var i = 0; i < read2.SequencedBaseDirectionMap.Length; i++)
            {
                read2.SequencedBaseDirectionMap[i] = DirectionType.Reverse;
            }

            foreach (var read in alignmentSet)
            {
                stateManager.AddAlleleCounts(read);
            }

            // check T counts
            Assert.Equal(stateManager.GetAlleleCount(1000, AlleleType.T, DirectionType.Forward), 0);
            for (int i = 1001; i <= 1013; i++)
            {
                var alleleType = i >= 1006 && i <= 1009 ? AlleleType.Deletion : AlleleType.T;
                Assert.Equal(stateManager.GetAlleleCount(i, alleleType, DirectionType.Forward), 1);
            }
            Assert.Equal(stateManager.GetAlleleCount(1014, AlleleType.T, DirectionType.Forward), 0);

            // check A counts
            Assert.Equal(stateManager.GetAlleleCount(1004, AlleleType.A, DirectionType.Reverse), 0);
            for (int i = 1005; i <= 1015; i++)
            {
                var alleleType = i >= 1006 && i <= 1007 ? AlleleType.Deletion : AlleleType.A;
                Assert.Equal(stateManager.GetAlleleCount(i, alleleType, DirectionType.Reverse), 1);
            }
            Assert.Equal(stateManager.GetAlleleCount(1116, AlleleType.A, DirectionType.Reverse), 0);

            // ---------------------------------------
            // Read beginning with deletion
            // ---------------------------------------
            var alignmentSet_frontEdge = TestHelper.CreateTestReads(
                DomainTestHelper.CreateRead("chr1", "NNNNNTTTT", 1001, new CigarAlignment("5S2D4M")),
                DomainTestHelper.CreateRead("chr1", "AAAAAAAAA", 1005, new CigarAlignment("9M")), minQuality);

            stateManager = new RegionStateManager(false, minQuality);
            var frontRead1 = alignmentSet_frontEdge[0];
            var frontRead2 = alignmentSet_frontEdge[1];

            foreach (var read in alignmentSet_frontEdge)
            {
                stateManager.AddAlleleCounts(read);
            }

            // check T counts
            Assert.Equal(stateManager.GetAlleleCount(1000, AlleleType.T, DirectionType.Forward), 0);
            var lengthRef = ((Read)frontRead1).CigarData.GetReferenceSpan();

            for (int i = 1001; i < 1001 + lengthRef - 1; i++)
            {
                var alleleType = i >= 1001 && i <= 1002 ? AlleleType.Deletion : AlleleType.T;
                Assert.Equal(stateManager.GetAlleleCount(i, alleleType, DirectionType.Forward), 1);
            }
            Assert.Equal(stateManager.GetAlleleCount(1014, AlleleType.T, DirectionType.Forward), 0);

            // ---------------------------------------
            // Terminal deletions
            // ---------------------------------------
            var alignmentSet_tailEdge = TestHelper.CreateTestReads(
                DomainTestHelper.CreateRead("chr1", "TTTTNNNNN", 1001, new CigarAlignment("4M2D5S")),
                DomainTestHelper.CreateRead("chr1", "AAAAAAAAA", 1015, new CigarAlignment("9M2D")), minQuality);

            var tailRead1 = alignmentSet_tailEdge[0];
            var tailRead2 = alignmentSet_tailEdge[1];

            stateManager = new RegionStateManager(false, minQuality);

            for (var i = 0; i < tailRead2.SequencedBaseDirectionMap.Length; i++)
            {
                tailRead2.SequencedBaseDirectionMap[i] = DirectionType.Reverse;
            }

            foreach (var read in alignmentSet_tailEdge)
            {
                stateManager.AddAlleleCounts(read);
            }

            // check T counts
            Assert.Equal(stateManager.GetAlleleCount(1000, AlleleType.T, DirectionType.Forward), 0);
            lengthRef = ((Read)tailRead1).CigarData.GetReferenceSpan();
            var lastPos = 1001 + lengthRef - 1;

            for (int i = 1001; i <= lastPos; i++)
            {
                var alleleType = i >= 1005 && i <= lastPos ? AlleleType.Deletion : AlleleType.T;
                Assert.Equal(stateManager.GetAlleleCount(i, alleleType, DirectionType.Forward), 1);
            }
            Assert.Equal(stateManager.GetAlleleCount((int)lastPos + 1, AlleleType.Deletion, DirectionType.Forward), 0);

            // check A counts
            Assert.Equal(stateManager.GetAlleleCount(1014, AlleleType.A, DirectionType.Reverse), 0);
            lengthRef = ((Read)tailRead2).CigarData.GetReferenceSpan();
            lastPos   = 1015 + lengthRef - 1;
            for (int i = 1015; i <= lastPos; i++)
            {
                var alleleType = i >= 1024 && i <= lastPos ? AlleleType.Deletion : AlleleType.A;
                Assert.Equal(stateManager.GetAlleleCount(i, alleleType, DirectionType.Reverse), 1);
            }
            Assert.Equal(stateManager.GetAlleleCount((int)lastPos + 1, AlleleType.Deletion, DirectionType.Reverse), 0);
        }
Exemplo n.º 22
0
        public void AddAndGetAlleleCounts()
        {
            int minQuality = 25;

            var stateManager = new RegionStateManager(false, minQuality);

            var reads = TestHelper.CreateTestReads(
                DomainTestHelper.CreateRead("chr1", "ACTGGCATC", 1001),
                DomainTestHelper.CreateRead("chr1", "TCTGCCACT", 1005), minQuality).ToList();
            var read1 = reads[0];
            var read2 = reads[1];

            for (var i = 0; i < read2.SequencedBaseDirectionMap.Length; i++)
            {
                read2.SequencedBaseDirectionMap[i] = DirectionType.Reverse;
            }
            read2.PositionMap[7] = -1;

            var reads2 = TestHelper.CreateTestReads(
                DomainTestHelper.CreateRead("chr1", "ACAC", 999), DomainTestHelper.CreateRead("chr1", "ACAC", 999), minQuality).ToList();
            var secondRead1 = reads2[0];
            var secondRead2 = reads2[1];

            for (var i = 0; i < secondRead1.SequencedBaseDirectionMap.Length; i++)
            {
                secondRead1.SequencedBaseDirectionMap[i] = DirectionType.Stitched;
            }

            foreach (var read in reads)
            {
                stateManager.AddAlleleCounts(read);
            }
            foreach (var read in reads2)
            {
                stateManager.AddAlleleCounts(read);
            }

            Assert.Equal(stateManager.GetAlleleCount(1004, AlleleType.G, DirectionType.Forward), 1);
            Assert.Equal(stateManager.GetAlleleCount(1005, AlleleType.G, DirectionType.Forward), 1);
            Assert.Equal(stateManager.GetAlleleCount(1005, AlleleType.T, DirectionType.Reverse), 1);
            Assert.Equal(stateManager.GetAlleleCount(1006, AlleleType.C, DirectionType.Forward), 1);
            Assert.Equal(stateManager.GetAlleleCount(1006, AlleleType.C, DirectionType.Reverse), 1);
            Assert.Equal(stateManager.GetAlleleCount(1007, AlleleType.A, DirectionType.Forward), 1);
            Assert.Equal(stateManager.GetAlleleCount(1007, AlleleType.T, DirectionType.Reverse), 1);
            Assert.Equal(stateManager.GetAlleleCount(1008, AlleleType.T, DirectionType.Forward), 1);
            Assert.Equal(stateManager.GetAlleleCount(1008, AlleleType.G, DirectionType.Reverse), 1);
            Assert.Equal(stateManager.GetAlleleCount(1009, AlleleType.C, DirectionType.Forward), 1);
            Assert.Equal(stateManager.GetAlleleCount(1009, AlleleType.C, DirectionType.Reverse), 1);
            Assert.Equal(stateManager.GetAlleleCount(1010, AlleleType.C, DirectionType.Reverse), 1);
            Assert.Equal(stateManager.GetAlleleCount(1012, AlleleType.C, DirectionType.Reverse), 0); // not mapped to reference

            Assert.Equal(stateManager.GetAlleleCount(999, AlleleType.A, DirectionType.Stitched), 1);
            Assert.Equal(stateManager.GetAlleleCount(1000, AlleleType.C, DirectionType.Stitched), 1);
            Assert.Equal(stateManager.GetAlleleCount(1001, AlleleType.A, DirectionType.Stitched), 1);
            Assert.Equal(stateManager.GetAlleleCount(1002, AlleleType.C, DirectionType.Stitched), 1);
            Assert.Equal(stateManager.GetAlleleCount(1001, AlleleType.A, DirectionType.Forward), 2);
            Assert.Equal(stateManager.GetAlleleCount(1002, AlleleType.C, DirectionType.Forward), 2);

            // error conditions
            Assert.Throws <ArgumentException>(() => stateManager.GetAlleleCount(0, AlleleType.A, DirectionType.Forward));

            //allow some funky ref bases. just treat as N
            //var badAlignmentSet = TestHelper.CreateTestReads(DomainTestHelper.CreateRead("chr1", "ACE", 999), minQuality);
            //Assert.Throws<ArgumentException>(() => stateManager.AddAlleleCounts(badAlignmentSet));

            // ---------------------------------------
            // no calls and low quality bases should map to allele type N
            // ---------------------------------------
            var noCallAlignment = TestHelper.CreateTestReads(DomainTestHelper.CreateRead("chr1", "NNAC", 999), minQuality);

            noCallAlignment[0].Qualities[2] = (byte)(minQuality - 1);
            noCallAlignment[0].Qualities[3] = (byte)(minQuality - 1);

            foreach (var read in noCallAlignment)
            {
                stateManager.AddAlleleCounts(read);
            }

            // make sure no calls logged
            Assert.Equal(stateManager.GetAlleleCount(999, AlleleType.N, DirectionType.Forward), 1);
            Assert.Equal(stateManager.GetAlleleCount(1000, AlleleType.N, DirectionType.Forward), 1);
            Assert.Equal(stateManager.GetAlleleCount(1001, AlleleType.N, DirectionType.Forward), 1);
            // make sure remaining didnt change
            Assert.Equal(stateManager.GetAlleleCount(999, AlleleType.A, DirectionType.Stitched), 1);
            Assert.Equal(stateManager.GetAlleleCount(1000, AlleleType.C, DirectionType.Stitched), 1);
            Assert.Equal(stateManager.GetAlleleCount(1001, AlleleType.A, DirectionType.Stitched), 1);
            Assert.Equal(stateManager.GetAlleleCount(1002, AlleleType.C, DirectionType.Stitched), 1);
            Assert.Equal(stateManager.GetAlleleCount(1001, AlleleType.A, DirectionType.Forward), 2);
            Assert.Equal(stateManager.GetAlleleCount(1002, AlleleType.C, DirectionType.Forward), 2);
        }
Exemplo n.º 23
0
        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);
        }
Exemplo n.º 24
0
        //[Fact] //TODO
        //This is currently expected to fail.
        //Because we now allow to stitch between softclips.
        //We should adjust this this unit test, or otherwise clarify the expectation.
        public void Pisces_MergeReadsWithInsertion_BoundaryTests()
        {
            //Migrated from old Pisces: Originally called Pisces_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 = DomainTestHelper.CreateRead("chr1",
                                                    "CATATAGG",
                                                    1,
                                                    new CigarAlignment("3M3I2M"),
                                                    new byte[8],
                                                    4);

            var read2 = DomainTestHelper.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 = DomainTestHelper.CreateRead("chr1", "CATATAGG", 1, new CigarAlignment("3M3I2M"),
                                                new byte[8], 4);

            read2 = DomainTestHelper.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");
            });

            // TODO - Currently, we are allowing stitching over softclips. Should we really disallow this?
            // TJD: Yes. But lets explictly turn of "usesoftclippedreads" for this test.
            // GB: I am now having trouble understanding why stitching should fail here. I believe UseSoftclippedReads just refers to whether the softclips can contribute to direction.
            //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  -- Looks like this if we knew it was an insertion...
            //- - T A G G T A A  -- Really looks like this...

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

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

            // Allow using softclipped bases: should take the CAT and the GGTAA
            TestSuccesfullyStitchedRead(read1, read2, 0, "8M", (mergedRead) =>
            {
                Assert.NotNull(mergedRead);
                Assert.Equal("1F7S", mergedRead.CigarDirections.ToString());
                Assert.Equal("CATATAGG", mergedRead.Sequence); // For stitched sites (all but the first), if disagreement, takes R1's
            });

            // Allow using softclipped bases and nifying: should take the C and the rest are Ns
            TestSuccesfullyStitchedRead(read1, read2, 0, "8M", (mergedRead) =>
            {
                Assert.NotNull(mergedRead);
                Assert.Equal("1F7S", mergedRead.CigarDirections.ToString());
                Assert.Equal("CNNNNNNN", mergedRead.Sequence); // For stitched sites (all but the first), if disagreement, takes R1's
            }, nifyDisagreements: true);

            // Not using softclipped bases: should take the first 3 from R1 and rest from R2.
            TestSuccesfullyStitchedRead(read1, read2, 0, "8M", (mergedRead) =>
            {
                Assert.NotNull(mergedRead);
                Assert.Equal("3F5R", mergedRead.CigarDirections.ToString());
                Assert.Equal("CATGGTAA", mergedRead.Sequence); // No stitched sites. Just take R1 first 3 and R2 for the last 5
            }, useSoftclippedBases: false);

            //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)));
            //},
            //false);
        }
Exemplo n.º 25
0
        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());
        }
Exemplo n.º 26
0
        private MockFactoryWithDefaults GetMockedFlowFactory(int numIterations)
        {
            var currentIteration = 0;

            var factory = new MockFactoryWithDefaults(new ApplicationOptions());

            // alignment source
            var mockAlignmentSource = new Mock <IAlignmentSource>();

            mockAlignmentSource.Setup(s => s.GetNextRead()).Returns(() =>
                                                                    currentIteration < numIterations ? DomainTestHelper.CreateRead(_chrReference.Name, "AAA", 1 + currentIteration++) : null);
            mockAlignmentSource.Setup(s => s.LastClearedPosition).Returns(() => currentIteration);
            factory.MockAlignmentSource = mockAlignmentSource;

            // state manager
            _candidateList = new List <CandidateAllele>()
            {
                new CandidateAllele("chr1", 100, "A", "G", AlleleCategory.Snv)
            };
            _batch = new CandidateBatch(_candidateList);

            var mockStateManager = new Mock <IStateManager>();

            mockStateManager.Setup(s => s.GetCandidatesToProcess(It.IsAny <int?>(), _chrReference)).Returns(_batch);
            factory.MockStateManager = mockStateManager;

            // variant finder
            var mockVariantFinder = new Mock <ICandidateVariantFinder>();

            mockVariantFinder.Setup(v => v.FindCandidates(It.IsAny <Read>(), _chrReference.Sequence, _chrReference.Name)).Returns(_candidateList);
            factory.MockVariantFinder = mockVariantFinder;

            // variant caller
            var mockVariantCaller = new Mock <IAlleleCaller>();

            mockVariantCaller.Setup(v => v.Call(_batch, mockStateManager.Object)).Returns(_calledList);
            factory.MockVariantCaller = mockVariantCaller;

            // region mapper
            var mockRegionMapper = new Mock <IRegionMapper>();

            factory.MockRegionMapper = mockRegionMapper;

            return(factory);
        }
Exemplo n.º 27
0
        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)));
            });
        }
Exemplo n.º 28
0
        public void DoneProcessing()
        {
            var stateManager = new RegionStateManager();
            var readLists    = new List <List <Read> >
            {
                TestHelper.CreateTestReads(DomainTestHelper.CreateRead("chr1", "A", 1)),    // 1-1000
                TestHelper.CreateTestReads(DomainTestHelper.CreateRead("chr1", "A", 1001)), // 1001-2000
                TestHelper.CreateTestReads(DomainTestHelper.CreateRead("chr1", "A", 2001)), // 2001-3000
                TestHelper.CreateTestReads(DomainTestHelper.CreateRead("chr1", "A", 3001)), // 2001-3000
                TestHelper.CreateTestReads(DomainTestHelper.CreateRead("chr1", "A", 5001)), // 5001-6000
                TestHelper.CreateTestReads(DomainTestHelper.CreateRead("chr1", "A", 7001))  // 7001-8000
            };

            foreach (var readList in readLists)
            {
                foreach (var read in readList)
                {
                    stateManager.AddAlleleCounts(read);
                }
            }

            // blocks should all be in memory
            Assert.Equal(1, stateManager.GetAlleleCount(1, AlleleType.A, DirectionType.Forward));
            Assert.Equal(1, stateManager.GetAlleleCount(1001, AlleleType.A, DirectionType.Forward));
            Assert.Equal(1, stateManager.GetAlleleCount(2001, AlleleType.A, DirectionType.Forward));
            Assert.Equal(1, stateManager.GetAlleleCount(3001, AlleleType.A, DirectionType.Forward));
            Assert.Equal(1, stateManager.GetAlleleCount(5001, AlleleType.A, DirectionType.Forward));
            Assert.Equal(1, stateManager.GetAlleleCount(7001, AlleleType.A, DirectionType.Forward));

            stateManager.AddCandidates(new List <CandidateAllele>()
            {
                new CandidateAllele("chr1", 1, "T", "A", AlleleCategory.Snv),
                new CandidateAllele("chr1", 3001, new string('A', 3500), "A", AlleleCategory.Deletion)
            });

            var batch = stateManager.GetCandidatesToProcess(1);

            stateManager.DoneProcessing(batch);
            Assert.Equal(1, stateManager.GetAlleleCount(1, AlleleType.A, DirectionType.Forward));

            batch = stateManager.GetCandidatesToProcess(1500);
            stateManager.DoneProcessing(batch);
            Assert.Equal(0, stateManager.GetAlleleCount(1, AlleleType.A, DirectionType.Forward));

            batch = stateManager.GetCandidatesToProcess(2001);
            stateManager.DoneProcessing(batch);
            Assert.Equal(0, stateManager.GetAlleleCount(1001, AlleleType.A, DirectionType.Forward));
            Assert.Equal(1, stateManager.GetAlleleCount(2001, AlleleType.A, DirectionType.Forward));

            // blocks 1001-2000 and 2001-3000 should be cleared
            batch = stateManager.GetCandidatesToProcess(5500);
            stateManager.DoneProcessing(batch);
            Assert.Equal(0, stateManager.GetAlleleCount(1, AlleleType.A, DirectionType.Forward));
            Assert.Equal(0, stateManager.GetAlleleCount(2001, AlleleType.A, DirectionType.Forward));
            //3001 block shouldn't be cleared yet because it holds a variant that extends into a further block
            Assert.Equal(1, stateManager.GetAlleleCount(3001, AlleleType.A, DirectionType.Forward));
            //5001 block shouldn't be cleared yet because it comes later than a held-up block
            Assert.Equal(1, stateManager.GetAlleleCount(5001, AlleleType.A, DirectionType.Forward));

            batch = stateManager.GetCandidatesToProcess(6500);
            stateManager.DoneProcessing(batch);
            //3001 block shouldn't be cleared yet because it holds a variant that extends into a further block
            Assert.Equal(1, stateManager.GetAlleleCount(3001, AlleleType.A, DirectionType.Forward));
            //5001 block shouldn't be cleared yet because it comes later than a held-up block
            Assert.Equal(1, stateManager.GetAlleleCount(5001, AlleleType.A, DirectionType.Forward));

            batch = stateManager.GetCandidatesToProcess(7001);
            stateManager.DoneProcessing(batch);
            Assert.Equal(0, stateManager.GetAlleleCount(3001, AlleleType.A, DirectionType.Forward));
            Assert.Equal(0, stateManager.GetAlleleCount(5001, AlleleType.A, DirectionType.Forward));
            Assert.Equal(1, stateManager.GetAlleleCount(7001, AlleleType.A, DirectionType.Forward));

            batch = stateManager.GetCandidatesToProcess(8001);
            stateManager.DoneProcessing(batch);
            Assert.Equal(0, stateManager.GetAlleleCount(7001, AlleleType.A, DirectionType.Forward));
        }
Exemplo n.º 29
0
        public static Read CreateRead(string cigarString, string bases, byte[] readQualities, int readStartPos)
        {
            var read = DomainTestHelper.CreateRead("chr1", bases, readStartPos, new CigarAlignment(cigarString), readQualities);

            return(read);
        }