Skip to content

Commit b833058

Browse files
committed
fix for netmhcpan to work in snap
1 parent e5a61b3 commit b833058

File tree

7 files changed

+65
-40
lines changed

7 files changed

+65
-40
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

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

77
### Background
88

9-
**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.
9+
**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.
1010

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

epitopepredict/app.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ def __init__(self, opts={}):
2626
def setup(self):
2727
"""Setup main parameters"""
2828

29-
#if base.check_snap() == True:
30-
#add_path()
29+
if base.check_snap() == True:
30+
print ('running in a snap')
31+
cmd = base.set_netmhcpan_cmd()
32+
print ('netmhcpan cmd set to:', cmd)
33+
3134
pd.set_option('display.width', 120)
3235
#override base.defaults entries if provided in conf
3336
set_defaults(self.__dict__)
@@ -86,6 +89,9 @@ def run(self):
8689
preds = []
8790
for p in self.predictors:
8891
P = base.get_predictor(p)
92+
if P.check_install() == False:
93+
print ('%s not installed' %P.name)
94+
continue
8995
savepath = os.path.join(self.path, p)
9096
if self.overwrite == True and os.path.exists(savepath):
9197
shutil.rmtree(savepath)
@@ -387,10 +393,10 @@ def check_installed():
387393
return found
388394

389395
def test_run():
390-
"""Test run for a sample file"""
396+
"""Test run for a sample file."""
391397

392398
#installed = ','.join(check_installed())
393-
installed = 'tepitope'
399+
installed = 'tepitope,mhcflurry'
394400
path = os.path.dirname(os.path.abspath(__file__))
395401
options = config.baseoptions
396402
b=options['base']
@@ -403,13 +409,25 @@ def test_run():
403409
b['verbose'] = True
404410
b['cutoff_method'] = 'score'
405411
b['cutoffs'] = '5,500'
406-
#b['compression'] = 'gzip'
407-
b['overwrite'] = False
412+
b['overwrite'] = True
408413
options = config.check_options(options)
409414
W = WorkFlow(options)
410415
st = W.setup()
411416
W.run()
412417

418+
def test_binary():
419+
420+
cmd = base.set_netmhcpan_cmd()
421+
cmd = cmd + ' -a HLA-A02:01 -l 9 P170919-test.fa'
422+
print (cmd)
423+
import subprocess
424+
tmp = subprocess.check_output(cmd, shell=True, executable='/bin/bash')
425+
import io
426+
tmp = tmp.decode()
427+
for i in tmp.split('\n'):
428+
print (i)
429+
return
430+
413431
def main():
414432
"Run the application"
415433

@@ -432,7 +450,7 @@ def main():
432450
default=False, help="Neo-epitope pipeline")
433451
parser.add_option("-e", "--ensembl", dest="ensembl", action="store_true",
434452
default=False, help="Get ensembl files for a release")
435-
parser.add_option("-s", "--server", dest="server",
453+
parser.add_option("-s", "--server", dest="server", action="store_true",
436454
default=False, help="Run web app")
437455
parser.add_option("-x", "--port", dest="port", default=8000,
438456
help="Port for web app, default 8000")
@@ -479,6 +497,7 @@ def main():
479497
import epitopepredict.tornado_serve
480498
epitopepredict.tornado_serve.main(opts.port)
481499
elif opts.test == True:
500+
#test_binary()
482501
test_run()
483502
elif opts.version == True:
484503
from . import __version__

epitopepredict/base.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -406,20 +406,21 @@ def check_snap():
406406
"""Check if inside a snap"""
407407

408408
if 'SNAP_COMMON' in os.environ:
409-
print ('running in a snap')
410409
return True
411410
return False
412411

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

417416
toolspath = os.path.join('/home', os.environ['USER'], 'tools')
418417
netmhcpath = os.path.join(toolspath, 'netMHCpan-4.0/Linux_x86_64')
418+
if not os.path.exists(netmhcpath):
419+
print ('you need to copy the netmhcpan files to %s' %toolspath)
419420
os.environ['NETMHCpan']=netmhcpath
420-
os.environ['TMPDIR']='/tmp'
421+
os.environ['TMPDIR']= '/tmp'
421422
cmd = os.path.join(netmhcpath, 'bin/netMHCpan')
422-
print ('netmhcpan cmd set to:', cmd)
423+
#print (os.environ)
423424
return cmd
424425

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

478+
def check_install(self):
479+
return True
480+
477481
def supported_lengths(self):
478482
"""Return supported peptide lengths"""
479483
return [9,11]
@@ -1204,7 +1208,7 @@ def __init__(self, data=None, scoring='affinity'):
12041208
self.qf = self.get_quantile_data()
12051209
self.basecmd = 'netMHCpan'
12061210
#base command needs to be to the binary directly if running snap
1207-
if check_snap is True:
1211+
if check_snap() is True:
12081212
self.basecmd = set_netmhcpan_cmd()
12091213

12101214
def read_result(self, temp):
@@ -1291,13 +1295,13 @@ def convert_allele_name(self, a):
12911295
return a
12921296

12931297
def check_install(self):
1294-
cmd = 'netMHCpan'
1298+
1299+
cmd = '%s -h' %self.basecmd
12951300
try:
12961301
temp = subprocess.check_output(cmd, shell=True)
12971302
print('netMHCpan appears to be installed')
12981303
return 1
12991304
except:
1300-
print ('netMHCpan not found')
13011305
return 0
13021306

13031307
@classmethod
@@ -1821,7 +1825,7 @@ def __init__(self, data=None, **kwargs):
18211825
self.operator = '<'
18221826
self.scorekey = 'score'
18231827
self.rankascending = 1
1824-
if self.check_install == False:
1828+
if self.check_install() == False:
18251829
return
18261830
self._check_models()
18271831
from mhcflurry import Class1AffinityPredictor
@@ -1870,10 +1874,10 @@ def get_alleles(self):
18701874

18711875
def check_install(self):
18721876
try:
1873-
import mhcflurry
1877+
from mhcflurry import Class1AffinityPredictor
18741878
return True
18751879
except:
1876-
print ('use pip install mhcflurry to install.')
1880+
#print ('use pip install mhcflurry to install.')
18771881
return False
18781882

18791883
def _check_models(self):

epitopepredict/description.txt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
11
Background
22
----------
33

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

1515
Supported methods
1616
-----------------
1717

1818
TEPITOPEPan
19-
NetMHCIIpan
19+
NetMHCpan
2020
IEDB MHC tools
21-
IEDB BCell tools
22-
MHCFlurry
21+
MHCflurry
2322

2423
Dependencies
2524
------------
2625

2726
pandas
2827
biopython
28+
tornado
29+
bokeh
30+
mhcflurry (optional)
2931

3032
Installation
3133
------------
34+
3235
pip install epitopepredict
3336

3437
Links

epitopepredict/neo.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ def run(self):
130130
else:
131131
alleles = self.mhc2_alleles
132132
length = self.mhc2_length
133-
seqs = get_mutant_sequences(effects=effects, length=length, verbose=self.verbose)
134133

134+
seqs = get_mutant_sequences(effects=effects, length=length, verbose=self.verbose)
135135
res = predict_variants(seqs, alleles=alleles, predictor=predictor,
136136
verbose=self.verbose, cpus=self.cpus)
137137
res['label'] = f
@@ -470,9 +470,8 @@ def predict_variants(df, predictor='netmhcpan', alleles=[],
470470
df['length'] = df.peptide.str.len()
471471

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

477476
peps = list(df.peptide)
478477
res = P.predict_peptides(peps, alleles=alleles, cpus=cpus,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
'description.txt']
2121
},
2222
install_requires=['numpy>=1.10',
23-
'pandas>=0.20',
23+
'pandas>=0.22',
2424
'biopython>=1.5',
2525
'bokeh==0.12.14',
2626
'wtforms>=2.1',

snap/snapcraft.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ parts:
2525
python-packages:
2626
[mhcflurry,gtfparse==1.2,pyensembl==1.7.3,varcode==0.8.0]
2727
stage-packages:
28-
[tcsh,gawk,ncbi-blast+]
28+
[gawk,ncbi-blast+]

0 commit comments

Comments
 (0)