Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
legaultmarc committed Dec 6, 2018
2 parents 3b070f9 + 306eb12 commit f698f97
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 10 additions & 2 deletions geneparse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down
13 changes: 12 additions & 1 deletion geneparse/readers/vcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions geneparse/tests/test_vcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
}


@unittest.skipIf(not vcf.CYVCF2_AVAILABLE, "cyvcf2 is not installed")
class TestVCF(TestContainer, unittest.TestCase):
@classmethod
def setUpClass(cls):
Expand Down
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

MAJOR = 0
MINOR = 7
MICRO = 4
MICRO = 5
VERSION = "{0}.{1}.{2}".format(MAJOR, MINOR, MICRO)


Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit f698f97

Please sign in to comment.