1 | """ |
---|
2 | Tests for `bx.seq.nib`. |
---|
3 | """ |
---|
4 | |
---|
5 | import unittest |
---|
6 | import sys |
---|
7 | import os.path |
---|
8 | import nib |
---|
9 | |
---|
10 | test_nib = "test_data/seq_tests/test.nib" |
---|
11 | |
---|
12 | # Same sequence data as stored in test.nib |
---|
13 | |
---|
14 | valid_seq = "TGGAGGCATTTGTGATTCAATAGATGCAGAAAGAAACCTTCCTAGAGCTG" \ |
---|
15 | + "GCGTTCTCTAACTAAAAGTGGAAAGTTCTGAGGAATGAGGACTGTTATAA" \ |
---|
16 | + "ATCCCACCCCACACCGCACCTTCTCCAGGGAAGTTTCATGGCCGTGAAGA" \ |
---|
17 | + "GGACAGAAAGTGAGAACCAAGATggaactgaataaacaagcttcacactg" \ |
---|
18 | + "ttagtttccccatatgcttaccttcccacagatgccaaccttggaggcct" \ |
---|
19 | + "aagaggcctagaatattatcctttgtctgatcatttctctacaaatttat" \ |
---|
20 | + "tgttctttgttaagatgctacataagcccaaattctaaccacccctttga" \ |
---|
21 | + "gttacccatcatcaagtttctcccatgtg" |
---|
22 | |
---|
23 | valid_seq_len = len( valid_seq ) |
---|
24 | |
---|
25 | class NIBTestCase( unittest.TestCase ): |
---|
26 | |
---|
27 | def test_get( self ): |
---|
28 | nibfile = nib.NibFile( file( test_nib ) ) |
---|
29 | # Try all combinations of even / odd boundaries |
---|
30 | check_get( nibfile, 0, 10 ) |
---|
31 | check_get( nibfile, 1, 10 ) |
---|
32 | check_get( nibfile, 0, 11 ) |
---|
33 | check_get( nibfile, 1, 11 ) |
---|
34 | # Test near end of file also |
---|
35 | check_get( nibfile, valid_seq_len - 10, 10 ) |
---|
36 | check_get( nibfile, valid_seq_len - 11, 11 ) |
---|
37 | # Test really short gets |
---|
38 | check_get( nibfile, 0, 0 ) |
---|
39 | check_get( nibfile, 1, 0 ) |
---|
40 | check_get( nibfile, 0, 1 ) |
---|
41 | check_get( nibfile, 1, 1 ) |
---|
42 | # Test negative length |
---|
43 | self.assertRaises( AssertionError, nibfile.get, 20, -1 ) |
---|
44 | |
---|
45 | def check_get( nibfile, start, len ): |
---|
46 | ## print "expect: |%r|" % valid_seq[start:start+len] |
---|
47 | ## print "actual: |%r|" % nibfile.get( start, len ) |
---|
48 | assert nibfile.get( start, len ) == valid_seq[start:start+len] |
---|
49 | |
---|
50 | test_classes = [ NIBTestCase ] |
---|
51 | suite = unittest.TestSuite( [ unittest.makeSuite( c ) for c in test_classes ] ) |
---|