def testBaseCallInDel(self): bam = MockBam(['test2']) bam.add_read('foo1', 'atcgaTtcg', '.........', 0, 0, cigar='5M1I3M') # inserted T @6 bam.add_read('foo2', 'atcgacg', 'AAAAAAA', 0, 4, cigar='5M1D2M') # deleted T @ 10 out = StringIO.StringIO('') ngsutils.bam.basecall.bam_basecall(bam, os.path.join( os.path.dirname(__file__), 'test.fa'), out=out) valid = '''chrom|pos|ref|count|consensus call|minor call|ave mappings|entropy|A|C|G|T|N|Deletions|Gaps|Insertions|Inserts test2|1|A|1|A||1.0|0.91686730441|1|0|0|0|0|0|0|0| test2|2|T|1|T||1.0|3.25488750216|0|0|0|1|0|0|0|0| test2|3|C|1|C||1.0|3.25488750216|0|1|0|0|0|0|0|0| test2|4|G|1|G||1.0|0.91686730441|0|0|1|0|0|0|0|0| test2|5|A|2|A||1.0|1.36179536943|2|0|0|0|0|0|0|0| test2|6|T|2|T||1.0|4.24102241591|0|0|0|2|0|0|0|1|T:1 test2|7|C|2|C||1.0|4.24102241591|0|2|0|0|0|0|0|0| test2|8|G|2|G||1.0|1.36179536943|0|0|2|0|0|0|0|0| test2|9|A|1|A||1.0|0.91686730441|1|0|0|0|0|0|0|0| test2|10|T|0|N||1.0|0|0|0|0|0|0|1|0|0| test2|11|C|1|C||1.0|3.25488750216|0|1|0|0|0|0|0|0| test2|12|G|1|G||1.0|0.91686730441|0|0|1|0|0|0|0|0| '''.replace('|', '\t') self.assertEqual(valid, out.getvalue())
def testBaseCallHetTest(self): bam = MockBam(['test2']) bam.add_read('foo1', 'atcgaccg', '........', 0, 0, cigar='8M') bam.add_read('foo2', 'atcgattg', 'AAAAAAAA', 0, 4, cigar='8M') bam.add_read('foo3', 'accgattg', '########', 0, 4, cigar='8M') # ref: atcgatcgatcg # atcgaccg # atcgattg # accgattg # * * out = StringIO.StringIO('') ngsutils.bam.basecall.bam_basecall(bam, os.path.join( os.path.dirname(__file__), 'test.fa'), variants=True, hettest=True, out=out) valid = '''chrom|pos|ref|count|consensus call|minor call|ave mappings|alt. allele freq|entropy|A|C|G|T|N|Deletions|Gaps|Insertions|Inserts test2|6|T|3|C|T|1.0|0.333333333333|2.9097148334|0|2|0|1|0|0|0|0| test2|11|C|2|T||1.0|0.0|4.24102241591|0|0|0|2|0|0|0|0| '''.replace('|', '\t') # print '---' # print out.getvalue().replace('\t', '|') # print '---' # print valid.replace('\t', '|') self.assertEqual(valid, out.getvalue())
def testBaseCallMinCount(self): bam = MockBam(['test2']) bam.add_read('foo1', 'atcgatcg', '........', 0, 0, cigar='8M') bam.add_read('foo2', 'atcgatcg', 'AAAAAAAA', 0, 4, cigar='8M') bam.add_read('foo3', 'accgatcg', '########', 0, 4, cigar='8M', tags=[('IH', 2), ('HI', 1)]) out = StringIO.StringIO('') ngsutils.bam.basecall.bam_basecall(bam, os.path.join( os.path.dirname(__file__), 'test.fa'), min_count=2, out=out) valid = '''chrom|pos|ref|count|consensus call|minor call|ave mappings|entropy|A|C|G|T|N|Deletions|Gaps|Insertions|Inserts test2|5|A|3|A||1.33333333333|1.65545182665|3|0|0|0|0|0|0|0| test2|6|T|3|T|C|1.33333333333|2.9097148334|0|1|0|2|0|0|0|0| test2|7|C|3|C||1.33333333333|4.85048518563|0|3|0|0|0|0|0|0| test2|8|G|3|G||1.33333333333|1.65545182665|0|0|3|0|0|0|0|0| test2|9|A|2|A||1.5|1.36179536943|2|0|0|0|0|0|0|0| test2|10|T|2|T||1.5|4.24102241591|0|0|0|2|0|0|0|0| test2|11|C|2|C||1.5|4.24102241591|0|2|0|0|0|0|0|0| test2|12|G|2|G||1.5|1.36179536943|0|0|2|0|0|0|0|0| '''.replace('|', '\t') self.assertEqual(valid, out.getvalue())
def testBaseCallMinQual(self): bam = MockBam(['test2']) bam.add_read('foo1', 'atcgatcg', '........', 0, 0, cigar='8M') bam.add_read('foo2', 'atcgatcg', 'AAAAAAAA', 0, 4, cigar='8M') bam.add_read('foo3', 'accgatcg', '########', 0, 4, cigar='8M', tags=[('IH', 2), ('HI', 1)]) out = StringIO.StringIO('') ngsutils.bam.basecall.bam_basecall(bam, os.path.join(os.path.dirname(__file__), 'test.fa'), min_qual=10, out=out) valid = '''chrom|pos|ref|count|consensus call|minor call|ave mappings|entropy|A|C|G|T|N|Deletions|Gaps|Insertions|Inserts test2|1|A|1|A||1.0|0.91686730441|1|0|0|0|0|0|0|0| test2|2|T|1|T||1.0|3.25488750216|0|0|0|1|0|0|0|0| test2|3|C|1|C||1.0|3.25488750216|0|1|0|0|0|0|0|0| test2|4|G|1|G||1.0|0.91686730441|0|0|1|0|0|0|0|0| test2|5|A|2|A||1.0|1.36179536943|2|0|0|0|0|0|0|0| test2|6|T|2|T||1.0|4.24102241591|0|0|0|2|0|0|0|0| test2|7|C|2|C||1.0|4.24102241591|0|2|0|0|0|0|0|0| test2|8|G|2|G||1.0|1.36179536943|0|0|2|0|0|0|0|0| test2|9|A|1|A||1.0|0.91686730441|1|0|0|0|0|0|0|0| test2|10|T|1|T||1.0|3.25488750216|0|0|0|1|0|0|0|0| test2|11|C|1|C||1.0|3.25488750216|0|1|0|0|0|0|0|0| test2|12|G|1|G||1.0|0.91686730441|0|0|1|0|0|0|0|0| '''.replace('|', '\t') self.assertEqual(valid, out.getvalue())
def testBaseCallHetTest(self): bam = MockBam(['test2']) bam.add_read('foo1', 'atcgaccg', '........', 0, 0, cigar='8M') bam.add_read('foo2', 'atcgattg', 'AAAAAAAA', 0, 4, cigar='8M') bam.add_read('foo3', 'accgattg', '########', 0, 4, cigar='8M') # ref: atcgatcgatcg # atcgaccg # atcgattg # accgattg # * * out = StringIO.StringIO('') ngsutils.bam.basecall.bam_basecall(bam, os.path.join(os.path.dirname(__file__), 'test.fa'), variants=True, hettest=True, out=out) valid = '''chrom|pos|ref|count|consensus call|minor call|ave mappings|alt. allele freq|entropy|A|C|G|T|N|Deletions|Gaps|Insertions|Inserts test2|6|T|3|C|T|1.0|0.333333333333|2.9097148334|0|2|0|1|0|0|0|0| test2|11|C|2|T||1.0|0.0|4.24102241591|0|0|0|2|0|0|0|0| '''.replace('|', '\t') # print '---' # print out.getvalue().replace('\t', '|') # print '---' # print valid.replace('\t', '|') self.assertEqual(valid, out.getvalue())
def testBaseCallMinCount(self): bam = MockBam(['test2']) bam.add_read('foo1', 'atcgatcg', '........', 0, 0, cigar='8M') bam.add_read('foo2', 'atcgatcg', 'AAAAAAAA', 0, 4, cigar='8M') bam.add_read('foo3', 'accgatcg', '########', 0, 4, cigar='8M', tags=[('IH', 2), ('HI', 1)]) out = StringIO.StringIO('') ngsutils.bam.basecall.bam_basecall(bam, os.path.join(os.path.dirname(__file__), 'test.fa'), min_count=2, out=out) valid = '''chrom|pos|ref|count|consensus call|minor call|ave mappings|entropy|A|C|G|T|N|Deletions|Gaps|Insertions|Inserts test2|5|A|3|A||1.33333333333|1.65545182665|3|0|0|0|0|0|0|0| test2|6|T|3|T|C|1.33333333333|2.9097148334|0|1|0|2|0|0|0|0| test2|7|C|3|C||1.33333333333|4.85048518563|0|3|0|0|0|0|0|0| test2|8|G|3|G||1.33333333333|1.65545182665|0|0|3|0|0|0|0|0| test2|9|A|2|A||1.5|1.36179536943|2|0|0|0|0|0|0|0| test2|10|T|2|T||1.5|4.24102241591|0|0|0|2|0|0|0|0| test2|11|C|2|C||1.5|4.24102241591|0|2|0|0|0|0|0|0| test2|12|G|2|G||1.5|1.36179536943|0|0|2|0|0|0|0|0| '''.replace('|', '\t') self.assertEqual(valid, out.getvalue())
def testBaseCallStrand(self): bam = MockBam(['test2']) bam.add_read('foo1', 'atcgatcg', '........', 0, 0, cigar='8M') bam.add_read('foo2', 'atcgatcg', 'AAAAAAAA', 0, 4, cigar='8M') bam.add_read('foo3', 'accgatcg', '########', 0, 4, cigar='8M', is_reverse=True) bam.add_read('foo4', 'atcgactgatcg', '############', 0, 0, cigar='12M') out = StringIO.StringIO('') ngsutils.bam.basecall.bam_basecall(bam, os.path.join(os.path.dirname(__file__), 'test.fa'), showstrand=True, out=out) valid = '''chrom|pos|ref|count|consensus call|minor call|ave mappings|entropy|A|C|G|T|N|Deletions|Gaps|Insertions|Inserts|+ strand %|A minor %|C minor %|G minor %|T minor %|N minor %|Deletion minor %|Insertion minor % test2|1|A|2|A||1.0|1.36179536943|2|0|0|0|0|0|0|0||1.0|0.0|0.0|0.0|0.0|0.0|0.0|0.0 test2|2|T|2|T||1.0|4.24102241591|0|0|0|2|0|0|0|0||1.0|0.0|0.0|0.0|0.0|0.0|0.0|0.0 test2|3|C|2|C||1.0|4.24102241591|0|2|0|0|0|0|0|0||1.0|0.0|0.0|0.0|0.0|0.0|0.0|0.0 test2|4|G|2|G||1.0|1.36179536943|0|0|2|0|0|0|0|0||1.0|0.0|0.0|0.0|0.0|0.0|0.0|0.0 test2|5|A|4|A||1.0|1.87433193885|4|0|0|0|0|0|0|0||0.75|0.25|0.0|0.0|0.0|0.0|0.0|0.0 test2|6|T|4|T/C||1.0|2.94335833285|0|2|0|2|0|0|0|0||0.75|0.0|0.5|0.0|0.0|0.0|0.0|0.0 test2|7|C|4|C|T|1.0|3.45990045591|0|3|0|1|0|0|0|0||0.75|0.0|0.333333333333|0.0|0.0|0.0|0.0|0.0 test2|8|G|4|G||1.0|1.87433193885|0|0|4|0|0|0|0|0||0.75|0.0|0.0|0.25|0.0|0.0|0.0|0.0 test2|9|A|3|A||1.0|1.65545182665|3|0|0|0|0|0|0|0||0.666666666667|0.333333333333|0.0|0.0|0.0|0.0|0.0|0.0 test2|10|T|3|T||1.0|4.85048518563|0|0|0|3|0|0|0|0||0.666666666667|0.0|0.0|0.0|0.333333333333|0.0|0.0|0.0 test2|11|C|3|C||1.0|4.85048518563|0|3|0|0|0|0|0|0||0.666666666667|0.0|0.333333333333|0.0|0.0|0.0|0.0|0.0 test2|12|G|3|G||1.0|1.65545182665|0|0|3|0|0|0|0|0||0.666666666667|0.0|0.0|0.333333333333|0.0|0.0|0.0|0.0 '''.replace('|', '\t') self.assertEqual(valid, out.getvalue())
def testBaseCallRegionStrand(self): # confirm that BED strand *isn't* used bam = MockBam(['test2']) bam.add_read('foo1', 'atcgatcg', '........', 0, 0, cigar='8M') bam.add_read('foo2', 'atcgatcg', 'AAAAAAAA', 0, 4, cigar='8M') bam.add_read('foo3', 'accgatcg', '########', 0, 4, cigar='8M', is_reverse=True) bam.add_read('foo4', 'atcgactgatcg', '############', 0, 0, cigar='12M') bed = BedFile(fileobj=StringIO.StringIO('''\ test2|4|7|foo|1|- '''.replace('|', '\t'))) # remember: bed is 0-based, basecall is 1-based, so 4->7, corresponds to 5->8 out = StringIO.StringIO('') ngsutils.bam.basecall.bam_basecall(bam, os.path.join(os.path.dirname(__file__), 'test.fa'), showstrand=True, regions=bed, out=out) valid = '''chrom|pos|ref|count|consensus call|minor call|ave mappings|entropy|A|C|G|T|N|Deletions|Gaps|Insertions|Inserts|+ strand %|A minor %|C minor %|G minor %|T minor %|N minor %|Deletion minor %|Insertion minor % test2|5|A|4|A||1.0|1.87433193885|4|0|0|0|0|0|0|0||0.75|0.25|0.0|0.0|0.0|0.0|0.0|0.0 test2|6|T|4|T/C||1.0|2.94335833285|0|2|0|2|0|0|0|0||0.75|0.0|0.5|0.0|0.0|0.0|0.0|0.0 test2|7|C|4|C|T|1.0|3.45990045591|0|3|0|1|0|0|0|0||0.75|0.0|0.333333333333|0.0|0.0|0.0|0.0|0.0 test2|8|G|4|G||1.0|1.87433193885|0|0|4|0|0|0|0|0||0.75|0.0|0.0|0.25|0.0|0.0|0.0|0.0 '''.replace('|', '\t') self.assertEqual(valid, out.getvalue())
def testBaseCallRegionStrand(self): # confirm that BED strand *isn't* used bam = MockBam(['test2']) bam.add_read('foo1', 'atcgatcg', '........', 0, 0, cigar='8M') bam.add_read('foo2', 'atcgatcg', 'AAAAAAAA', 0, 4, cigar='8M') bam.add_read('foo3', 'accgatcg', '########', 0, 4, cigar='8M', is_reverse=True) bam.add_read('foo4', 'atcgactgatcg', '############', 0, 0, cigar='12M') bed = BedFile(fileobj=StringIO.StringIO('''\ test2|4|7|foo|1|- '''.replace('|', '\t'))) # remember: bed is 0-based, basecall is 1-based, so 4->7, corresponds to 5->8 out = StringIO.StringIO('') ngsutils.bam.basecall.bam_basecall(bam, os.path.join( os.path.dirname(__file__), 'test.fa'), showstrand=True, regions=bed, out=out) valid = '''chrom|pos|ref|count|consensus call|minor call|ave mappings|entropy|A|C|G|T|N|Deletions|Gaps|Insertions|Inserts|+ strand %|A minor %|C minor %|G minor %|T minor %|N minor %|Deletion minor %|Insertion minor % test2|5|A|4|A||1.0|1.87433193885|4|0|0|0|0|0|0|0||0.75|0.25|0.0|0.0|0.0|0.0|0.0|0.0 test2|6|T|4|T/C||1.0|2.94335833285|0|2|0|2|0|0|0|0||0.75|0.0|0.5|0.0|0.0|0.0|0.0|0.0 test2|7|C|4|C|T|1.0|3.45990045591|0|3|0|1|0|0|0|0||0.75|0.0|0.333333333333|0.0|0.0|0.0|0.0|0.0 test2|8|G|4|G||1.0|1.87433193885|0|0|4|0|0|0|0|0||0.75|0.0|0.0|0.25|0.0|0.0|0.0|0.0 '''.replace('|', '\t') self.assertEqual(valid, out.getvalue())
def testBaseCallStrand(self): bam = MockBam(['test2']) bam.add_read('foo1', 'atcgatcg', '........', 0, 0, cigar='8M') bam.add_read('foo2', 'atcgatcg', 'AAAAAAAA', 0, 4, cigar='8M') bam.add_read('foo3', 'accgatcg', '########', 0, 4, cigar='8M', is_reverse=True) bam.add_read('foo4', 'atcgactgatcg', '############', 0, 0, cigar='12M') out = StringIO.StringIO('') ngsutils.bam.basecall.bam_basecall(bam, os.path.join( os.path.dirname(__file__), 'test.fa'), showstrand=True, out=out) valid = '''chrom|pos|ref|count|consensus call|minor call|ave mappings|entropy|A|C|G|T|N|Deletions|Gaps|Insertions|Inserts|+ strand %|A minor %|C minor %|G minor %|T minor %|N minor %|Deletion minor %|Insertion minor % test2|1|A|2|A||1.0|1.36179536943|2|0|0|0|0|0|0|0||1.0|0.0|0.0|0.0|0.0|0.0|0.0|0.0 test2|2|T|2|T||1.0|4.24102241591|0|0|0|2|0|0|0|0||1.0|0.0|0.0|0.0|0.0|0.0|0.0|0.0 test2|3|C|2|C||1.0|4.24102241591|0|2|0|0|0|0|0|0||1.0|0.0|0.0|0.0|0.0|0.0|0.0|0.0 test2|4|G|2|G||1.0|1.36179536943|0|0|2|0|0|0|0|0||1.0|0.0|0.0|0.0|0.0|0.0|0.0|0.0 test2|5|A|4|A||1.0|1.87433193885|4|0|0|0|0|0|0|0||0.75|0.25|0.0|0.0|0.0|0.0|0.0|0.0 test2|6|T|4|T/C||1.0|2.94335833285|0|2|0|2|0|0|0|0||0.75|0.0|0.5|0.0|0.0|0.0|0.0|0.0 test2|7|C|4|C|T|1.0|3.45990045591|0|3|0|1|0|0|0|0||0.75|0.0|0.333333333333|0.0|0.0|0.0|0.0|0.0 test2|8|G|4|G||1.0|1.87433193885|0|0|4|0|0|0|0|0||0.75|0.0|0.0|0.25|0.0|0.0|0.0|0.0 test2|9|A|3|A||1.0|1.65545182665|3|0|0|0|0|0|0|0||0.666666666667|0.333333333333|0.0|0.0|0.0|0.0|0.0|0.0 test2|10|T|3|T||1.0|4.85048518563|0|0|0|3|0|0|0|0||0.666666666667|0.0|0.0|0.0|0.333333333333|0.0|0.0|0.0 test2|11|C|3|C||1.0|4.85048518563|0|3|0|0|0|0|0|0||0.666666666667|0.0|0.333333333333|0.0|0.0|0.0|0.0|0.0 test2|12|G|3|G||1.0|1.65545182665|0|0|3|0|0|0|0|0||0.666666666667|0.0|0.0|0.333333333333|0.0|0.0|0.0|0.0 '''.replace('|', '\t') self.assertEqual(valid, out.getvalue())
#!/usr/bin/env python ''' Tests for bamutils count ''' import unittest import StringIO import ngsutils.bam import ngsutils.bam.count import ngsutils.bam.count.models from ngsutils.bam.t import MockBam testbam1 = MockBam(['chr1']) testbam1.add_read('foo1', 'A' * 50, tid=0, pos=100, cigar='50M', tags=[('IH', 2)]) testbam1.add_read('foo1', 'A' * 50, tid=0, pos=1000, cigar='50M', tags=[('IH', 2)]) testbam1.add_read('foo2', 'A' * 50, tid=0, pos=101, cigar='50M') testbam1.add_read('foo3', 'A' * 50, tid=0, pos=101, cigar='50M') testbam1.add_read('foo4', 'A' * 50, tid=0, pos=103, cigar='50M') testbam1.add_read('foo5', 'A' * 50, tid=0, pos=200, cigar='25M') testbam1.add_read('foo6', 'A' * 50, tid=0, pos=200, cigar='25M') testbam1.add_read('foo7', 'A' * 50, tid=0, pos=225, cigar='25M') testbam1.add_read('foo8', 'A' * 50, tid=0, pos=225, cigar='25M') testbam1.add_read('foo9', 'A' * 50, tid=0, pos=300, cigar='50M') testbam1.add_read('foo10', 'A' * 50, tid=0, pos=301, cigar='50M') testbam1.add_read('foo11', 'A' * 50, tid=0, pos=302, cigar='50M', is_reverse=True) testbam1.add_read('foo12', 'A' * 50, tid=0, pos=303, cigar='50M', is_reverse=True) class CountTest(unittest.TestCase):
#!/usr/bin/env python ''' Tests for bamutils extract ''' import unittest import os import ngsutils.bam from ngsutils.bam.innerdist import bam_innerdist from ngsutils.bam.t import MockBam, _matches testbam1 = MockBam(['chr1'], insert_order=True) testbam1.add_read('foo1', tid=0, pos=100, aend=150, cigar='50M') testbam1.add_read('foo2', tid=0, pos=200, aend=250, cigar='50M') testbam1.add_read('foo3', tid=0, pos=300, aend=350, cigar='50M') testbam1.add_read('foo4', tid=0, pos=400, aend=450, cigar='50M') testbam1.add_read('foo5', tid=0, pos=400, aend=450, cigar='50M') testbam1.add_read('foo6', tid=-1) testbam2 = MockBam(['chr1'], insert_order=True) testbam2.add_read('foo1', tid=0, pos=200, aend=250, cigar='50M') testbam2.add_read('foo2', tid=0, pos=300, aend=350, cigar='50M') testbam2.add_read('foo3', tid=0, pos=450, aend=500, cigar='50M') testbam2.add_read('foo4', tid=0, pos=550, aend=600, cigar='50M') testbam2.add_read('foo5', tid=-1) testbam2.add_read('foo6', tid=0, pos=500, aend=550, cigar='50M') testbam3 = MockBam(['chr1'], insert_order=True) testbam3.add_read('foo1', tid=0, pos=100, aend=150, cigar='50M')
#!/usr/bin/env python ''' Tests for bamutils extract ''' import unittest import os import ngsutils.bam import ngsutils.bam.extract from ngsutils.bam.t import MockBam, _matches testbam1 = MockBam(['chr1']) testbam1.add_read('foo1', tid=0, pos=100, aend=150, cigar='50M') # too early testbam1.add_read('foo2', tid=0, pos=200, aend=250, cigar='50M') # in range, + strand testbam1.add_read('foo3', tid=0, pos=1000, aend=1050, cigar='50M') # too late testbam1.add_read('foo4', tid=0, pos=200, aend=350, cigar='25M100N25M') # in range, start, + strand testbam1.add_read('foo5', tid=0, pos=200, aend=250, cigar='50M', is_reverse=True) # in range, start, - strand testbam1.add_read('foo6', tid=0, pos=2000, aend=3050, cigar='20M500N20M500M10M') # touches (2000,2020), (2520, 2540), (3040, 3050) class ExtractTest(unittest.TestCase): def setUp(self): self.fname1 = os.path.join(os.path.dirname(__file__), 'testbam1') with open(self.fname1, 'w') as f: f.write('chr1\t200\t250\tfoo\t1\t+\n') f.write('chr1\t125\t170\tfoo\t1\t+\n') self.fname2 = os.path.join(os.path.dirname(__file__), 'testbam2') with open(self.fname2, 'w') as f:
#!/usr/bin/env python ''' Tests for bamutils export ''' import StringIO import unittest import ngsutils.bam import ngsutils.bam.export from ngsutils.bam.t import MockBam testbam1 = MockBam(['chr1']) testbam1.add_read('foo1', 'atcgatcg', 'AAAAAAAA', 0, 0, 8, '8M') testbam1.add_read('foo2', 'atcgtttt', 'AAAABBBB', 0, 4, 12, '8M', is_reverse=True) testbam1.add_read('foo3', 'gggggggg', 'CCCCCCCC') testbam2 = MockBam(['chr1']) testbam2.add_read('bar1', 'atcgatcg', 'AAAAAAAA', 0, 0, 8, '8M', rnext=0, pnext=100, is_paired=True, is_read1=True) testbam2.add_read('bar1', 'gctagcta', 'AAAAAAAA', 0, 100, 108, '8M', is_paired=True, is_read2=True) testbam2.add_read('bar2', 'atcgatcg', 'AAAAAAAA', is_paired=True, is_read1=True) testbam2.add_read('bar2', 'gctagcta', 'AAAAAAAA', is_paired=True, is_read2=True) testbam3 = MockBam(['chr1']) testbam3.add_read('baz1', 'atcgatcg', 'AAAAAAAA', 0, 0, 8, '8M', mapq=10, isize=100, tlen=120, tags=[('ZZ', 'foo'), ('ZY', 100), ('ZX', 1.0), ('ZW', 'a'), ]) class ExportTest(unittest.TestCase): def testExport1(self):
#!/usr/bin/env python ''' Tests for bamutils export ''' import StringIO import unittest import ngsutils.bam import ngsutils.bam.export from ngsutils.bam.t import MockBam testbam1 = MockBam(['chr1']) testbam1.add_read('foo1', 'atcgatcg', 'AAAAAAAA', 0, 0, 8, '8M') testbam1.add_read('foo2', 'atcgtttt', 'AAAABBBB', 0, 4, 12, '8M', is_reverse=True) testbam1.add_read('foo3', 'gggggggg', 'CCCCCCCC') testbam2 = MockBam(['chr1']) testbam2.add_read('bar1', 'atcgatcg', 'AAAAAAAA', 0, 0,
Tests for bamutils count ''' import unittest import StringIO import ngsutils.bam import ngsutils.bam.count import ngsutils.bam.count.models from ngsutils.bam.t import MockBam testbam1 = MockBam(['chr1']) testbam1.add_read('foo1', 'A' * 50, tid=0, pos=100, cigar='50M', tags=[('IH', 2)]) testbam1.add_read('foo1', 'A' * 50, tid=0, pos=1000, cigar='50M', tags=[('IH', 2)]) testbam1.add_read('foo2', 'A' * 50, tid=0, pos=101, cigar='50M') testbam1.add_read('foo3', 'A' * 50, tid=0, pos=101, cigar='50M') testbam1.add_read('foo4', 'A' * 50, tid=0, pos=103, cigar='50M') testbam1.add_read('foo5', 'A' * 50, tid=0, pos=200, cigar='25M') testbam1.add_read('foo6', 'A' * 50, tid=0, pos=200, cigar='25M') testbam1.add_read('foo7', 'A' * 50, tid=0, pos=225, cigar='25M') testbam1.add_read('foo8', 'A' * 50, tid=0, pos=225, cigar='25M')
#!/usr/bin/env python ''' Tests for bamutils extract ''' import unittest import os import ngsutils.bam import ngsutils.bam.extract from ngsutils.bam.t import MockBam, _matches testbam1 = MockBam(['chr1']) testbam1.add_read('foo1', tid=0, pos=100, aend=150, cigar='50M') # too early testbam1.add_read('foo2', tid=0, pos=200, aend=250, cigar='50M') # in range, + strand testbam1.add_read('foo3', tid=0, pos=1000, aend=1050, cigar='50M') # too late testbam1.add_read('foo4', tid=0, pos=200, aend=350, cigar='25M100N25M') # in range, start, + strand testbam1.add_read('foo5', tid=0, pos=200, aend=250, cigar='50M', is_reverse=True) # in range, start, - strand testbam1.add_read('foo6', tid=0, pos=2000, aend=3050, cigar='20M500N20M500M10M'