root/galaxy-central/eggs/bx_python-0.5.0_dev_f74aec067563-py2.6-macosx-10.6-universal-ucs2.egg/bx/seq/seq_tests.py @ 3

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

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

行番号 
1"""
2Tests for `bx.seq.seq`.
3"""
4
5
6import unittest
7import os.path
8import sys
9import bx.seq, fasta_tests, nib_tests, qdna_tests
10
11test_fa     = "test_data/seq_tests/test.fa"
12test2_fa    = "test_data/seq_tests/test2.fa"
13test_nib    = "test_data/seq_tests/test.nib"
14test_qdna   = "test_data/seq_tests/test.qdna"
15
16valid_fasta = fasta_tests.valid_seq
17valid_nib   = nib_tests.valid_seq
18valid_qdna  = qdna_tests.valid_seq
19
20# Same sequences as stored in test2.fa
21
22valid2_fa = [("apple",      "GGCGCTGCGATAAGGTTGCGACAACACGGACCTTCTTTTGCCTACCTCTGTTCTTGGCACG"),
23             ("orange",     "CGTGCCGAGAACAGAAAATACGCCGGGCGGTGCAGTAGTATCTTGGTATCCGATATGCAGG"),
24             ("grapefruit", "CCTGCATATCGACTAGTACACCCTCCCGAGGTACCCCACCCATCCCTCTTTTCTCGGCGCG")]
25
26class 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
50def check_get (seqfile, valid_seq, start, len):
51    assert seqfile.get (start, len) == valid_seq[start:start+len]
52
53test_classes = [SEQTestCase]
54suite = unittest.TestSuite ([unittest.makeSuite (c) for c in test_classes])
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。