Skip to content

Commit

Permalink
fix for netmhcpan to work in snap
Browse files Browse the repository at this point in the history
  • Loading branch information
dmnfarrell committed Feb 11, 2019
1 parent e5a61b3 commit b833058
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 40 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

[![PyPI version shields.io](https://img.shields.io/pypi/v/epitopepredict.svg)](https://pypi.python.org/pypi/epitopepredict/)
[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![Build: status](https://img.shields.io/travis/dmnfarrell/epitopepredict.svg)](https://travis-ci.org/dmnfarrell/epitopepredict)
[![Documentation Status](https://readthedocs.org/projects/epitopepredict/badge/?version=latest)](https://epitopepredict.readthedocs.io/en/latest/?badge=latest)

### Background

**epitopepredict** provides a standardized programmatic interface and command line tool for executing multiple epitope prediction methods. Currently this largely consists of interfaces to several MHC binding prediction, the results of which can then be processed and visualized in a consistent manner. The Tepitope module implements the TEPITOPEPan method is provided as a 'built in' method. The IEDB tools and netMHCIIpan and mhcflurry are also supported. All of these tools are free for academic use. This software runs on most linux systems. Users are recommended to use the snap package for convenience. This software is under active development particularly with a view to improve the command line and web tools.
**epitopepredict** provides a standardized programmatic interface and command line tool for executing multiple epitope prediction methods. Currently this largely consists of interfaces to several MHC binding prediction, the results of which can then be processed and visualized in a consistent manner. The Tepitope module implements the TEPITOPEPan method is provided as a 'built in' method. The IEDB tools and netMHCIIpan and mhcflurry are also supported. All of these tools are free for academic use. This software runs on most linux systems. Users are recommended to use the snap package for convenience. This software is under active development particularly with a view to improve the command line and web tools.

Documentation is at http://epitopepredict.readthedocs.io

Expand Down
33 changes: 26 additions & 7 deletions epitopepredict/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ def __init__(self, opts={}):
def setup(self):
"""Setup main parameters"""

#if base.check_snap() == True:
#add_path()
if base.check_snap() == True:
print ('running in a snap')
cmd = base.set_netmhcpan_cmd()
print ('netmhcpan cmd set to:', cmd)

pd.set_option('display.width', 120)
#override base.defaults entries if provided in conf
set_defaults(self.__dict__)
Expand Down Expand Up @@ -86,6 +89,9 @@ def run(self):
preds = []
for p in self.predictors:
P = base.get_predictor(p)
if P.check_install() == False:
print ('%s not installed' %P.name)
continue
savepath = os.path.join(self.path, p)
if self.overwrite == True and os.path.exists(savepath):
shutil.rmtree(savepath)
Expand Down Expand Up @@ -387,10 +393,10 @@ def check_installed():
return found

def test_run():
"""Test run for a sample file"""
"""Test run for a sample file."""

#installed = ','.join(check_installed())
installed = 'tepitope'
installed = 'tepitope,mhcflurry'
path = os.path.dirname(os.path.abspath(__file__))
options = config.baseoptions
b=options['base']
Expand All @@ -403,13 +409,25 @@ def test_run():
b['verbose'] = True
b['cutoff_method'] = 'score'
b['cutoffs'] = '5,500'
#b['compression'] = 'gzip'
b['overwrite'] = False
b['overwrite'] = True
options = config.check_options(options)
W = WorkFlow(options)
st = W.setup()
W.run()

def test_binary():

cmd = base.set_netmhcpan_cmd()
cmd = cmd + ' -a HLA-A02:01 -l 9 P170919-test.fa'
print (cmd)
import subprocess
tmp = subprocess.check_output(cmd, shell=True, executable='/bin/bash')
import io
tmp = tmp.decode()
for i in tmp.split('\n'):
print (i)
return

def main():
"Run the application"

Expand All @@ -432,7 +450,7 @@ def main():
default=False, help="Neo-epitope pipeline")
parser.add_option("-e", "--ensembl", dest="ensembl", action="store_true",
default=False, help="Get ensembl files for a release")
parser.add_option("-s", "--server", dest="server",
parser.add_option("-s", "--server", dest="server", action="store_true",
default=False, help="Run web app")
parser.add_option("-x", "--port", dest="port", default=8000,
help="Port for web app, default 8000")
Expand Down Expand Up @@ -479,6 +497,7 @@ def main():
import epitopepredict.tornado_serve
epitopepredict.tornado_serve.main(opts.port)
elif opts.test == True:
#test_binary()
test_run()
elif opts.version == True:
from . import __version__
Expand Down
28 changes: 16 additions & 12 deletions epitopepredict/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,20 +406,21 @@ def check_snap():
"""Check if inside a snap"""

if 'SNAP_COMMON' in os.environ:
print ('running in a snap')
return True
return False

def set_netmhcpan_cmd():
"""Setup the netmhcpan command for using inside snap. Avoids using
tcsh script."""
def set_netmhcpan_cmd(path=None):
"""Setup the netmhcpan command to point directly to the binary. This is a
workaround for running inside snaps. Avoids using the tcsh script."""

toolspath = os.path.join('/home', os.environ['USER'], 'tools')
netmhcpath = os.path.join(toolspath, 'netMHCpan-4.0/Linux_x86_64')
if not os.path.exists(netmhcpath):
print ('you need to copy the netmhcpan files to %s' %toolspath)
os.environ['NETMHCpan']=netmhcpath
os.environ['TMPDIR']='/tmp'
os.environ['TMPDIR']= '/tmp'
cmd = os.path.join(netmhcpath, 'bin/netMHCpan')
print ('netmhcpan cmd set to:', cmd)
#print (os.environ)
return cmd

class DataFrameIterator:
Expand Down Expand Up @@ -474,6 +475,9 @@ def __repr__(self):
n = len(self.data.name.unique())
return '%s predictor with results in %s sequences' %(self.name, n)

def check_install(self):
return True

def supported_lengths(self):
"""Return supported peptide lengths"""
return [9,11]
Expand Down Expand Up @@ -1204,7 +1208,7 @@ def __init__(self, data=None, scoring='affinity'):
self.qf = self.get_quantile_data()
self.basecmd = 'netMHCpan'
#base command needs to be to the binary directly if running snap
if check_snap is True:
if check_snap() is True:
self.basecmd = set_netmhcpan_cmd()

def read_result(self, temp):
Expand Down Expand Up @@ -1291,13 +1295,13 @@ def convert_allele_name(self, a):
return a

def check_install(self):
cmd = 'netMHCpan'

cmd = '%s -h' %self.basecmd
try:
temp = subprocess.check_output(cmd, shell=True)
print('netMHCpan appears to be installed')
return 1
except:
print ('netMHCpan not found')
return 0

@classmethod
Expand Down Expand Up @@ -1821,7 +1825,7 @@ def __init__(self, data=None, **kwargs):
self.operator = '<'
self.scorekey = 'score'
self.rankascending = 1
if self.check_install == False:
if self.check_install() == False:
return
self._check_models()
from mhcflurry import Class1AffinityPredictor
Expand Down Expand Up @@ -1870,10 +1874,10 @@ def get_alleles(self):

def check_install(self):
try:
import mhcflurry
from mhcflurry import Class1AffinityPredictor
return True
except:
print ('use pip install mhcflurry to install.')
#print ('use pip install mhcflurry to install.')
return False

def _check_models(self):
Expand Down
29 changes: 16 additions & 13 deletions epitopepredict/description.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
Background
----------

epitopepredict provides a standardized programmatic interface and command line
tool for executing several epitope prediction methods. Currently this largely
consists of interfaces to several MHC binding prediction, the results of which
can then be processed and visualized in a consistent manner. Many MHC binding
predictors have been developed but usually not in an open source manner. The
Tepitope module implements the TEPITOPEPan method is provided as a 'built in'
method. netMHCIIpan must be downloaded separately from the website and
installed on your system. The process is quite simple. The same applies for
the IEDB tools. Both of these tools are free for academic use. It is hoped
that other epitope predictors will be integrated.
epitopepredict provides a standardized programmatic interface and command line tool for
executing multiple epitope prediction methods. Currently this largely consists of interfaces
to several MHC binding prediction, the results of which can then be processed and visualized
in a consistent manner. The Tepitope module implements the TEPITOPEPan method is provided as
a 'built in' method. The IEDB tools and netMHCIIpan and mhcflurry are also supported.
All of these tools are free for academic use. This software runs on most linux systems.
Users are recommended to use the snap package for convenience. This software is under
active development particularly with a view to improve the command line and web tools.

Documentation is at http://epitopepredict.readthedocs.io

Supported methods
-----------------

TEPITOPEPan
NetMHCIIpan
NetMHCpan
IEDB MHC tools
IEDB BCell tools
MHCFlurry
MHCflurry

Dependencies
------------

pandas
biopython
tornado
bokeh
mhcflurry (optional)

Installation
------------

pip install epitopepredict

Links
Expand Down
7 changes: 3 additions & 4 deletions epitopepredict/neo.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def run(self):
else:
alleles = self.mhc2_alleles
length = self.mhc2_length
seqs = get_mutant_sequences(effects=effects, length=length, verbose=self.verbose)

seqs = get_mutant_sequences(effects=effects, length=length, verbose=self.verbose)
res = predict_variants(seqs, alleles=alleles, predictor=predictor,
verbose=self.verbose, cpus=self.cpus)
res['label'] = f
Expand Down Expand Up @@ -470,9 +470,8 @@ def predict_variants(df, predictor='netmhcpan', alleles=[],
df['length'] = df.peptide.str.len()

P = base.get_predictor(predictor, scoring='ligand')
if verbose == True:
print (P)
print ('predicting mhc binding for %s peptides with %s' %(len(df), P.name))
print (P)
print ('predicting mhc binding for %s peptides with %s' %(len(df), P.name))

peps = list(df.peptide)
res = P.predict_peptides(peps, alleles=alleles, cpus=cpus,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
'description.txt']
},
install_requires=['numpy>=1.10',
'pandas>=0.20',
'pandas>=0.22',
'biopython>=1.5',
'bokeh==0.12.14',
'wtforms>=2.1',
Expand Down
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ parts:
python-packages:
[mhcflurry,gtfparse==1.2,pyensembl==1.7.3,varcode==0.8.0]
stage-packages:
[tcsh,gawk,ncbi-blast+]
[gawk,ncbi-blast+]

0 comments on commit b833058

Please sign in to comment.