CAST-genomics / haptools

Ancestry and haplotype aware simulation of genotypes and phenotypes for complex trait analysis
https://haptools.readthedocs.io
MIT License
19 stars 4 forks source link

numpy error when testing `simgenotype` #149

Closed armartin closed 1 year ago

armartin commented 1 year ago

Thanks for writing haptools! I'm running into an issue when testing the simgenotype module, example as follows:

$ haptools simgenotype \
> --model model.dat \
> --mapdir test_haptools/ \
> --invcf ALL.wgs.nhgri_coriell_affy_6.20140825.genotypes_no_ped.vcf.gz \
> --sample_info 1000genomes_sampleinfo.tsv \
> --out test
Traceback (most recent call last):
  File "/Users/alicia/Library/Python/3.7/bin/haptools", line 8, in <module>
    sys.exit(main())
  File "/Users/alicia/Library/Python/3.7/lib/python/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/Users/alicia/Library/Python/3.7/lib/python/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/Users/alicia/Library/Python/3.7/lib/python/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/alicia/Library/Python/3.7/lib/python/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/alicia/Library/Python/3.7/lib/python/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/alicia/Library/Python/3.7/lib/python/site-packages/haptools/__main__.py", line 181, in simgenotype
    from .sim_genotype import (
  File "/Users/alicia/Library/Python/3.7/lib/python/site-packages/haptools/sim_genotype.py", line 13, in <module>
    from .data import GenotypesRefAlt, GenotypesPLINK
  File "/Users/alicia/Library/Python/3.7/lib/python/site-packages/haptools/data/__init__.py", line 2, in <module>
    from .phenotypes import Phenotypes
  File "/Users/alicia/Library/Python/3.7/lib/python/site-packages/haptools/data/phenotypes.py", line 10, in <module>
    import numpy.typing as npt
ModuleNotFoundError: No module named 'numpy.typing'

numpy otherwise seems to work fine on my computer. Any ideas why this might be happening or how to fix it?

aryarm commented 1 year ago

Hi @armartin !

Thank you for trying out haptools! What version of numpy is that? We might need to pin to a version recent enough that it contains numpy's typing module (ie some version $\ge$ 1.20)

import numpy
import numpy.typing as npt # does this line work for you?

print(numpy.__version__)

As a temporary workaround, you can try just commenting out the lines that import numpy.typing. It's only used for type checking, anyway.

Or, if it's indeed an older version of numpy, you can try updating numpy or installing haptools within a new, empty conda environment.

armartin commented 1 year ago

Hi @aryarm, Thanks for your quick response! It does indeed look like an older version of numpy:

print(numpy.__version__)
1.19.2

I upgraded my numpy and it now seems to run fine. Thanks a bunch!

aryarm commented 1 year ago

great! I'm glad it was an easy fix

I've updated the version of numpy that we require to be $\ge$ 1.20.0 so that this issue doesn't crop up again in future releases of haptools (see #151)