Skip to content

Commit

Permalink
fix python 2 to 3 encoding compatiblity issue
Browse files Browse the repository at this point in the history
  • Loading branch information
hannaml committed Oct 29, 2014
1 parent 2edfc49 commit 5fcaa25
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 37 deletions.
74 changes: 38 additions & 36 deletions test/test_tools_bwa.py
Expand Up @@ -8,53 +8,55 @@

class TestToolBwa(unittest.TestCase) :

def setUp(self) :
util.file.set_tmpDir('TestToolBwa')
self.bwa = tools.bwa.Bwa()
self.bwa.install()
def setUp(self) :
util.file.set_tmpDir('TestToolBwa')
self.bwa = tools.bwa.Bwa()
self.bwa.install()


def tearDown(self) :
util.file.destroy_tmpDir()
def tearDown(self) :
util.file.destroy_tmpDir()

def test_tool_bwa_index(self) :
referenceDir = util.file.get_test_input_path()
expectedDir = util.file.get_test_input_path(self)
def test_tool_bwa_index(self) :
referenceDir = util.file.get_test_input_path()
expectedDir = util.file.get_test_input_path(self)

fasta = os.path.join(referenceDir, 'ebola.fasta')
self.bwa.execute('index', [fasta])
fasta = os.path.join(referenceDir, 'ebola.fasta')
self.bwa.execute('index', [fasta])

expected_fasta = os.path.join(expectedDir, 'ebola_expected.fasta')
extensions = ['amb', 'ann', 'bwt', 'pac', 'sa']
for ext in extensions:
result = '{}.{}'.format(fasta, ext)
expect = '{}.{}'.format(expected_fasta, ext)
self.assertEqual(open(result).read(),
open(expect).read())
expected_fasta = os.path.join(expectedDir, 'ebola_expected.fasta')
extensions = ['amb', 'ann', 'bwt', 'pac', 'sa']
for ext in extensions:
result = open('{}.{}'.format(fasta, ext), 'rb')
expect = open('{}.{}'.format(expected_fasta, ext), 'rb')

def test_tool_bwa_aln(self) :
# referenceDir = util.file.get_test_input_path()
expectedDir = util.file.get_test_input_path(self)
self.assertEqual(result.read(),
expect.read() )

# can used expected out for index as input
reference = os.path.join(expectedDir, 'ebola_expected.fasta')
fastq = os.path.join(expectedDir, 'ebola_aln_input.fastq')
output = "{}.sai".format(util.file.mkstempfname())
expect = os.path.join(expectedDir, 'ebola_aln_expected.sai')
result.close(); expect.close()

def test_tool_bwa_aln(self) :
# referenceDir = util.file.get_test_input_path()
expectedDir = util.file.get_test_input_path(self)

bwa = tools.bwa.Bwa()
bwa.install()
# can used expected out for index as input
reference = os.path.join(expectedDir, 'ebola_expected.fasta')
fastq = os.path.join(expectedDir, 'ebola_aln_input.fastq')
output = "{}.sai".format(util.file.mkstempfname())
expect = os.path.join(expectedDir, 'ebola_aln_expected.sai')

bwa.execute('aln', [reference, fastq], options={'-q': 5, '-t': 4},
post_cmd=" > {}".format(output))

self.assertEqual(open(output).read(),
open(expect).read())
# extensions = ['amb', 'ann', 'bwt', 'pac', 'sa']
# for ext in extensions:
# result = '{}.{}'.format(fasta, ext)
# expect = '{}.{}'.format(expected_fasta, ext)
bwa = tools.bwa.Bwa()
bwa.install()

bwa.execute('aln', [reference, fastq], options={'-q': 5, '-t': 4},
post_cmd=" > {}".format(output))

result = open(output, 'rb')
gold = open(expect, 'rb')
self.assertEqual(result.read(),
gold.read())
result.close(); gold.close()

if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion tools/bwa.py
Expand Up @@ -53,7 +53,7 @@ def execute(self, subcommand, args=[], options={}, option_string="",
"""
arg_str = " ".join(args)
option_str = '{} {}'.format(' '.join([ "{} {}".format(k, v) for k, v in
options.iteritems() ]),
options.items() ]),
option_string
)
cmd = "{self.exec_path} {subcommand} {option_str} {arg_str} {post_cmd}" \
Expand Down

0 comments on commit 5fcaa25

Please sign in to comment.