| 1 |
import unittest |
| 2 |
import sys |
| 3 |
import os |
| 4 |
import filecmp |
| 5 |
from ariba import read_filter, read_store, external_progs |
| 6 |
|
| 7 |
modules_dir = os.path.dirname(os.path.abspath(read_filter.__file__)) |
| 8 |
data_dir = os.path.join(modules_dir, 'tests', 'data') |
| 9 |
|
| 10 |
|
| 11 |
class TestReadFilter(unittest.TestCase): |
| 12 |
def setUp(self): |
| 13 |
self.external_progs = external_progs.ExternalProgs() |
| 14 |
|
| 15 |
|
| 16 |
# skip this, as no longer using cdhit2d, but leave it here in case we want |
| 17 |
# to put it back in at a later date |
| 18 |
def _test_run_cdhit_est_2d(self): |
| 19 |
'''test _run_cdhit_est_2d''' |
| 20 |
reads_in = os.path.join(data_dir, 'read_filter_test_run_cdhit_est_2d.reads.in.fa') |
| 21 |
ref_in = os.path.join(data_dir, 'read_filter_test_run_cdhit_est_2d.ref.in.fa') |
| 22 |
tmp_out = 'tmp.test_run_cdhit_est_2d.out' |
| 23 |
read_filter.ReadFilter._run_cdhit_est_2d(ref_in, reads_in, tmp_out, self.external_progs.exe('cdhit2d')) |
| 24 |
got_clustr = tmp_out + '.clstr' |
| 25 |
expected_clstr = os.path.join(data_dir, 'read_filter_test_run_cdhit_est_2d.expected.clstr') |
| 26 |
self.assertTrue(filecmp.cmp(got_clustr, expected_clstr, shallow=False)) |
| 27 |
os.unlink(got_clustr) |
| 28 |
|
| 29 |
|
| 30 |
def test_cdhit_clstr_to_reads(self): |
| 31 |
'''test _cdhit_clstr_to_reads''' |
| 32 |
infile = os.path.join(data_dir, 'read_filter_cdhit_clstr_to_reads.in.clstr') |
| 33 |
expected = {1, 3, 5, 7, 9, 11} |
| 34 |
got = read_filter.ReadFilter._cdhit_clstr_to_reads(infile) |
| 35 |
self.assertEqual(expected, got) |
| 36 |
|
| 37 |
|
| 38 |
# skip this, as no longer using cdhit2d, but leave it here in case we want |
| 39 |
# to put it back in at a later date |
| 40 |
def _test_run(self): |
| 41 |
'''test run''' |
| 42 |
rstore_infile = os.path.join(data_dir, 'read_filter_test_run.in.read_store') |
| 43 |
ref_fasta = os.path.join(data_dir, 'read_filter_test_run.in.ref.fa') |
| 44 |
expected_reads1 = os.path.join(data_dir, 'read_filter_test_run.expected.reads_1.fq') |
| 45 |
expected_reads2 = os.path.join(data_dir, 'read_filter_test_run.expected.reads_2.fq') |
| 46 |
tmp_rstore_prefix = 'tmp.filter_test_run.read_store' |
| 47 |
tmp_reads1 = 'tmp.filter_test_run.reads_1.fq' |
| 48 |
tmp_reads2 = 'tmp.filter_test_run.reads_2.fq' |
| 49 |
rstore = read_store.ReadStore(rstore_infile, tmp_rstore_prefix) |
| 50 |
rfilter = read_filter.ReadFilter(rstore, ref_fasta, '1', sys.stdout) |
| 51 |
got_reads, got_bases = rfilter.run(tmp_reads1, tmp_reads2) |
| 52 |
self.assertEqual(12, got_reads) |
| 53 |
self.assertEqual(912, got_bases) |
| 54 |
self.assertTrue(filecmp.cmp(expected_reads1, tmp_reads1, shallow=False)) |
| 55 |
self.assertTrue(filecmp.cmp(expected_reads2, tmp_reads2, shallow=False)) |
| 56 |
os.unlink(tmp_reads1) |
| 57 |
os.unlink(tmp_reads2) |
| 58 |
rstore.clean() |