From f58c2bfb73a49ef917682108c7fbe507280d8fac Mon Sep 17 00:00:00 2001 From: Tavi Nathanson Date: Mon, 24 Aug 2015 18:49:41 -0400 Subject: [PATCH 01/13] Adding Travis CI to mhctools + fixes --- .travis.yml | 16 ++++++++++++++++ lint.sh | 9 +++++++++ mhctools/epitope_collection.py | 2 +- mhctools/iedb.py | 5 +++++ pylintrc | 4 ++++ requirements.txt | 4 +++- test/test_known_epitopes.py | 5 +++-- 7 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 .travis.yml create mode 100755 lint.sh create mode 100644 pylintrc diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b30bd4a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,16 @@ +sudo: false # Use container-based infrastructure +language: python +python: +- "2.7" +- "3.4" +install: +- pip install -r requirements.txt +- python install . +script: nosetests test && ./lint.sh +deploy: + provider: pypi + user: hammerlab + password: # See http://docs.travis-ci.com/user/encryption-keys/ + secure: gJSWl4PLXKtVc2ERwbzfd4qKk9Yy4T8dpfR7Q89VLVXTd7Tv1SsEknShJZUFaCPN85aYFcAWsoOI6vSlBSdXeTONU/pmPgcWOLfiErsgCqUs6qq7edOhrtOS307SREX4oF6AF2iyJduWAF4NPq+9IoJUROIiB4u5qeUtWfVu2Eo= + on: + tags: true \ No newline at end of file diff --git a/lint.sh b/lint.sh new file mode 100755 index 0000000..acb172f --- /dev/null +++ b/lint.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -o errexit + +find . -name '*.py' \ + | xargs pylint \ + --errors-only \ + --disable=print-statement + +echo 'Passes pylint check' diff --git a/mhctools/epitope_collection.py b/mhctools/epitope_collection.py index 2126a67..2a5597b 100644 --- a/mhctools/epitope_collection.py +++ b/mhctools/epitope_collection.py @@ -58,7 +58,7 @@ def strong_binders_by_rank(self, max_rank=2.0): def groupby(self, key_fn): groups = defaultdict(list) - for binding_prediction in self.binding_predictions: + for binding_prediction in self.elements: key = key_fn(binding_prediction) groups[key].append(binding_prediction) # want to create an EpitopeCollection for each group diff --git a/mhctools/iedb.py b/mhctools/iedb.py index 8425f99..5f13b30 100644 --- a/mhctools/iedb.py +++ b/mhctools/iedb.py @@ -75,6 +75,11 @@ def _parse_iedb_response(response): if len(response) == 0: raise ValueError("Empty response from IEDB!") df = pd.read_csv(io.BytesIO(response), delim_whitespace=True, header=0) + + # pylint doesn't realize that df is a DataFrame, so tell is + assert type(df) == pd.DataFrame + df = pd.DataFrame(df) + if len(df) == 0: raise ValueError( "No binding predictions in response from IEDB: %s" % (response,)) diff --git a/pylintrc b/pylintrc new file mode 100644 index 0000000..fae5c22 --- /dev/null +++ b/pylintrc @@ -0,0 +1,4 @@ +[TYPECHECK] +# Without ignoring this, we get errors like: +# E:249,20: Module 'numpy' has no 'nan' member (no-member) +ignored-modules = numpy \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index f05a77c..03e4001 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,6 @@ numpy==1.7 pandas==0.13.1 varcode >=0.3.17 -six >= 1.9.0 \ No newline at end of file +six >= 1.9.0 +pylint >= 1.4.4 +nose >= 1.3.6 diff --git a/test/test_known_epitopes.py b/test/test_known_epitopes.py index fd87063..b9eaa40 100644 --- a/test/test_known_epitopes.py +++ b/test/test_known_epitopes.py @@ -18,6 +18,7 @@ import mhctools mhc_classes = [ + mhctools.NetMHCcons, mhctools.NetMHCpan, mhctools.NetMHCcons, mhctools.NetMHC, @@ -43,5 +44,5 @@ def test_HIV_epitope(): for mhc_class in mhc_classes: mhc_model = mhc_class("HLA-A*02:01", epitope_lengths=9) epitope = mhc_model.predict("SLYNTVATL")[0] - assert epitope.value < 500, \ - "Expected %s to have IC50 < 500nM" % (epitope,) + assert epitope.percentile_rank < 1.0, \ + "Expected %s to have percentile rank <= 1.0" % epitope From f1eabbf4639238214adc7630e1695360fc1fa582 Mon Sep 17 00:00:00 2001 From: Tavi Nathanson Date: Mon, 24 Aug 2015 14:16:49 -0400 Subject: [PATCH 02/13] Apt-get scipy --- .travis.yml | 7 +++++++ README.md | 2 ++ 2 files changed, 9 insertions(+) diff --git a/.travis.yml b/.travis.yml index b30bd4a..0150bcf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,13 @@ language: python python: - "2.7" - "3.4" +addons: + apt: + packages: + - python-scipy + - python3-scipy +virtualenv: # Needed in conjunction with apt-get'ing scipy + system_site_packages: true install: - pip install -r requirements.txt - python install . diff --git a/README.md b/README.md index d3a0868..398efdd 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://travis-ci.org/hammerlab/mhctools.svg?branch=master)](https://travis-ci.org/hammerlab/mhctools) + # mhctools Python interface to running command-line and web-based MHC binding predictors. From 978a185cd5a1f6c7fb2cda1c7478d50101ef254f Mon Sep 17 00:00:00 2001 From: Tavi Nathanson Date: Mon, 24 Aug 2015 15:29:08 -0400 Subject: [PATCH 03/13] Try using anaconda --- .travis.yml | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0150bcf..b015e2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,19 @@ sudo: false # Use container-based infrastructure language: python python: -- "2.7" -- "3.4" -addons: - apt: - packages: - - python-scipy - - python3-scipy -virtualenv: # Needed in conjunction with apt-get'ing scipy - system_site_packages: true + - "2.7" + - "3.4" +# Setup anaconda; see https://gist.github.com/dan-blanchard/7045057 +before_install: + - wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh + - chmod +x miniconda.sh + - ./miniconda.sh -b + - export PATH=/home/travis/miniconda/bin:$PATH + - conda update --yes conda install: -- pip install -r requirements.txt -- python install . + - conda install --yes python=$TRAVIS_PYTHON_VERSION numpy scipy nose pandas + - pip install -r requirements.txt + - python install . script: nosetests test && ./lint.sh deploy: provider: pypi From af7212e7b817791fcbc5759d061e61e41658a75a Mon Sep 17 00:00:00 2001 From: Tavi Nathanson Date: Mon, 24 Aug 2015 15:43:19 -0400 Subject: [PATCH 04/13] Fix pip installation and pandas for Travis --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b015e2b..520e693 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,9 +11,9 @@ before_install: - export PATH=/home/travis/miniconda/bin:$PATH - conda update --yes conda install: - - conda install --yes python=$TRAVIS_PYTHON_VERSION numpy scipy nose pandas + - conda install --yes python=$TRAVIS_PYTHON_VERSION numpy scipy nose - pip install -r requirements.txt - - python install . + - pip install . script: nosetests test && ./lint.sh deploy: provider: pypi From 847dc6a66938b8c0dbf4f388df7a0800c3d5d8ac Mon Sep 17 00:00:00 2001 From: Tavi Nathanson Date: Mon, 24 Aug 2015 18:52:16 -0400 Subject: [PATCH 05/13] Don't require specific numpy version --- requirements.txt | 12 ++++++------ setup.py | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/requirements.txt b/requirements.txt index 03e4001..11b763b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -numpy==1.7 -pandas==0.13.1 -varcode >=0.3.17 -six >= 1.9.0 -pylint >= 1.4.4 -nose >= 1.3.6 +numpy>=1.7 +pandas>=0.13.1 +varcode>=0.3.17 +six>=1.9.0 +pylint>=1.4.4 +nose>=1.3.6 diff --git a/setup.py b/setup.py index 29b8111..cb34c65 100644 --- a/setup.py +++ b/setup.py @@ -55,8 +55,8 @@ install_requires=[ 'numpy>=1.7', 'pandas>=0.13.1', - 'varcode >=0.3.17', - 'six >=1.9.0' + 'varcode>=0.3.17', + 'six>=1.9.0' ], long_description=readme, packages=['mhctools'], From f02926e2ff67736fa517d723890856678d500a2c Mon Sep 17 00:00:00 2001 From: Tavi Nathanson Date: Mon, 24 Aug 2015 17:37:20 -0400 Subject: [PATCH 06/13] Add NetMHC installation --- .travis.yml | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 520e693..bb93839 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,15 +3,28 @@ language: python python: - "2.7" - "3.4" -# Setup anaconda; see https://gist.github.com/dan-blanchard/7045057 +addons: + apt: + packages: + tcsh +env: + global: + # MHC_BUNDLE_PASS + - secure: "TIminZrp9m1kMXhemqz8Zx4BjojIoEYZJnNrDrL6T/pKMpP5FQ6sprj8meGfNse4ApRIPmp5lhqxbPOe7Cg7ooetIcORekjRueHwRkYXqgMbgffgZYuEJTAGLKFsBDEXFD1kWT7igmvXFsP1T0bb1TxRPK93Q5G+e1dEAm6Iqwo=" +# Setup anaconda for easily running scipy on Travis; see https://gist.github.com/dan-blanchard/7045057 before_install: - wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh - chmod +x miniconda.sh - ./miniconda.sh -b - export PATH=/home/travis/miniconda/bin:$PATH - conda update --yes conda + - git clone https://mhcbundle:$MHC_BUNDLE_PASS@github.com/hammerlab/netmhc-bundle.git + - export NETMHC_BUNDLE_HOME=$PWD/netmhc-bundle + - mkdir tmp + - export NETMHC_BUNDLE_TMPDIR=$PWD/tmp + - export PATH=$PATH:$NETMHC_BUNDLE_HOME/bin install: - - conda install --yes python=$TRAVIS_PYTHON_VERSION numpy scipy nose + - conda install --yes python=$TRAVIS_PYTHON_VERSION numpy scipy nose pandas - pip install -r requirements.txt - pip install . script: nosetests test && ./lint.sh @@ -19,6 +32,6 @@ deploy: provider: pypi user: hammerlab password: # See http://docs.travis-ci.com/user/encryption-keys/ - secure: gJSWl4PLXKtVc2ERwbzfd4qKk9Yy4T8dpfR7Q89VLVXTd7Tv1SsEknShJZUFaCPN85aYFcAWsoOI6vSlBSdXeTONU/pmPgcWOLfiErsgCqUs6qq7edOhrtOS307SREX4oF6AF2iyJduWAF4NPq+9IoJUROIiB4u5qeUtWfVu2Eo= + secure: "gJSWl4PLXKtVc2ERwbzfd4qKk9Yy4T8dpfR7Q89VLVXTd7Tv1SsEknShJZUFaCPN85aYFcAWsoOI6vSlBSdXeTONU/pmPgcWOLfiErsgCqUs6qq7edOhrtOS307SREX4oF6AF2iyJduWAF4NPq+9IoJUROIiB4u5qeUtWfVu2Eo=" on: tags: true \ No newline at end of file From 9eca2f313891580c99479ac6aee0178404aaec1d Mon Sep 17 00:00:00 2001 From: Tavi Nathanson Date: Mon, 24 Aug 2015 18:44:57 -0400 Subject: [PATCH 07/13] Fix lint.sh --- lint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lint.sh b/lint.sh index acb172f..af1b2e3 100755 --- a/lint.sh +++ b/lint.sh @@ -1,7 +1,7 @@ #!/bin/bash set -o errexit -find . -name '*.py' \ +find mhctools test -name '*.py' \ | xargs pylint \ --errors-only \ --disable=print-statement From f507b21fc412391bea8abe2b5fa6eaac5a0975af Mon Sep 17 00:00:00 2001 From: Tavi Nathanson Date: Mon, 24 Aug 2015 19:00:25 -0400 Subject: [PATCH 08/13] Add a comment about tcsh --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index bb93839..f887329 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ python: addons: apt: packages: + # Needed for NetMHC tcsh env: global: From 2f5553c50a7597f55a50b5c07fbe0510e7bb6484 Mon Sep 17 00:00:00 2001 From: Tavi Nathanson Date: Mon, 24 Aug 2015 19:11:33 -0400 Subject: [PATCH 09/13] Fix a percentile_rank unit test --- test/test_known_epitopes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_known_epitopes.py b/test/test_known_epitopes.py index b9eaa40..0ee6d38 100644 --- a/test/test_known_epitopes.py +++ b/test/test_known_epitopes.py @@ -44,5 +44,5 @@ def test_HIV_epitope(): for mhc_class in mhc_classes: mhc_model = mhc_class("HLA-A*02:01", epitope_lengths=9) epitope = mhc_model.predict("SLYNTVATL")[0] - assert epitope.percentile_rank < 1.0, \ - "Expected %s to have percentile rank <= 1.0" % epitope + assert epitope.percentile_rank <= 4.0, \ + "Expected %s to have percentile rank <= 3.0" % str(epitope) From 95778a9d823f25d02c841667061388b9263534b0 Mon Sep 17 00:00:00 2001 From: Tavi Nathanson Date: Mon, 24 Aug 2015 19:16:20 -0400 Subject: [PATCH 10/13] Bump version and only PyPi on master tags --- .travis.yml | 3 ++- setup.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f887329..c408b96 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,4 +35,5 @@ deploy: password: # See http://docs.travis-ci.com/user/encryption-keys/ secure: "gJSWl4PLXKtVc2ERwbzfd4qKk9Yy4T8dpfR7Q89VLVXTd7Tv1SsEknShJZUFaCPN85aYFcAWsoOI6vSlBSdXeTONU/pmPgcWOLfiErsgCqUs6qq7edOhrtOS307SREX4oF6AF2iyJduWAF4NPq+9IoJUROIiB4u5qeUtWfVu2Eo=" on: - tags: true \ No newline at end of file + tags: true + branch: master \ No newline at end of file diff --git a/setup.py b/setup.py index cb34c65..f88fb10 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,7 @@ if __name__ == '__main__': setup( name='mhctools', - version="0.1.3", + version="0.1.4", description="Python interface to running command-line and web-based MHC binding predictors", author="Alex Rubinsteyn", author_email="alex {dot} rubinsteyn {at} mssm {dot} edu", From 59510b7ade6a8aa1984d3abf0be8c20fdea18429 Mon Sep 17 00:00:00 2001 From: Tavi Nathanson Date: Mon, 24 Aug 2015 19:21:29 -0400 Subject: [PATCH 11/13] Add a return to _determine_valid_alleles --- mhctools/base_commandline_predictor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mhctools/base_commandline_predictor.py b/mhctools/base_commandline_predictor.py index 68e868c..8334cc4 100644 --- a/mhctools/base_commandline_predictor.py +++ b/mhctools/base_commandline_predictor.py @@ -86,6 +86,7 @@ def _determine_valid_alleles(command, supported_allele_flag): logging.info("Skipping allele %s: %s" % ( line, error)) continue + return valid_alleles except: logging.warning( "Failed to run %s %s", From ffda6e38e02daef9f531de27d7d2763768ec567c Mon Sep 17 00:00:00 2001 From: Tavi Nathanson Date: Mon, 24 Aug 2015 19:34:09 -0400 Subject: [PATCH 12/13] Fix a pylint unicode complaint --- mhctools/common.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mhctools/common.py b/mhctools/common.py index 6c7e5d5..fac3730 100644 --- a/mhctools/common.py +++ b/mhctools/common.py @@ -16,6 +16,7 @@ # Python3 doesn't have a unicode classes try: + # pylint: disable=undefined-variable string_classes = (unicode, str) except NameError: string_classes = (str,) From b8790687db1676347e1d5de51c2011f6ac00023b Mon Sep 17 00:00:00 2001 From: Tavi Nathanson Date: Tue, 25 Aug 2015 11:48:28 -0400 Subject: [PATCH 13/13] Fix merge error in a test --- test/test_known_epitopes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_known_epitopes.py b/test/test_known_epitopes.py index 0ee6d38..640092f 100644 --- a/test/test_known_epitopes.py +++ b/test/test_known_epitopes.py @@ -44,5 +44,5 @@ def test_HIV_epitope(): for mhc_class in mhc_classes: mhc_model = mhc_class("HLA-A*02:01", epitope_lengths=9) epitope = mhc_model.predict("SLYNTVATL")[0] - assert epitope.percentile_rank <= 4.0, \ - "Expected %s to have percentile rank <= 3.0" % str(epitope) + assert epitope.value < 500, \ + "Expected %s to have IC50 < 500nM" % (epitope,)