public void IsDuplicate()
        {
            var duplicateIdentifier = new AlignmentFlagDuplicateIdentifier();

            var alignment = new BamAlignment();

            alignment.SetIsDuplicate(true);

            Assert.True(duplicateIdentifier.IsDuplicate(alignment));

            alignment.SetIsDuplicate(false);
            Assert.False(duplicateIdentifier.IsDuplicate(alignment));
        }
Beispiel #2
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());
        }
Beispiel #3
0
        private Read CreateRead(string chr, string sequence, int position, string name, bool isMapped = true,
                                bool isPrimaryAlignment = true, bool isProperPair = true, bool isDuplicate = false, int mapQuality = 10, bool addCigarData = true)
        {
            var alignment = new BamAlignment()
            {
                Bases = sequence, Position = position, Name = name, MapQuality = (uint)mapQuality
            };

            alignment.SetIsUnmapped(!isMapped);
            alignment.SetIsSecondaryAlignment(!isPrimaryAlignment);
            alignment.SetIsDuplicate(isDuplicate);
            alignment.SetIsProperPair(isProperPair);
            if (addCigarData)
            {
                alignment.CigarData = new CigarAlignment(sequence.Length + "M");
            }
            return(new Read(chr, alignment));
        }
Beispiel #4
0
        public void FromBam()
        {
            var alignment = new BamAlignment
            {
                Bases        = "ATCTTA",
                Position     = 100,
                MatePosition = 500,
                Name         = "test",
                CigarData    = new CigarAlignment("5M1S"),
                MapQuality   = 10,
                Qualities    = new[] { (byte)10, (byte)20, (byte)30 }
            };

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

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

            Assert.Equal(read.Chromosome, "chr1");
            Assert.Equal(read.Sequence, alignment.Bases);
            Assert.Equal(read.Position, alignment.Position + 1);
            Assert.Equal(read.MatePosition, alignment.MatePosition + 1);
            Assert.Equal(read.Name, alignment.Name);
            Assert.Equal(read.CigarData, alignment.CigarData);
            Assert.Equal(read.IsMapped, alignment.IsMapped());
            Assert.Equal(read.IsProperPair, alignment.IsProperPair());
            Assert.Equal(read.IsPrimaryAlignment, alignment.IsPrimaryAlignment());
            Assert.Equal(read.IsPcrDuplicate, alignment.IsDuplicate());

            foreach (var direction in read.SequencedBaseDirectionMap)
            {
                Assert.Equal(direction, DirectionType.Forward);
            }

            for (var i = 0; i < read.Qualities.Length; i++)
            {
                Assert.Equal(read.Qualities[i], alignment.Qualities[i]);
            }
        }
Beispiel #5
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());
        }
Beispiel #6
0
        public void BamAlignmentFlag_Setter_Tests()
        {
            var alignment = new BamAlignment();

            //Set Failed QC
            alignment.SetIsFailedQC(true);
            Assert.Equal((uint)512, alignment.AlignmentFlag);
            alignment.SetIsFailedQC(false);
            Assert.Equal((uint)0, alignment.AlignmentFlag);

            //Set Mate Unmapped
            alignment.SetIsMateUnmapped(true);
            Assert.Equal((uint)8, alignment.AlignmentFlag);
            alignment.SetIsMateUnmapped(false);
            Assert.Equal((uint)0, alignment.AlignmentFlag);

            //Set Mate Reverse Strand
            alignment.SetIsMateReverseStrand(true);
            Assert.Equal((uint)32, alignment.AlignmentFlag);
            alignment.SetIsMateReverseStrand(false);
            Assert.Equal((uint)0, alignment.AlignmentFlag);

            //Set Is Paired
            alignment.SetIsPaired(true);
            Assert.Equal((uint)1, alignment.AlignmentFlag);
            alignment.SetIsPaired(false);
            Assert.Equal((uint)0, alignment.AlignmentFlag);

            //Set Duplicate
            alignment.SetIsDuplicate(true);
            Assert.Equal((uint)1024, alignment.AlignmentFlag);
            alignment.SetIsDuplicate(false);
            Assert.Equal((uint)0, alignment.AlignmentFlag);

            //Set First Mate
            alignment.SetIsFirstMate(true);
            Assert.Equal((uint)64, alignment.AlignmentFlag);
            alignment.SetIsFirstMate(false);
            Assert.Equal((uint)0, alignment.AlignmentFlag);

            //Set Proper Pair
            alignment.SetIsProperPair(true);
            Assert.Equal((uint)2, alignment.AlignmentFlag);
            alignment.SetIsProperPair(false);
            Assert.Equal((uint)0, alignment.AlignmentFlag);

            //Set Reverse Strand
            alignment.SetIsReverseStrand(true);
            Assert.Equal((uint)16, alignment.AlignmentFlag);
            alignment.SetIsReverseStrand(false);
            Assert.Equal((uint)0, alignment.AlignmentFlag);

            //Set Secondary Alignment
            alignment.SetIsSecondaryAlignment(true);
            Assert.Equal((uint)256, alignment.AlignmentFlag);
            alignment.SetIsSecondaryAlignment(false);
            Assert.Equal((uint)0, alignment.AlignmentFlag);

            //Set Second Mate
            alignment.SetIsSecondMate(true);
            Assert.Equal((uint)128, alignment.AlignmentFlag);
            alignment.SetIsSecondMate(false);
            Assert.Equal((uint)0, alignment.AlignmentFlag);

            //Set Unmapped
            alignment.SetIsUnmapped(true);
            Assert.Equal((uint)4, alignment.AlignmentFlag);
            alignment.SetIsUnmapped(false);
            Assert.Equal((uint)0, alignment.AlignmentFlag);
        }