PeteHaitch / methtuple

methtuple is a methylation caller for methylation events that co-occur on the same DNA fragment from high-throughput bisulfite sequencing data, such as methylC-seq.
MIT License
12 stars 3 forks source link

Python3 support #75

Closed PeteHaitch closed 10 years ago

PeteHaitch commented 10 years ago

Currently failing Travis build. Need to try building locally using Python3 to figure out why it doesn't work out-of-the-box.

PeteHaitch commented 10 years ago

Tried installed on python 3.4 but fails:

(py34)Peters-MacBook-Pro:Comethylation Peter$ python setup.py install
running install
running bdist_egg
running egg_info
writing comethylation.egg-info/PKG-INFO
writing top-level names to comethylation.egg-info/top_level.txt
writing requirements to comethylation.egg-info/requires.txt
writing dependency_links to comethylation.egg-info/dependency_links.txt
reading manifest file 'comethylation.egg-info/SOURCES.txt'
writing manifest file 'comethylation.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.5-x86_64/egg
running install_lib
running build_py
creating build/bdist.macosx-10.5-x86_64/egg
creating build/bdist.macosx-10.5-x86_64/egg/comethylation
copying build/lib/comethylation/__init__.py -> build/bdist.macosx-10.5-x86_64/egg/comethylation
copying build/lib/comethylation/funcs.py -> build/bdist.macosx-10.5-x86_64/egg/comethylation
copying build/lib/comethylation/mtuple.py -> build/bdist.macosx-10.5-x86_64/egg/comethylation
creating build/bdist.macosx-10.5-x86_64/egg/comethylation/scripts
copying build/lib/comethylation/scripts/comethylation -> build/bdist.macosx-10.5-x86_64/egg/comethylation/scripts
creating build/bdist.macosx-10.5-x86_64/egg/comethylation/tests
copying build/lib/comethylation/tests/__init__.py -> build/bdist.macosx-10.5-x86_64/egg/comethylation/tests
byte-compiling build/bdist.macosx-10.5-x86_64/egg/comethylation/__init__.py to __init__.cpython-34.pyc
byte-compiling build/bdist.macosx-10.5-x86_64/egg/comethylation/funcs.py to funcs.cpython-34.pyc
  File "build/bdist.macosx-10.5-x86_64/egg/comethylation/funcs.py", line 372
    print positions_1
                    ^
SyntaxError: invalid syntax

byte-compiling build/bdist.macosx-10.5-x86_64/egg/comethylation/mtuple.py to mtuple.cpython-34.pyc
  File "build/bdist.macosx-10.5-x86_64/egg/comethylation/mtuple.py", line 36
    print 'Sample name =', self.sample_name
                        ^
SyntaxError: invalid syntax

byte-compiling build/bdist.macosx-10.5-x86_64/egg/comethylation/tests/__init__.py to __init__.cpython-34.pyc
Sorry: TabError: inconsistent use of tabs and spaces in indentation (__init__.py, line 682)
creating build/bdist.macosx-10.5-x86_64/egg/EGG-INFO
installing scripts to build/bdist.macosx-10.5-x86_64/egg/EGG-INFO/scripts
running install_scripts
running build_scripts
creating build/bdist.macosx-10.5-x86_64/egg/EGG-INFO/scripts
copying build/scripts-3.4/comethylation -> build/bdist.macosx-10.5-x86_64/egg/EGG-INFO/scripts
changing mode of build/bdist.macosx-10.5-x86_64/egg/EGG-INFO/scripts/comethylation to 755
copying comethylation.egg-info/PKG-INFO -> build/bdist.macosx-10.5-x86_64/egg/EGG-INFO
copying comethylation.egg-info/SOURCES.txt -> build/bdist.macosx-10.5-x86_64/egg/EGG-INFO
copying comethylation.egg-info/dependency_links.txt -> build/bdist.macosx-10.5-x86_64/egg/EGG-INFO
copying comethylation.egg-info/not-zip-safe -> build/bdist.macosx-10.5-x86_64/egg/EGG-INFO
copying comethylation.egg-info/requires.txt -> build/bdist.macosx-10.5-x86_64/egg/EGG-INFO
copying comethylation.egg-info/top_level.txt -> build/bdist.macosx-10.5-x86_64/egg/EGG-INFO
creating 'dist/comethylation-1.1.0-py3.4.egg' and adding 'build/bdist.macosx-10.5-x86_64/egg' to it
removing 'build/bdist.macosx-10.5-x86_64/egg' (and everything under it)
Processing comethylation-1.1.0-py3.4.egg
removing '/anaconda/envs/py34/lib/python3.4/site-packages/comethylation-1.1.0-py3.4.egg' (and everything under it)
creating /anaconda/envs/py34/lib/python3.4/site-packages/comethylation-1.1.0-py3.4.egg
Extracting comethylation-1.1.0-py3.4.egg to /anaconda/envs/py34/lib/python3.4/site-packages
  File "/anaconda/envs/py34/lib/python3.4/site-packages/comethylation-1.1.0-py3.4.egg/comethylation/funcs.py", line 372
    print positions_1
                    ^
SyntaxError: invalid syntax

  File "/anaconda/envs/py34/lib/python3.4/site-packages/comethylation-1.1.0-py3.4.egg/comethylation/mtuple.py", line 36
    print 'Sample name =', self.sample_name
                        ^
SyntaxError: invalid syntax

Sorry: TabError: inconsistent use of tabs and spaces in indentation (__init__.py, line 682)
comethylation 1.1.0 is already the active version in easy-install.pth
Installing comethylation script to //anaconda/envs/py34/bin

Installed /anaconda/envs/py34/lib/python3.4/site-packages/comethylation-1.1.0-py3.4.egg
Processing dependencies for comethylation==1.1.0
Searching for pysam==0.7.8
Best match: pysam 0.7.8
Processing pysam-0.7.8-py3.4-macosx-10.5-x86_64.egg
pysam 0.7.8 is already the active version in easy-install.pth

Using /anaconda/envs/py34/lib/python3.4/site-packages/pysam-0.7.8-py3.4-macosx-10.5-x86_64.egg
Searching for Cython==0.20.1
Best match: Cython 0.20.1
Adding Cython 0.20.1 to easy-install.pth file

Using /anaconda/envs/py34/lib/python3.4/site-packages
Finished processing dependencies for comethylation==1.1.0

Tried to run help:

(py34)Peters-MacBook-Pro:Comethylation Peter$ comethylation -h
Traceback (most recent call last):
  File "//anaconda/envs/py34/bin/comethylation", line 5, in <module>
    pkg_resources.run_script('comethylation==1.1.0', 'comethylation')
  File "//anaconda/envs/py34/lib/python3.4/site-packages/setuptools-3.6-py3.4.egg/pkg_resources.py", line 534, in run_script
  File "//anaconda/envs/py34/lib/python3.4/site-packages/setuptools-3.6-py3.4.egg/pkg_resources.py", line 1434, in run_script
  File "//anaconda/envs/py34/lib/python3.4/site-packages/setuptools-3.6-py3.4.egg/pkg_resources.py", line 55, in execfile
  File "/anaconda/envs/py34/lib/python3.4/site-packages/comethylation-1.1.0-py3.4.egg/EGG-INFO/scripts/comethylation", line 286
    print "comethylation (v"+__version__+")\n"
                           ^
SyntaxError: invalid syntax

Tried to run tests:

running test
running egg_info
writing top-level names to comethylation.egg-info/top_level.txt
writing comethylation.egg-info/PKG-INFO
writing dependency_links to comethylation.egg-info/dependency_links.txt
writing requirements to comethylation.egg-info/requires.txt
reading manifest file 'comethylation.egg-info/SOURCES.txt'
writing manifest file 'comethylation.egg-info/SOURCES.txt'
running build_ext
Traceback (most recent call last):
  File "setup.py", line 29, in <module>
    'comethylation/scripts/comethylation'
  File "//anaconda/envs/py34/lib/python3.4/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "//anaconda/envs/py34/lib/python3.4/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "//anaconda/envs/py34/lib/python3.4/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "//anaconda/envs/py34/lib/python3.4/site-packages/setuptools-3.6-py3.4.egg/setuptools/command/test.py", line 146, in run
  File "//anaconda/envs/py34/lib/python3.4/site-packages/setuptools-3.6-py3.4.egg/setuptools/command/test.py", line 127, in with_project_on_sys_path
  File "//anaconda/envs/py34/lib/python3.4/site-packages/setuptools-3.6-py3.4.egg/setuptools/command/test.py", line 167, in run_tests
  File "//anaconda/envs/py34/lib/python3.4/unittest/main.py", line 92, in __init__
    self.parseArgs(argv)
  File "//anaconda/envs/py34/lib/python3.4/unittest/main.py", line 139, in parseArgs
    self.createTests()
  File "//anaconda/envs/py34/lib/python3.4/unittest/main.py", line 146, in createTests
    self.module)
  File "//anaconda/envs/py34/lib/python3.4/unittest/loader.py", line 146, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "//anaconda/envs/py34/lib/python3.4/unittest/loader.py", line 146, in <listcomp>
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "//anaconda/envs/py34/lib/python3.4/unittest/loader.py", line 105, in loadTestsFromName
    module = __import__('.'.join(parts_copy))
  File "/Users/Peter/GitHub/Comethylation/comethylation/__init__.py", line 4, in <module>
    import funcs
ImportError: No module named 'funcs'
PeteHaitch commented 10 years ago

Ah, it's because the print is a function in Python3; see https://docs.python.org/3.0/whatsnew/3.0.html.

PeteHaitch commented 10 years ago

Running 2to3 over all source code.

PeteHaitch commented 10 years ago

Changing print statements affects Python 2 output. Need to find out way to fix this.

PeteHaitch commented 10 years ago

Simple! Add from __future__ import print_function as the first line of all source files that call print.

PeteHaitch commented 10 years ago

Almost there, the qual is a str in Python 2.7 but a bytes in Python 3 (http://pysam.readthedocs.org/en/latest/api.html). In Python 2.7 using ord() to coerce qual to an integer but this won't work (and isn't necessary) in Python 3. So, need to find a way to make it work in both versions.

PeteHaitch commented 10 years ago

Have implemented a quick fix with bytearray but awaiting a reply from Pysam google group https://groups.google.com/forum/#!topic/pysam-user-group/9I6YMZijCVI

PeteHaitch commented 10 years ago

Travis CI builds working for Python 2.7, 3.2, 3.3 but not 2.6, 3.4 or pypy.

Reasons for failure