1 | """ |
---|
2 | Tests for `bx.seqmapping`. |
---|
3 | """ |
---|
4 | |
---|
5 | import unittest |
---|
6 | import bx.seqmapping |
---|
7 | |
---|
8 | from numpy import array, allclose |
---|
9 | from StringIO import StringIO |
---|
10 | |
---|
11 | class CharMappingTests( unittest.TestCase ): |
---|
12 | def test_DNA( self ): |
---|
13 | assert( allclose( bx.seqmapping.DNA.translate( "ACGTacgt-?X" ), |
---|
14 | [ 0, 1, 2, 3, 0, 1, 2, 3, 4, -1, -1 ] ) ) |
---|
15 | def test_DNA_list( self ): |
---|
16 | assert( allclose( bx.seqmapping.DNA.translate_list( [ "ACGTA", "TGCAX" ] ), |
---|
17 | [ 0 + 3*6, 1 + 2*6, 2 + 1*6, 3 + 0*6, -1 ] ) ) |
---|
18 | def test_other( self ): |
---|
19 | m = bx.seqmapping.CharToIntArrayMapping() |
---|
20 | m.set_mapping( "A", 0 ) |
---|
21 | m.set_mapping( "B", 7 ) |
---|
22 | assert( allclose( m.translate( "ABCCBA" ), [ 0, 7, -1, -1, 7, 0 ] ) ) |
---|
23 | |
---|
24 | class IntMappingTests( unittest.TestCase ): |
---|
25 | def test_simple( self ): |
---|
26 | m = bx.seqmapping.IntToIntMapping( 4 ) |
---|
27 | m.set_mapping( 0, 0 ) |
---|
28 | m.set_mapping( 2, 0 ) |
---|
29 | m.set_mapping( 1, 1 ) |
---|
30 | m.set_mapping( 3, 1 ) |
---|
31 | assert( allclose( m.translate( array( [ 0, 1, 2, 3, 4 ], 'i' ) ), array( [ 0, 1, 0, 1, -1 ] ) ) ) |
---|
32 | |
---|
33 | eight_species_mapping = """TTTTTTTT 0 |
---|
34 | CCCCCCCC 4 |
---|
35 | AAAAAAAA 1 |
---|
36 | GGGGGGGG 5 |
---|
37 | AAAAA*AA 2 |
---|
38 | TTTTT*TT 0 |
---|
39 | GGGGG*GG 5 |
---|
40 | CCCCC*CC 4 |
---|
41 | GGGG*GGG 5 |
---|
42 | TTTT*TTT 2 |
---|
43 | GGGAAGGG 5 |
---|
44 | AAAA*AAA 2 |
---|
45 | TTTTT*T* 2 |
---|
46 | CCCCC*C* 4 |
---|
47 | CCCTTCCC 4 |
---|
48 | CCCC*CCC 4 |
---|
49 | TTTT**TT 2 |
---|
50 | AAAA**AA 2 |
---|
51 | AAAAA*A* 2 |
---|
52 | GGGGG*G* 5 |
---|
53 | AAAAAGAA 2 |
---|
54 | TTTTTCTT 2 |
---|
55 | GGGAA*GG 5 |
---|
56 | TTTT**T* 2 |
---|
57 | TTTCCTTT 0 |
---|
58 | AAAAAAA* 1 |
---|
59 | CCCTT*CC 3 |
---|
60 | TTTTTTT* 2 |
---|
61 | CC*CC*CC 3 |
---|
62 | AAAGGAAA 2 |
---|
63 | ------G- 2 |
---|
64 | """ |
---|
65 | |
---|
66 | rows = [ "AAATTGT-----ATGTCCATCCTTTAAAGGTCATTCCTTTAATGGTCTTTTCTGGACACCACTAGGGGTCAGAAGTAGTTCATCAAAC-----------------TTTCTTCCCTCCC-TACTTCAGTG", |
---|
67 | "AAATTGT-----ATGTCCATCCTTTAAAGGTCATTCCTTTAATGGTCTTTTCTGGACACCACTAGGGGTCAGAAGTAGTTCATCAAAC-----------------TTTCTTCCCTCCC-TACTTCAGTG", |
---|
68 | "AAATTTT-----ATGTCTATCCTTTAAAGGTCATTCCTCTAATAGTCTTTTCTGGACACCACTAGGGGTCAGAAGTAGTTCATTAAAC-----------------TTTCTTCCCTCCC-TACCTCAGTG", |
---|
69 | "AAACTGT-----ATCACCACCTTTTTAAGGTCATTTCTCTAATGATCCTGTT-GCATACCAGTAGGGGGCAGAAGTGTTCCGCTGATTTCCGCCCTCCTCCCCACCCCCCCACCCCCC-TTATTCAAAG", |
---|
70 | "*********************************************************************************************************************************", |
---|
71 | "-TATTAT-----ATGGCCATGTTCAAAAGGTTGTTTCTCTAATGATTCCTTC-TGATACCAGTAGGGGTCAGAAGTGGTCCATTGATT---------------------CTTTTCCTC-TGATTC-AAG", |
---|
72 | "AAATTGA--AAGATCTCACTCTTTGCCAGGTAGTCCATCTAAGGGTCACATATGGATACCAGCAGGGCCT-GAAGAAGCCCATTGAAT------------------------TTTCCC-ATCTTCAAGG", |
---|
73 | "AAATTCATGATAGTGTCACTCTTAAATAGATGATTC--------TTCACAT---GATGCCAGCAGGGGGC-AGAGCAGGCTGTGAAAT------------------------TTTCCCTTTCTTCAAAG" ] |
---|
74 | |
---|
75 | class AlignmentMappingTests( unittest.TestCase ): |
---|
76 | def test_largescale( self ): |
---|
77 | f = StringIO( eight_species_mapping ) |
---|
78 | n, m = bx.seqmapping.alignment_mapping_from_file( f ) |
---|
79 | t = bx.seqmapping.DNA.translate_list( rows ) |
---|
80 | i = m.translate( t ) |
---|
81 | |
---|
82 | |
---|
83 | test_classes = [ AlignmentMappingTests, CharMappingTests, IntMappingTests ] |
---|
84 | suite = unittest.TestSuite( [ unittest.makeSuite( c ) for c in test_classes ] ) |
---|