Commit dff07374 authored by Laros's avatar Laros
Browse files

Reproducible output.

parent 209cbfdc
*.pyc
*.egg-info
build
dist
.ipynb_checkpoints
build/
dist/
.ipynb_checkpoints/
.cache/
.tox/
......@@ -30,7 +30,7 @@ def with_dna(input_handle, output_handle, offset, position, amino_acid):
codon = reference[codon_pos:codon_pos + 3]
substitutions = bt.with_dna(codon, protein_letters_3to1[amino_acid])
for subst in subst_to_cds(substitutions, (position - 1) * 3):
for subst in sorted(subst_to_cds(substitutions, (position - 1) * 3)):
output_handle.write('{}\t{}\t{}\n'.format(*subst))
......@@ -58,7 +58,7 @@ def without_dna(output_handle, position, reference_amino_acid, amino_acid):
output_handle.write(
'This substitution can be improved by using `with_dna`.\n')
for subst in subst_to_cds(substitutions, (position - 1) * 3):
for subst in sorted(subst_to_cds(substitutions, (position - 1) * 3)):
output_handle.write('{}\t{}\t{}\n'.format(*subst))
......@@ -79,14 +79,15 @@ def find_stops(input_handle, output_handle, offset, compact):
for position in stop_positions:
if not compact:
for subst in stop_positions[position]:
for subst in sorted(stop_positions[position]):
output_handle.write('{}\t{}\t{}\n'.format(
offset + (index * 3) + position, *subst))
else:
output_handle.write('{}\t{}\t{}\n'.format(
offset + (index * 3) + position,
list(stop_positions[position])[0][0],
','.join(map(lambda x: x[1], stop_positions[position]))))
','.join(map(lambda x: x[1],
sorted(stop_positions[position])))))
def main():
......
......@@ -11,8 +11,8 @@ def _three_to_one():
:returns dict: Three letter to one letter amino acids table.
"""
return dict(map(lambda x: (str(x[0]), str(x[1])),
IUPACData.protein_letters_3to1_extended.items()) + [('Ter', '*')])
return dict(list(map(lambda x: (str(x[0]), str(x[1])),
IUPACData.protein_letters_3to1_extended.items()) + [('Ter', '*')]))
def subst_to_cds(substitutions, offset):
......
......@@ -12,6 +12,7 @@ license = 'MIT License'
keywords = ['bioinformatics']
dependencies = ['biopython', 'future', 'python-Levenshtein']
develop_dependencies = ['pytest', 'tox']
supported = [(2, 7), (3, 3), (3, 4)]
classifiers = [
'Development Status :: 3 - Alpha',
......@@ -71,6 +72,7 @@ setup(
platforms=['any'],
packages=[package],
install_requires=dependencies,
tests_require=develop_dependencies,
entry_points={
'console_scripts': ['{0} = {0}.cli:main'.format(package)]
},
......
......@@ -5,14 +5,16 @@ from __future__ import (
absolute_import, division, print_function, unicode_literals)
from future.builtins import str, zip
import StringIO
import md5
import sys
from hashlib import md5
from io import StringIO
from backtranslate import cli
def md5_check(data, md5sum):
return md5.md5(data).hexdigest() == md5sum
return md5(data).hexdigest() == md5sum
class TestParser(object):
......@@ -21,7 +23,7 @@ class TestParser(object):
"""
def setup(self):
self._input = open('data/mhv.fa')
self._output = StringIO.StringIO()
self._output = StringIO()
def test_with_dna(self):
cli.with_dna(self._input, self._output, 210, 1, 'Leu')
......@@ -36,9 +38,9 @@ class TestParser(object):
def test_find_stops(self):
cli.find_stops(self._input, self._output, 210, False)
assert md5_check(
self._output.getvalue(), 'b3dbcc94594ab61e36dbb2256d4b4561')
self._output.getvalue(), '41c105e384651201970c0b2efd3afa3e')
def test_find_stops_compact(self):
cli.find_stops(self._input, self._output, 210, True)
assert md5_check(
self._output.getvalue(), '34aa553f2ea72ca992b2568a963c27ee')
self._output.getvalue(), '67c62854f4c0972e3fbf3dcec81b6a94')
[tox]
envlist = py27,py34
[testenv]
commands = py.test
whitelist_externals = py.test
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment