Skip to content

Commit

Permalink
updates towards P3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
TomSmithCGAT committed Apr 8, 2016
1 parent b2f072a commit c826b80
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
2 changes: 2 additions & 0 deletions setup.cfg
@@ -0,0 +1,2 @@
[metadata]
description-file = README.rst
19 changes: 7 additions & 12 deletions setup.py
Expand Up @@ -53,19 +53,13 @@

major, minor1, minor2, s, tmp = sys.version_info

# Need to check Python 3 compatibility
if major == 3:
raise SystemExit("""UMI-tools is not fully python3 compatible""")
# Need to comfirm Python 3 compatibility
#if major == 3:
# raise SystemExit("""UMI-tools is not fully python3 compatible""")

if (major == 2 and minor1 < 7) or major < 2:
raise SystemExit("""UMI-tools requires Python 2.7 or later.""")

# use requires.txt to identify requirements
#requires = []
#for requirement in (
# l.strip() for l in open('requires.txt') if not l.startswith("#")):
# requires.append(requirement)

umi_tools_packages = ["umi_tools"]
umi_tools_package_dirs = {'umi_tools': 'umi_tools'}

Expand Down Expand Up @@ -110,7 +104,7 @@
"cython>=0.19",
"numpy>=1.7",
"pandas>=0.12.0",
"pysam>=0.8.4",
"pysam==0.8.4",
"future"]
setup(
# package information
Expand All @@ -119,19 +113,20 @@
description='umi-tools: Tools for UMI analyses',
author='Ian Sudbury',
author_email='i.sudbery@sheffield.ac.uk',
license="BSD",
license="MIT",
platforms=["any"],
keywords="computational genomics",
long_description='umi-tools: Tools for UMI analyses',
classifiers=filter(None, classifiers.split("\n")),
url="https://github.com/CGATOxford/UMI-tools",
download_url="https://github.com/CGATOxford/UMI-tools/tarball/0.0.3",
# package contents
packages=umi_tools_packages,
package_dir=umi_tools_package_dirs,
include_package_data=True,
# dependencies
install_requires=requires,
#cmdclass={'build_ext': build_ext},
cmdclass={'build_ext': build_ext},
entry_points={
'console_scripts': ['umi_tools = umi_tools.umi_tools:main']
},
Expand Down
5 changes: 3 additions & 2 deletions umi_tools/Utilities.py
Expand Up @@ -253,6 +253,7 @@ class method (:func:`cachedmethod`) calls.
import random
import uuid

from builtins import bytes, chr

class DefaultOptions:
stdlog = sys.stdout
Expand Down Expand Up @@ -526,12 +527,12 @@ def getParams(options=None):
if options:
members = options.__dict__
for k, v in sorted(members.items()):
result.append("# %-40s: %s" % (k, str(v).encode("string_escape")))
result.append("# %-40s: %s" % (k, str(v)))
else:
vars = inspect.currentframe().f_back.f_locals
for var in filter(lambda x: re.match("param_", x), vars.keys()):
result.append("# %-40s: %s" %
(var, str(vars[var]).encode("string_escape")))
(var, str(vars[var])))

if result:
return "\n".join(result)
Expand Down
16 changes: 10 additions & 6 deletions umi_tools/dedup.py
Expand Up @@ -169,6 +169,7 @@

# required to make iteritems python2 and python3 compatible
from future.utils import iteritems
from builtins import dict

import pysam

Expand Down Expand Up @@ -216,7 +217,8 @@ def get_average_umi_distance(umis):
if len(umis) == 1:
return -1

dists = [edit_distance(x, y) for x, y in itertools.combinations(umis, 2)]
dists = [edit_distance(x.encode('utf-8'), y.encode('utf-8')) for
x, y in itertools.combinations(umis, 2)]
return float(sum(dists))/(len(dists))


Expand Down Expand Up @@ -299,15 +301,17 @@ def _get_adj_list_adjacency(self, umis, counts, threshold):
''' identify all umis within hamming distance threshold'''

return {umi: [umi2 for umi2 in umis if
edit_distance(umi, umi2) <= threshold]
edit_distance(umi.encode('utf-8'),
umi2.encode('utf-8')) <= threshold]
for umi in umis}

def _get_adj_list_directional_adjacency(self, umis, counts, threshold):
''' identify all umis within the hamming distance threshold
and where the counts of the first umi is > (2 * second umi counts)-1'''

return {umi: [umi2 for umi2 in umis if
edit_distance(umi, umi2) == 1 and
edit_distance(umi.encode('utf-8'),
umi2.encode('utf-8')) == 1 and
counts[umi] >= (counts[umi2]*2)-1] for umi in umis}

def _get_adj_list_null(self, umis, counts, threshold):
Expand Down Expand Up @@ -530,7 +534,7 @@ def get_bundles(insam, ignore_umi=False, subset=None, quality_threshold=0,
out_keys = reads_dict.keys()

for p in out_keys:
for bundle in reads_dict[p].itervalues():
for bundle in reads_dict[p].values():
yield bundle
del reads_dict[p]
del read_counts[p]
Expand Down Expand Up @@ -572,7 +576,7 @@ def get_bundles(insam, ignore_umi=False, subset=None, quality_threshold=0,
out_keys = [x for x in reads_dict.keys() if x <= start-1000]

for p in out_keys:
for bundle in reads_dict[p].itervalues():
for bundle in reads_dict[p].values():
yield bundle
del reads_dict[p]
del read_counts[p]
Expand Down Expand Up @@ -632,7 +636,7 @@ def get_bundles(insam, ignore_umi=False, subset=None, quality_threshold=0,

# yield remaining bundles
for p in reads_dict:
for bundle in reads_dict[p].itervalues():
for bundle in reads_dict[p].values():
yield bundle


Expand Down
2 changes: 1 addition & 1 deletion umi_tools/version.py
@@ -1,2 +1,2 @@

__version__ = "0.0.3"
__version__ = "0.0.4"

0 comments on commit c826b80

Please sign in to comment.