Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mirrors
backtranslate
Commits
dff07374
Commit
dff07374
authored
Oct 30, 2016
by
Laros
Browse files
Reproducible output.
parent
209cbfdc
Changes
6
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
dff07374
*.pyc
*.egg-info
build
dist
.ipynb_checkpoints
build/
dist/
.ipynb_checkpoints/
.cache/
.tox/
backtranslate/cli.py
View file @
dff07374
...
...
@@ -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
():
...
...
backtranslate/util.py
View file @
dff07374
...
...
@@ -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
):
...
...
setup.py
View file @
dff07374
...
...
@@ -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
)]
},
...
...
tests/test_cli.py
View file @
dff07374
...
...
@@ -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.ini
0 → 100644
View file @
dff07374
[tox]
envlist
=
py27,py34
[testenv]
commands
=
py.test
whitelist_externals
=
py.test
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment