Skip to content

Commit

Permalink
fix to snpeff availabl_databases() for conda-based installs
Browse files Browse the repository at this point in the history
the version of snpeff installed by conda relies on a shell script
wrapper, and must be called differently than a standard jar file. this
difference in invocation was present in snpeff.execute() but not
snpeff.available_databases(). The latter now relies on
snpeff.execute(). The execute() function itself has been changed to use
util.misc.run() rather than subprocess.check_call() so we can capture
the output (it is read to get the list of available databases)
  • Loading branch information
tomkinsc committed Feb 16, 2016
1 parent 5920893 commit 2d784c6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tools/snpeff.py
Expand Up @@ -16,6 +16,7 @@
# module-specific
import tools
import util.file
import util.misc
import util.genbank

_log = logging.getLogger(__name__)
Expand All @@ -27,9 +28,9 @@


class SnpEff(tools.Tool):
jvmMemDefault = '4g'

def __init__(self, install_methods=None, extra_genomes=None):
self.jvmMemDefault = '4g'
extra_genomes = extra_genomes or ['KJ660346.2']
if not install_methods:
install_methods = []
Expand All @@ -43,22 +44,22 @@ def version(self):
return "4.1"

def execute(self, command, args, JVMmemory=None, stdin=None, stdout=None): # pylint: disable=W0221
if JVMmemory is None:
if not JVMmemory:
JVMmemory = self.jvmMemDefault

# the conda version wraps the jar file with a shell script
if self.install_and_get_path().endswith(".jar"):
tool_cmd = [
'java', '-Xmx' + JVMmemory, '-Djava.io.tmpdir=' + tempfile.tempdir, '-jar', self.install_and_get_path(),
'java', '-Xmx' + JVMmemory, '-Djava.io.tmpdir=' + tempfile.gettempdir(), '-jar', self.install_and_get_path(),
command
] + args
else:
tool_cmd = [
self.install_and_get_path(), '-Xmx' + JVMmemory, '-Djava.io.tmpdir=' + tempfile.tempdir, command
self.install_and_get_path(), '-Xmx' + JVMmemory, '-Djava.io.tmpdir=' + tempfile.gettempdir(), command
] + args

_log.debug(' '.join(tool_cmd))
subprocess.check_call(tool_cmd, stdin=stdin, stdout=stdout)
return util.misc.run(tool_cmd)

def has_genome(self, genome):
if not self.known_dbs:
Expand Down Expand Up @@ -108,12 +109,13 @@ def create_db(self, accessions, emailAddress, JVMmemory):
self.execute('build', args, JVMmemory=JVMmemory)

def available_databases(self):
tool_cmd = ['java', '-jar', self.install_and_get_path(), 'databases']
command_ps = self.execute("databases", args=[])

split_points = []
keys = ['Genome', 'Organism', 'Status', 'Bundle', 'Database']
self.installed_dbs = set()
self.known_dbs = set()
for line in subprocess.check_output(tool_cmd, universal_newlines=True).split('\n'):
for line in command_ps.stdout.splitlines():
line = line.strip()
if not split_points:
if not line.startswith('Genome'):
Expand Down

0 comments on commit 2d784c6

Please sign in to comment.