Skip to content

Commit

Permalink
paths in hatchet.ini specify folder names, not full path to exes. Bum…
Browse files Browse the repository at this point in the history
…ped version (#124)
  • Loading branch information
vineetbansal authored Apr 29, 2022
1 parent b58b2bb commit 2c6b31f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def build_extension(self, ext):

setup(
name='hatchet',
version='0.4.13',
version='0.4.14',
packages=['hatchet', 'hatchet.utils', 'hatchet.utils.solve', 'hatchet.bin', 'hatchet.data'],
package_dir={'': 'src'},
package_data={'hatchet': ['hatchet.ini'], 'hatchet.data': ['*']},
Expand Down
2 changes: 1 addition & 1 deletion src/hatchet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.4.13'
__version__ = '0.4.14'

import os.path
from importlib.resources import path
Expand Down
14 changes: 13 additions & 1 deletion src/hatchet/hatchet.ini
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ ymin =
clonepalette = Set1
linkage = single

[phase_snps]
# The phase-snps step uses the Picard tool to perform liftover, if needed.
# Picard is a java tool and lets the JVM decide on the amount of memory to allocate.
# We specify a good estimate here, but this may need to be tweaked for certain situations.
# These flags are passed to picard invocation as either:
# java -jar picard.jar <picard_java_flags> LiftoverVcf ..
# or
# picard <picard_java_flags> LiftoverVcf .. (if picard is installed from bioconda and is available as a script)
picard_java_flags = "-Xmx8g"

[preprocess]
samplenames =
size = 250kb
Expand All @@ -149,7 +159,9 @@ samtools = ""
bcftools = ""
reference = ""
tabix = ""
# Path to picard .jar file, or a wrapper script that directly invokes picard
# Path to where 'picard.jar' or a 'picard' wrapper script can be found
# (available when picard is installed from bioconda)
# Leave blank if 'picard' is already on your PATH.
picard = ""
mosdepth = ""
shapeit = ""
Expand Down
28 changes: 17 additions & 11 deletions src/hatchet/utils/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ def suppress_stdout():
sys.stderr = old_stderr


def _check_cmd(exe, *args):
def _check_cmd(exe_path, exe_name, *args):
# This function should never raise Exceptions unless it's a genuine implementation bug
# Only use exe and args that return a return code of 0
cmd = [exe, *args]
# Use exe_path as '' if you expect <exe_name> to be on PATH
cmd = [os.path.join(exe_path, exe_name), *args]
try:
p = subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, universal_newlines=True)
p.communicate()
Expand All @@ -42,27 +43,32 @@ def _check_cmd(exe, *args):
return True


# Most command-line commands can be checked using _check_cmd(<command>, '--version')
# Most command-line commands can be checked using _check_cmd(<folder_with_command>, <command>, '--version')
# Others, like below, need special handling because they have no simple invocations that return 0
def _check_tabix():
with tempfile.TemporaryDirectory() as tempdirname:
with importlib.resources.path(hatchet.data, 'sample.sorted.gff.gz') as gz_path:
_temp_gz_path = os.path.join(tempdirname, 'sample.sorted.gff.gz')
shutil.copy(gz_path, _temp_gz_path)
return _check_cmd(config.paths.tabix, '-p', 'gff', _temp_gz_path, '-f')
return _check_cmd(config.paths.tabix, 'tabix', '-p', 'gff', _temp_gz_path, '-f')


def _check_picard():
if config.paths.picard.endswith('.jar'):
cmd = 'java'
args_pre = ('-jar', config.paths.picard)
picard_dir = config.paths.picard
picard_java_flags = config.phase_snps.picard_java_flags
picard_bin_path = os.path.join(picard_dir, 'picard')
if os.path.exists(picard_bin_path):
exe_path = f'{picard_dir}'
exe_name = 'picard'
args_pre = (picard_java_flags, )
else:
cmd = config.paths.picard
args_pre = ()
exe_path = '' # Assume java is on PATH
exe_name = 'java'
args_pre = (picard_java_flags, '-jar', os.path.join(picard_dir, 'picard.jar'))

with tempfile.TemporaryDirectory() as tempdirname:
with importlib.resources.path(hatchet.data, 'sample.sorted.bam') as bam_path:
return _check_cmd(cmd, *args_pre, 'BuildBamIndex', '--INPUT', bam_path, '--OUTPUT', f'{tempdirname}/sample.sorted.bam.bai')
return _check_cmd(exe_path, exe_name, *args_pre, 'BuildBamIndex', '--INPUT', bam_path, '--OUTPUT', f'{tempdirname}/sample.sorted.bam.bai')


def _check_python_import(which):
Expand All @@ -80,7 +86,7 @@ def _check_python_import(which):
'compute-cn': [
(
'solver',
f'Your selected solver "{config.compute_cn.solver}" seems to be working correctly.',
f'Your selected solver "{config.compute_cn.solver}" seems to be working correctly',
'See http://compbio.cs.brown.edu/hatchet/README.html#using-a-solver',
check_solver
)
Expand Down

0 comments on commit 2c6b31f

Please sign in to comment.