root/galaxy-central/eggs/bx_python-0.5.0_dev_f74aec067563-py2.6-macosx-10.6-universal-ucs2.egg/bx/seqmapping_tests.py

リビジョン 3, 3.0 KB (コミッタ: kohda, 14 年 前)

Install Unix tools  http://hannonlab.cshl.edu/galaxy_unix_tools/galaxy.html

行番号 
1"""
2Tests for `bx.seqmapping`.
3"""
4
5import unittest
6import bx.seqmapping
7
8from numpy import array, allclose
9from StringIO import StringIO
10
11class 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       
24class 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   
33eight_species_mapping = """TTTTTTTT 0
34CCCCCCCC 4
35AAAAAAAA 1
36GGGGGGGG 5
37AAAAA*AA 2
38TTTTT*TT 0
39GGGGG*GG 5
40CCCCC*CC 4
41GGGG*GGG 5
42TTTT*TTT 2
43GGGAAGGG 5
44AAAA*AAA 2
45TTTTT*T* 2
46CCCCC*C* 4
47CCCTTCCC 4
48CCCC*CCC 4
49TTTT**TT 2
50AAAA**AA 2
51AAAAA*A* 2
52GGGGG*G* 5
53AAAAAGAA 2
54TTTTTCTT 2
55GGGAA*GG 5
56TTTT**T* 2
57TTTCCTTT 0
58AAAAAAA* 1
59CCCTT*CC 3
60TTTTTTT* 2
61CC*CC*CC 3
62AAAGGAAA 2
63------G- 2
64"""
65       
66rows = [ "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       
75class 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       
83test_classes = [ AlignmentMappingTests, CharMappingTests, IntMappingTests ]
84suite = unittest.TestSuite( [ unittest.makeSuite( c ) for c in test_classes ] )
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。