From 8e970da966eaec49a5372c8f9072a968ed0a5449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Legault?= Date: Wed, 18 Jul 2018 10:22:27 -0400 Subject: [PATCH 1/3] Improved error reporting for the split chromosome readers. --- geneparse/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/geneparse/__init__.py b/geneparse/__init__.py index 78ca138..a8058f5 100644 --- a/geneparse/__init__.py +++ b/geneparse/__init__.py @@ -61,6 +61,7 @@ def __call__(self, pattern, *args, **kwargs): # Explode the path for every possible chromosome. chrom_to_reader = {} + last_exception = None for chrom in list(range(1, 23)) + ["X", "Y", "XY", "MT"]: chrom = str(chrom) cur = re.sub("{chrom}", chrom, pattern) @@ -69,8 +70,15 @@ def __call__(self, pattern, *args, **kwargs): chrom_to_reader[chrom] = self.reader_class( cur, *args, **kwargs ) - except: - pass + except Exception as e: + last_exception = e + + if len(chrom_to_reader) == 0: + raise ValueError( + "Could not initialize any genotype reader for chromosomes 1 " + "to 22 or X, Y, XY, MT.\nLast exception was: {}." + "".format(last_exception) + ) return SplitChromosomeReader(chrom_to_reader) From fbff0a5738a70b62b50ad0597ace1f45cbe9e2a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Legault?= Date: Thu, 6 Dec 2018 10:23:12 -0500 Subject: [PATCH 2/3] Made cyvcf2 optional because the latest version is hard to automatically install. --- geneparse/readers/vcf.py | 13 ++++++++++++- geneparse/tests/test_vcf.py | 1 + setup.py | 5 ++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/geneparse/readers/vcf.py b/geneparse/readers/vcf.py index 78a66e7..d2d9e30 100644 --- a/geneparse/readers/vcf.py +++ b/geneparse/readers/vcf.py @@ -27,12 +27,23 @@ from ..core import Variant, ImputedVariant, Genotypes, GenotypesReader -from cyvcf2 import VCF import numpy as np +try: + from cyvcf2 import VCF + CYVCF2_AVAILABLE = True +except ImportError: + CYVCF2_AVAILABLE = False + class VCFReader(GenotypesReader): def __init__(self, filename, quality_field=None): + if not CYVCF2_AVAILABLE: + raise RuntimeError( + "cyvcf2 is not installed. Install cyvcf2 (from source or " + "using `pip install cyvcf2`) to use the VCF reader." + ) + self.get_vcf = lambda: VCF(filename) self.quality_field = quality_field diff --git a/geneparse/tests/test_vcf.py b/geneparse/tests/test_vcf.py index 85ba743..3a5b6ac 100644 --- a/geneparse/tests/test_vcf.py +++ b/geneparse/tests/test_vcf.py @@ -50,6 +50,7 @@ } +@unittest.skipIf(not vcf.CYVCF2_AVAILABLE, "cyvcf2 is not installed") class TestVCF(TestContainer, unittest.TestCase): @classmethod def setUpClass(cls): diff --git a/setup.py b/setup.py index bca9c3e..3a62996 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ MAJOR = 0 MINOR = 7 -MICRO = 4 +MICRO = 5 VERSION = "{0}.{1}.{2}".format(MAJOR, MINOR, MICRO) @@ -63,8 +63,7 @@ def setup_package(): zip_safe=False, install_requires=["numpy >= 1.11.0", "pandas >= 0.19.0", "pyplink >= 1.3.4", "setuptools >= 26.1.0", - "cyvcf2 >= 0.7.4", "biopython >= 1.68", - "pybgen >= 0.5.0"], + "biopython >= 1.68", "pybgen >= 0.5.0"], packages=find_packages(), package_data={"geneparse.tests": ["data/*", "data/*/*"]}, classifiers=["Development Status :: 4 - Beta", From 306eb12005c978ed2a7b1c6153bd5fd7263fbfa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Legault?= Date: Thu, 6 Dec 2018 10:29:25 -0500 Subject: [PATCH 3/3] Fixed travis build. --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 229ee8b..6363edd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,8 @@ install: - pip install -U cython - pip install -U numpy - pip install -U pandas $(if [[ "$TRAVIS_PYTHON_VERSION" == "3.4" ]]; then echo "--no-build-isolation"; fi) - - pip install -U biopython pyplink pybgen cyvcf2 + - pip install -U biopython pyplink pybgen + - pip install 'cyvcf2<0.10' - pip list script: python setup.py test