Skip to content

Commit

Permalink
Removed Python 2 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfjlaros committed Jun 17, 2019
1 parent 0fa4fca commit ff096e4
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 130 deletions.
36 changes: 17 additions & 19 deletions backtranslate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
"""
backtranslate: Functions for reverse translation.
from os.path import dirname, abspath

from configparser import ConfigParser

Copyright (c) 2015 Leiden University Medical Center <[email protected]>
Copyright (c) 2015 Jeroen F.J. Laros <[email protected]>
from .backtranslate import BackTranslate

Licensed under the MIT license, see the LICENSE file.
"""
from __future__ import (
absolute_import, division, print_function, unicode_literals)
from future.builtins import str, zip

config = ConfigParser()
with open('{}/setup.cfg'.format(dirname(abspath(__file__)))) as handle:
config.read_file(handle)

__version_info__ = ('0', '1', '0')
_copyright_notice = 'Copyright (c) {} {} <{}>'.format(
config.get('metadata', 'copyright'),
config.get('metadata', 'author'),
config.get('metadata', 'author_email'))

__version__ = '.'.join(__version_info__)
__author__ = 'LUMC, Jeroen F.J. Laros'
__contact__ = '[email protected]'
__homepage__ = 'https://github.com/mutalyzer/backtranslate'

usage = __doc__.split("\n\n\n")
usage = [config.get('metadata', 'description'), _copyright_notice]


def doc_split(func):
return func.__doc__.split("\n\n")[0]
return func.__doc__.split('\n\n')[0]


def version(name):
return "%s version %s\n\nAuthor : %s <%s>\nHomepage : %s" % (name,
__version__, __author__, __contact__, __homepage__)
return '{} version {}\n\n{}\nHomepage: {}'.format(
config.get('metadata', 'name'),
config.get('metadata', 'version'),
_copyright_notice,
config.get('metadata', 'url'))
33 changes: 10 additions & 23 deletions backtranslate/backtranslate.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
from __future__ import (
absolute_import, division, print_function, unicode_literals)
from future.builtins import str, zip

from collections import defaultdict

from Bio.Data import CodonTable
from Levenshtein import hamming


def cmp_subst(subst_1, subst_2):
"""
Compare two substitution sets.
"""Compare two substitution sets.
:arg dict subst_1: Substitution set.
:arg dict subst_2: Substitution set.
Expand All @@ -28,8 +23,7 @@ def cmp_subst(subst_1, subst_2):


def reverse_translation_table(table_id=1):
"""
Calculate a reverse translation table.
"""Calculate a reverse translation table.
:arg int table_id: Translation table id.
Expand All @@ -47,20 +41,16 @@ def reverse_translation_table(table_id=1):


class BackTranslate(object):
"""
Back translation.
"""
"""Back translation."""
def __init__(self, table_id=1):
"""
Initialise the class.
"""Initialise the class.
:arg int table_id: Translation table id.
"""
self._back_table = reverse_translation_table(table_id)

def _one_subst(self, substitutions, reference_codon, amino_acid):
"""
Find single nucleotide substitutions that given a reference codon
"""Find single nucleotide substitutions that given a reference codon
explains an observed amino acid.
:arg defaultdict(set) substitutions: Set of single nucleotide
Expand All @@ -76,8 +66,7 @@ def _one_subst(self, substitutions, reference_codon, amino_acid):
(reference_codon[position], codon[position]))

def with_dna(self, reference_codon, amino_acid):
"""
Find single nucleotide substitutions that given a reference codon
"""Find single nucleotide substitutions that given a reference codon
explains an observed amino acid.
:arg str reference_codon: Original codon.
Expand All @@ -93,9 +82,8 @@ def with_dna(self, reference_codon, amino_acid):
return dict(substitutions)

def without_dna(self, reference_amino_acid, amino_acid):
"""
Find single nucleotide substitutions that given a reference amino acid
explains an observed amino acid.
"""Find single nucleotide substitutions that given a reference amino
acid explains an observed amino acid.
:arg str reference_amino_acid: Original amino acid.
:arg str amino_acid: Observed amino acid.
Expand All @@ -111,9 +99,8 @@ def without_dna(self, reference_amino_acid, amino_acid):
return dict(substitutions)

def improvable(self):
"""
Calculate all pairs of amino acid substututions that can be improved by
looking at the underlying codon.
"""Calculate all pairs of amino acid substututions that can be improved
by looking at the underlying codon.
:returns list: List of improvable substitutions.
"""
Expand Down
1 change: 1 addition & 0 deletions backtranslate/setup.cfg
10 changes: 2 additions & 8 deletions backtranslate/util.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
from __future__ import (
absolute_import, division, print_function, unicode_literals)
from future.builtins import str, zip

from Bio.Data import IUPACData


def _three_to_one():
"""
The three letter to one letter table for amino acids including stop.
"""The three letter to one letter table for amino acids including stop.
:returns dict: Three letter to one letter amino acids table.
"""
Expand All @@ -16,8 +11,7 @@ def _three_to_one():


def subst_to_cds(substitutions, offset):
"""
Convert a set of substitutions to CDS coordinates.
""" Convert a set of substitutions to CDS coordinates.
:arg dict substitutions: Set of single nucleotide substitutions indexed by
position.
Expand Down
29 changes: 29 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[metadata]
name = backtranslate
version = 0.1.1
description = Functions for reverse translation.
long_description = file: README.rst
author = LUMC, Jeroen F.J. Laros
author_email = [email protected]
url = https://github.com/mutalyzer/backtranslate
keywords = bioinformatics
license = MIT
classifiers =
Programming Language :: Python :: 3
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
copyright = 2015-2019

[options]
packages = find:
install_requires =
biopython
configparser
python-Levenshtein

[options.package_data]
backtranslate = setup.cfg

[options.entry_points]
console_scripts =
backtranslate = backtranslate.cli:main
79 changes: 1 addition & 78 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,81 +1,4 @@
import os
import sys

from setuptools import setup


package = 'backtranslate'
package_name = 'BackTranslate'
description = '{}: Functions for reverse translation.'.format(package_name)
documentation = 'README.md'
license = 'MIT License'
keywords = ['bioinformatics']

dependencies = ['biopython', 'future', 'python-Levenshtein']
develop_dependencies = ['fake-open', 'pytest', 'tox']
supported = [(2, 7), (3, 3), (3, 4)]
classifiers = [
'Development Status :: 3 - Alpha',
'Intended Audience :: Science/Research',
'Intended Audience :: Developers',
'Topic :: Scientific/Engineering :: Bio-Informatics',
]


if sys.version_info < supported[0]:
raise Exception('{} requires Python {}.{} or higher.'.format(
package, *supported[0]))

if sys.version_info[:2] == supported[0]:
dependencies.extend(['argparse', 'importlib'])

# This is quite the hack, but we don't want to import our package from here
# since that's recipe for disaster (it might have some uninstalled
# dependencies, or we might import another already installed version).
distmeta = {}
for line in open(os.path.join(package, '__init__.py')):
try:
field, value = (x.strip() for x in line.split('='))
except ValueError:
continue
if field == '__version_info__':
value = value.strip('[]()')
value = '.'.join(x.strip(' \'"') for x in value.split(','))
else:
value = value.strip('\'"')
distmeta[field] = value

try:
with open(documentation) as readme:
long_description = readme.read()
except IOError:
long_description = 'See ' + distmeta['__homepage__']

language_string = 'Programming Language :: Python'
classifiers += [
'License :: OSI Approved :: {}'.format(license),
'Operating System :: OS Independent',
language_string,
'{} :: {}'.format(language_string, supported[0][0]),
'{} :: {}'.format(language_string, supported[-1][0])] + \
['{} :: {}.{}'.format(language_string, *version) for version in supported]

setup(
name=package_name,
version=distmeta['__version_info__'],
description=description,
long_description=long_description,
author=distmeta['__author__'],
author_email=distmeta['__contact__'],
url=distmeta['__homepage__'],
license=license,
platforms=['any'],
packages=[package],
install_requires=dependencies,
tests_require=develop_dependencies,
entry_points={
'console_scripts': ['{0} = {0}.cli:main'.format(package)]
},
classifiers=classifiers,
keywords=' '.join(keywords)
)
setup()
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist = py27,py34
envlist = py35, py36

[testenv]
commands = py.test
commands = py.test -W error
whitelist_externals = py.test

0 comments on commit ff096e4

Please sign in to comment.