| 1 |
|
| 2 |
|
| 3 |
import unittest |
| 4 |
import os |
| 5 |
|
| 6 |
from utils import aug_assertions |
| 7 |
from utils import aug_process |
| 8 |
from utils import aug_path |
| 9 |
|
| 10 |
|
| 11 |
default_wd = os.getcwd() |
| 12 |
pathname = os.path.join(default_wd, 'auxprogs/homgenemapping') |
| 13 |
referencedir = os.path.join(pathname, 'expected_results') |
| 14 |
resultdir = os.path.join(pathname, 'result_files') |
| 15 |
examplesdir = os.path.join('../../', 'examples') |
| 16 |
htmldir = os.path.join(default_wd, 'output_html') |
| 17 |
tmpdir = os.path.join(pathname, 'tmp') |
| 18 |
testdir = os.path.join(pathname, 'test_files') |
| 19 |
bindir = os.path.join('../../../../../', 'bin/') |
| 20 |
hgmbin = bindir+ 'homGeneMapping' |
| 21 |
load2sqlbin = '../../bin/load2sqlitedb' |
| 22 |
|
| 23 |
gtffilenames_with_hints = os.path.join( |
| 24 |
os.path.join(default_wd, testdir), 'gtffilenames.tbl') |
| 25 |
gtffilenames_without_hints = os.path.join( |
| 26 |
tmpdir, 'gtffilenames_without_hints.tbl') |
| 27 |
sqlitedb = os.path.join(tmpdir, 'homGeneMapping_hints.db') |
| 28 |
|
| 29 |
|
| 30 |
def clean(force_tmp_dir=True, force_html_dir=True, force_result_dir=True): |
| 31 |
"""Remove empty directories or if forced""" |
| 32 |
aug_path.rmtree_if_exists(resultdir, force_result_dir) |
| 33 |
aug_path.rmtree_if_exists(tmpdir, force_tmp_dir) |
| 34 |
aug_path.rmtree_if_exists(htmldir, force_html_dir) |
| 35 |
|
| 36 |
|
| 37 |
class TestHomGeneMapping(unittest.TestCase): |
| 38 |
|
| 39 |
opt_compare = False |
| 40 |
opt_html = False |
| 41 |
|
| 42 |
@classmethod |
| 43 |
def setUpClass(cls): |
| 44 |
os.chdir(default_wd) |
| 45 |
clean(force_tmp_dir=False, force_html_dir=True, force_result_dir=True) |
| 46 |
aug_path.mkdir_if_not_exists(resultdir) |
| 47 |
aug_path.mkdir_if_not_exists(tmpdir) |
| 48 |
|
| 49 |
|
| 50 |
aug_process.execute(None, |
| 51 |
'cat ' + gtffilenames_with_hints + ' | sed "s/gtf\\t.*/gtf/g"', |
| 52 |
gtffilenames_without_hints) |
| 53 |
|
| 54 |
|
| 55 |
out_load2sqlitedb = os.path.join(tmpdir, 'out_load2sqlitedb.txt') |
| 56 |
if os.path.exists(sqlitedb): |
| 57 |
os.remove(sqlitedb) |
| 58 |
|
| 59 |
aug_process.execute(None, |
| 60 |
load2sqlbin +' --species=hg19 --dbaccess=' + sqlitedb + ' ' + examplesdir + '/cgp/human.fa', |
| 61 |
out_load2sqlitedb) |
| 62 |
aug_process.execute(None, |
| 63 |
load2sqlbin + ' --species=mm9 --dbaccess=' +sqlitedb +' '+examplesdir+'/cgp/mouse.fa', |
| 64 |
out_load2sqlitedb) |
| 65 |
aug_process.execute(None, |
| 66 |
load2sqlbin +' --noIdx --species=hg19 --dbaccess=' + sqlitedb + ' ' + testdir + '/gtfs/human.hints.gff', |
| 67 |
out_load2sqlitedb) |
| 68 |
aug_process.execute(None, |
| 69 |
load2sqlbin + ' --noIdx --species=mm9 --dbaccess=' + sqlitedb + ' ' + testdir + '/gtfs/mouse.hints.gff', |
| 70 |
out_load2sqlitedb) |
| 71 |
aug_process.execute(None, |
| 72 |
load2sqlbin + ' --makeIdx --dbaccess=' + sqlitedb, |
| 73 |
out_load2sqlitedb) |
| 74 |
|
| 75 |
@classmethod |
| 76 |
def tearDownClass(cls): |
| 77 |
os.chdir(default_wd) |
| 78 |
clean(force_tmp_dir=False, force_html_dir=False, force_result_dir=False) |
| 79 |
|
| 80 |
def test_homGeneMapping_without_hints(self): |
| 81 |
''' |
| 82 |
test without hints |
| 83 |
gtffilenames_without_hints.tbl - is gtffilenames.tbl with hints removed |
| 84 |
.../bin/homGeneMapping --noDupes --gtfs=.../gtffilenames_without_hints.tbl |
| 85 |
--halfile=aln.hal --tmpdir=.../tmp --outdir=...//outdir |
| 86 |
--printHomologs=.../homologs.txt > .../homGeneMapping.out) |
| 87 |
''' |
| 88 |
os.chdir(os.path.join(default_wd, testdir)) |
| 89 |
refdir = os.path.join(referencedir, 'without_hints') |
| 90 |
outputdir = os.path.join(resultdir, 'without_hints') |
| 91 |
aug_path.mkdir_if_not_exists(refdir) |
| 92 |
aug_path.mkdir_if_not_exists(outputdir) |
| 93 |
resfile = os.path.join(outputdir, 'homGeneMapping.out') |
| 94 |
|
| 95 |
args = '--noDupes --gtfs=' + gtffilenames_without_hints + ' --halfile=aln.hal \ |
| 96 |
--tmpdir=' + outputdir +'/tmp --outdir=' + outputdir + '/outdir \ |
| 97 |
--printHomologs=' + outputdir + '/homologs.txt' |
| 98 |
|
| 99 |
aug_process.execute(self, hgmbin + ' ' +args, resfile) |
| 100 |
|
| 101 |
|
| 102 |
if TestHomGeneMapping.opt_compare: |
| 103 |
aug_assertions.assertEqualDirectory(self, refdir, outputdir, |
| 104 |
TestHomGeneMapping.opt_html, |
| 105 |
htmldir) |
| 106 |
|
| 107 |
def test_homGeneMapping_with_file_hints(self): |
| 108 |
''' |
| 109 |
test with hints provided by file |
| 110 |
.../bin/homGeneMapping --noDupes --gtfs=gtffilenames.tbl --halfile=aln.hal |
| 111 |
--tmpdir=.../tmp --outdir=.../outdir |
| 112 |
--printHomologs=.../homologs.txt > .../homGeneMapping.out |
| 113 |
''' |
| 114 |
|
| 115 |
os.chdir(os.path.join(default_wd, testdir)) |
| 116 |
refdir = os.path.join(referencedir, 'with_hints') |
| 117 |
outputdir = os.path.join(resultdir, 'with_hints') |
| 118 |
aug_path.mkdir_if_not_exists(refdir) |
| 119 |
aug_path.mkdir_if_not_exists(outputdir) |
| 120 |
resfile = os.path.join(outputdir, 'homGeneMapping.out') |
| 121 |
args = '--noDupes --gtfs=' + gtffilenames_with_hints + ' --halfile=aln.hal \ |
| 122 |
--tmpdir=' + outputdir + '/tmp --outdir=' + outputdir + '/outdir \ |
| 123 |
--printHomologs=' + outputdir + '/homologs.txt' |
| 124 |
|
| 125 |
aug_process.execute(self, hgmbin + ' ' + args, resfile) |
| 126 |
|
| 127 |
|
| 128 |
if TestHomGeneMapping.opt_compare: |
| 129 |
aug_assertions.assertEqualDirectory( |
| 130 |
self, refdir, outputdir, TestHomGeneMapping.opt_html, htmldir) |
| 131 |
|
| 132 |
def test_homGeneMapping_with_sql_hints(self): |
| 133 |
''' |
| 134 |
test with hints provided by SQLite database |
| 135 |
.../bin/homGeneMapping --noDupes --gtfs=.../gtffilenames_without_hints.tbl |
| 136 |
--dbaccess=.../homGeneMapping_hints.db --halfile=aln.hal |
| 137 |
--tmpdir=.../tmp --outdir=.../outdir |
| 138 |
--printHomologs=.../homologs.txt > .../homGeneMapping.out |
| 139 |
''' |
| 140 |
os.chdir(os.path.join(default_wd, testdir)) |
| 141 |
refdir = os.path.join(referencedir, 'with_hints') |
| 142 |
outputdir = os.path.join(resultdir, 'with_sql_hints') |
| 143 |
aug_path.mkdir_if_not_exists(refdir) |
| 144 |
aug_path.mkdir_if_not_exists(outputdir) |
| 145 |
resfile = os.path.join(outputdir, 'homGeneMapping.out') |
| 146 |
|
| 147 |
args = '--noDupes --gtfs=' + gtffilenames_without_hints + \ |
| 148 |
' --dbaccess=' + sqlitedb + ' --halfile=aln.hal \ |
| 149 |
--tmpdir=' + outputdir + '/tmp --outdir=' + outputdir + '/outdir \ |
| 150 |
--printHomologs=' + outputdir + '/homologs.txt' |
| 151 |
|
| 152 |
aug_process.execute(self, hgmbin + ' ' + args, resfile) |
| 153 |
|
| 154 |
|
| 155 |
if TestHomGeneMapping.opt_compare: |
| 156 |
aug_assertions.assertEqualDirectory( |
| 157 |
self, refdir, outputdir, TestHomGeneMapping.opt_html, htmldir) |
| 158 |
|
| 159 |
|
| 160 |
def test_suite(): |
| 161 |
print('Start Test...') |
| 162 |
suite = unittest.TestSuite() |
| 163 |
suite.addTest(TestHomGeneMapping('test_homGeneMapping_without_hints')) |
| 164 |
suite.addTest(TestHomGeneMapping('test_homGeneMapping_with_file_hints')) |
| 165 |
suite.addTest(TestHomGeneMapping('test_homGeneMapping_with_sql_hints')) |
| 166 |
|
| 167 |
return suite |
| 168 |
|
| 169 |
|
| 170 |
def execute(compare, html, mysql): |
| 171 |
TestHomGeneMapping.opt_compare = compare |
| 172 |
TestHomGeneMapping.opt_html = html |
| 173 |
|
| 174 |
runner = unittest.TextTestRunner(verbosity=2) |
| 175 |
result = runner.run(test_suite()) |
| 176 |
|
| 177 |
return result.wasSuccessful() |