| 1 |
|
| 2 |
|
| 3 |
import unittest |
| 4 |
import os |
| 5 |
import shutil |
| 6 |
|
| 7 |
from utils import aug_assertions |
| 8 |
from utils import aug_process |
| 9 |
from utils import aug_path |
| 10 |
|
| 11 |
pathname = 'auxprogs/bam2hints/' |
| 12 |
referencedir = os.path.join(pathname, 'expected_results') |
| 13 |
resultdir = os.path.join(pathname, 'result_files') |
| 14 |
htmldir = os.path.join('output_html/') |
| 15 |
tmpdir = os.path.join(pathname, 'tmp') |
| 16 |
exampledir = os.path.join(pathname, 'test_files') |
| 17 |
testfilename = 'test.s.sorted.bam' |
| 18 |
reffilename = 'test.intron.gff' |
| 19 |
|
| 20 |
bindir = '../../bin/' |
| 21 |
bam2hintsbin = bindir + 'bam2hints' |
| 22 |
default_wd = os.getcwd() |
| 23 |
|
| 24 |
|
| 25 |
def clean(force_tmp_dir=True, force_html_dir=True, force_result_dir=True): |
| 26 |
"""Remove empty directories or if forced""" |
| 27 |
aug_path.rmtree_if_exists(resultdir, force_result_dir) |
| 28 |
aug_path.rmtree_if_exists(tmpdir, force_tmp_dir) |
| 29 |
aug_path.rmtree_if_exists(htmldir, force_html_dir) |
| 30 |
|
| 31 |
|
| 32 |
class TestBam2Hints(unittest.TestCase): |
| 33 |
|
| 34 |
opt_compare = False |
| 35 |
opt_html = False |
| 36 |
|
| 37 |
@classmethod |
| 38 |
def setUpClass(cls): |
| 39 |
os.chdir(default_wd) |
| 40 |
clean(force_tmp_dir=False, force_html_dir=True, force_result_dir=True) |
| 41 |
aug_path.mkdir_if_not_exists(resultdir) |
| 42 |
aug_path.mkdir_if_not_exists(tmpdir) |
| 43 |
|
| 44 |
inputfile = os.path.join(exampledir, testfilename) |
| 45 |
testfile = os.path.join(tmpdir, testfilename) |
| 46 |
shutil.copyfile(inputfile, testfile) |
| 47 |
|
| 48 |
|
| 49 |
@classmethod |
| 50 |
def tearDownClass(cls): |
| 51 |
os.chdir(default_wd) |
| 52 |
clean(force_tmp_dir=False, force_html_dir=False, force_result_dir=False) |
| 53 |
|
| 54 |
def test_bam2hints(self): |
| 55 |
os.chdir(default_wd) |
| 56 |
testfile = os.path.join(tmpdir, testfilename) |
| 57 |
reffile = os.path.join(referencedir, reffilename) |
| 58 |
resfile = os.path.join(resultdir, reffilename) |
| 59 |
|
| 60 |
aug_process.execute( |
| 61 |
self, bam2hintsbin + ' --in=' + testfile + ' --out=' + resfile) |
| 62 |
|
| 63 |
|
| 64 |
if TestBam2Hints.opt_compare: |
| 65 |
aug_assertions.assertEqualFiles( |
| 66 |
self, reffile, resfile, TestBam2Hints.opt_html, htmldir) |
| 67 |
os.remove(resfile) |
| 68 |
|
| 69 |
def test_bam2hints_pipes(self): |
| 70 |
os.chdir(default_wd) |
| 71 |
testfile = os.path.join(tmpdir, testfilename) |
| 72 |
reffile = os.path.join(referencedir, reffilename) |
| 73 |
resfile = os.path.join(resultdir, reffilename) |
| 74 |
|
| 75 |
aug_process.execute( |
| 76 |
self, 'cat ' + testfile + ' | ' + bam2hintsbin, resfile) |
| 77 |
|
| 78 |
|
| 79 |
if TestBam2Hints.opt_compare: |
| 80 |
aug_assertions.assertEqualFiles( |
| 81 |
self, reffile, resfile, TestBam2Hints.opt_html, htmldir) |
| 82 |
os.remove(resfile) |
| 83 |
|
| 84 |
|
| 85 |
def test_suite(): |
| 86 |
suite = unittest.TestSuite() |
| 87 |
suite.addTest(TestBam2Hints('test_bam2hints')) |
| 88 |
suite.addTest(TestBam2Hints('test_bam2hints_pipes')) |
| 89 |
|
| 90 |
return suite |
| 91 |
|
| 92 |
|
| 93 |
def execute(compare, html, mysql): |
| 94 |
TestBam2Hints.opt_compare = compare |
| 95 |
TestBam2Hints.opt_html = html |
| 96 |
|
| 97 |
runner = unittest.TextTestRunner(verbosity=2) |
| 98 |
result = runner.run(test_suite()) |
| 99 |
|
| 100 |
return result.wasSuccessful() |