[3] | 1 | """ |
---|
| 2 | Tests for `bx.seq.seq`. |
---|
| 3 | """ |
---|
| 4 | |
---|
| 5 | |
---|
| 6 | import unittest |
---|
| 7 | import os.path |
---|
| 8 | import sys |
---|
| 9 | import bx.seq, fasta_tests, nib_tests, qdna_tests |
---|
| 10 | |
---|
| 11 | test_fa = "test_data/seq_tests/test.fa" |
---|
| 12 | test2_fa = "test_data/seq_tests/test2.fa" |
---|
| 13 | test_nib = "test_data/seq_tests/test.nib" |
---|
| 14 | test_qdna = "test_data/seq_tests/test.qdna" |
---|
| 15 | |
---|
| 16 | valid_fasta = fasta_tests.valid_seq |
---|
| 17 | valid_nib = nib_tests.valid_seq |
---|
| 18 | valid_qdna = qdna_tests.valid_seq |
---|
| 19 | |
---|
| 20 | # Same sequences as stored in test2.fa |
---|
| 21 | |
---|
| 22 | valid2_fa = [("apple", "GGCGCTGCGATAAGGTTGCGACAACACGGACCTTCTTTTGCCTACCTCTGTTCTTGGCACG"), |
---|
| 23 | ("orange", "CGTGCCGAGAACAGAAAATACGCCGGGCGGTGCAGTAGTATCTTGGTATCCGATATGCAGG"), |
---|
| 24 | ("grapefruit", "CCTGCATATCGACTAGTACACCCTCCCGAGGTACCCCACCCATCCCTCTTTTCTCGGCGCG")] |
---|
| 25 | |
---|
| 26 | class SEQTestCase (unittest.TestCase): |
---|
| 27 | |
---|
| 28 | def test_get_fasta (self): |
---|
| 29 | fastafile = bx.seq.seq_file (file (test_fa, "rb")) |
---|
| 30 | check_get (fastafile, valid_fasta, 3, 40) |
---|
| 31 | |
---|
| 32 | def test_get_nib (self): |
---|
| 33 | nibfile = bx.seq.seq_file (file (test_nib, "rb")) |
---|
| 34 | check_get (nibfile, valid_nib, 3, 40) |
---|
| 35 | |
---|
| 36 | def test_get_qdna (self): |
---|
| 37 | qdnafile = bx.seq.seq_file (file (test_qdna, "rb")) |
---|
| 38 | check_get (qdnafile, valid_qdna, 3, 40) |
---|
| 39 | |
---|
| 40 | def test_get_reader (self): |
---|
| 41 | reader = bx.seq.seq_reader (file (test2_fa, "rb")) |
---|
| 42 | for (ix,seq) in enumerate(reader): |
---|
| 43 | assert (ix < len(valid2_fa)), "FastaReader returns too many sequences" |
---|
| 44 | text = "%s" % seq |
---|
| 45 | fields = text.split() |
---|
| 46 | assert (len(fields) == 2), "SeqReader.__str__ returns incorrect sequence string \"%s\" (%d)" % text |
---|
| 47 | assert (fields[0] == valid2_fa[ix][0]), "FastaReader returned the wrong name (%s,%s)" % (fields[0],valid2_fa[ix][0]) |
---|
| 48 | assert (fields[1] == valid2_fa[ix][1]), "FastaReader returned the wrong text (%s,%s)" % (fields[1],valid2_fa[ix][1]) |
---|
| 49 | |
---|
| 50 | def check_get (seqfile, valid_seq, start, len): |
---|
| 51 | assert seqfile.get (start, len) == valid_seq[start:start+len] |
---|
| 52 | |
---|
| 53 | test_classes = [SEQTestCase] |
---|
| 54 | suite = unittest.TestSuite ([unittest.makeSuite (c) for c in test_classes]) |
---|