Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
uses: actions/cache@v2
with:
path: testdata
key: hatchetcache04
key: hatchetcache05

- name: Download Testing Data
if: steps.cache-test-data.outputs.cache-hit != 'true'
Expand All @@ -75,17 +75,17 @@ jobs:

- name: Install SAMtools
run: |
wget https://sourceforge.net/projects/samtools/files/samtools/1.7/samtools-1.7.tar.bz2/download -O samtools-1.7.tar.bz2
tar xvjf samtools-1.7.tar.bz2
(cd samtools-1.7 && ./configure && make)
echo "HATCHET_PATHS_SAMTOOLS=$(realpath samtools-1.7)" >> $GITHUB_ENV
wget https://sourceforge.net/projects/samtools/files/samtools/1.11/samtools-1.11.tar.bz2/download -O samtools-1.11.tar.bz2
tar xvjf samtools-1.11.tar.bz2
(cd samtools-1.11 && ./configure && make)
echo "HATCHET_PATHS_SAMTOOLS=$(realpath samtools-1.11)" >> $GITHUB_ENV

- name: Install BCFTools
run: |
wget https://sourceforge.net/projects/samtools/files/samtools/1.7/bcftools-1.7.tar.bz2/download -O bcftools-1.7.tar.bz2
tar xvjf bcftools-1.7.tar.bz2
(cd bcftools-1.7 && ./configure && make)
echo "HATCHET_PATHS_BCFTOOLS=$(realpath bcftools-1.7)" >> $GITHUB_ENV
wget https://sourceforge.net/projects/samtools/files/samtools/1.11/bcftools-1.11.tar.bz2/download -O bcftools-1.11.tar.bz2
tar xvjf bcftools-1.11.tar.bz2
(cd bcftools-1.11 && ./configure && make)
echo "HATCHET_PATHS_BCFTOOLS=$(realpath bcftools-1.11)" >> $GITHUB_ENV

- name: Install tabix
run: |
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "hatchet"
version = "1.0.3"
version = "1.0.4"
authors = [
{ name="Simone Zaccaria", email="[email protected]" },
{ name="Ben Raphael", email="[email protected]" },
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__ = '1.0.3'
__version__ = '1.0.4'

import os.path
from importlib.resources import path
Expand Down
44 changes: 27 additions & 17 deletions src/hatchet/utils/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from contextlib import contextmanager
import tempfile
import shutil
from packaging import version

from hatchet import config
import hatchet.data
Expand All @@ -29,7 +30,7 @@ def suppress_stdout():
sys.stderr = old_stderr


def _check_cmd(exe_path, exe_name, *args):
def _check_cmd(exe_path, exe_name, cwd=None, *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
# Use exe_path as '' if you expect <exe_name> to be on PATH
Expand All @@ -39,6 +40,7 @@ def _check_cmd(exe_path, exe_name, *args):
cmd,
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE,
cwd=cwd,
universal_newlines=True,
)
p.communicate()
Expand All @@ -49,22 +51,22 @@ def _check_cmd(exe_path, exe_name, *args):
return True


# Most command-line commands can be checked using _check_cmd(<folder_with_command>, <command>, '--version')
# Most command-line commands can be checked using _check_cmd(<folder_with_command>, <command>, <cwd>, '--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, 'tabix', '-p', 'gff', _temp_gz_path, '-f')
return _check_cmd(config.paths.tabix, 'tabix', None, '-p', 'gff', _temp_gz_path, '-f')


def _check_bgzip():
with tempfile.TemporaryDirectory() as tempdirname:
with importlib.resources.path(hatchet.data, 'sample.bbc') as file_path:
_temp_file_path = os.path.join(tempdirname, 'sample.bbc')
shutil.copy(file_path, _temp_file_path)
return _check_cmd(config.paths.bgzip, 'bgzip', _temp_file_path, '-f')
return _check_cmd(config.paths.bgzip, 'bgzip', None, _temp_file_path, '-f')


def _check_picard():
Expand Down Expand Up @@ -92,6 +94,7 @@ def _check_picard():
return _check_cmd(
exe_path,
exe_name,
None,
*args_pre,
'BuildBamIndex',
'--INPUT',
Expand All @@ -101,6 +104,17 @@ def _check_picard():
)


def _check_bcftools():
# The bcftools version we select should be capable of querying remote .vcf.gz files while also specifying
# a region; This is the use case in HATCHet's genotype_snps step; This seems to work with bcftools>=1.11
try:
cmd = os.path.join(config.paths.bcftools, 'bcftools')
bcftools_version = subprocess.check_output([cmd, '--version-only']).decode('utf-8')
return version.parse(bcftools_version) >= version.parse('1.11')
except: # noqa: E722
return False


def _check_python_import(which):
try:
importlib.import_module(which)
Expand Down Expand Up @@ -131,6 +145,7 @@ def _check_python_import(which):
_check_cmd,
config.paths.samtools,
'samtools',
None,
'--version',
),
(
Expand All @@ -142,6 +157,7 @@ def _check_python_import(which):
_check_cmd,
config.paths.mosdepth,
'mosdepth',
None,
'--version',
),
],
Expand All @@ -155,18 +171,16 @@ def _check_python_import(which):
_check_cmd,
config.paths.samtools,
'samtools',
None,
'--version',
),
(
'bcftools',
'',
'Please install bcftools executable and either ensure its on your PATH, or its location specified in '
'Please install bcftools>=1.11 executable and either ensure its on your PATH, or its location specified in '
'hatchet.ini as config.paths.bcftools, or its location specified using the environment variable '
'HATCHET_PATHS_BCFTOOLS',
_check_cmd,
config.paths.bcftools,
'bcftools',
'--version',
_check_bcftools,
),
],
'count-alleles': [
Expand All @@ -179,6 +193,7 @@ def _check_python_import(which):
_check_cmd,
config.paths.samtools,
'samtools',
None,
'--version',
),
(
Expand All @@ -187,10 +202,7 @@ def _check_python_import(which):
'Please install bcftools executable and either ensure its on your PATH, or its location specified in '
'hatchet.ini as config.paths.bcftools, or its location specified using the environment variable '
'HATCHET_PATHS_BCFTOOLS',
_check_cmd,
config.paths.bcftools,
'bcftools',
'--version',
_check_bcftools,
),
],
'phase-snps': [
Expand All @@ -200,10 +212,7 @@ def _check_python_import(which):
'Please install bcftools executable and either ensure its on your PATH, or its location specified in '
'hatchet.ini as config.paths.samtools, or its location specified using the environment variable '
'HATCHET_PATHS_BCFTOOLS',
_check_cmd,
config.paths.bcftools,
'bcftools',
'--version',
_check_bcftools,
),
(
'picard',
Expand All @@ -223,6 +232,7 @@ def _check_python_import(which):
_check_cmd,
config.paths.shapeit,
'shapeit',
None,
'--version',
),
(
Expand Down