getian107/PRScs

Module 'scipy' has no attribute 'sqrt'

Closed this issue · 5 comments

Hey! Thank you for this awesome work! When I try to run the test I get this issue.
I did some check and apparently the function scipy.sqrt has been removed.

$ python PRScs.py --ref_dir=./ldblk_1kg_eur --bim_prefix=path_to_bim/test --sst_file=test_data/sumstats_se.txt --n_gwas=200000 --chrom=22 --phi=1e-2 --out_dir=test_data/eur


--ref_dir=./ldblk_1kg_eur
--bim_prefix=path_to_bim/test
--sst_file=test_data/sumstats_se.txt
--a=1
--b=0.5
--phi=0.01
--n_gwas=200000
--n_iter=1000
--n_burnin=500
--thin=5
--out_dir=test_data/eur
--chrom=['22']
--beta_std=False
--write_psi=False
--seed=None


##### process chromosome 22 #####
... parse reference file: ./ldblk_1kg_eur/snpinfo_1kg_hm3 ...
... 16464 SNPs on chromosome 22 read from ./ldblk_1kg_eur/snpinfo_1kg_hm3 ...
... parse bim file: path_to_bim/test.bim ...
Traceback (most recent call last):
  File "XXX/PRScs/PRScs.py", line 115, in <module>
    main()
  File "XXX/PRScs/PRScs.py", line 102, in main
    vld_dict = parse_genet.parse_bim(param_dict['bim_prefix'], int(chrom))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "XXX/PRScs/parse_genet.py", line 40, in parse_bim
    with open(bim_file + '.bim') as ff:
         ^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'path_to_bim/test.bim'
$ python PRScs.py --ref_dir=./ldblk_1kg_eur --bim_prefix=test_data/test --sst_file=test_data/sumstats_se.txt --n_gwas=200000 --chrom=22 --phi=1e-2 --out_dir=test_data/eur


--ref_dir=./ldblk_1kg_eur
--bim_prefix=test_data/test
--sst_file=test_data/sumstats_se.txt
--a=1
--b=0.5
--phi=0.01
--n_gwas=200000
--n_iter=1000
--n_burnin=500
--thin=5
--out_dir=test_data/eur
--chrom=['22']
--beta_std=False
--write_psi=False
--seed=None


##### process chromosome 22 #####
... parse reference file: ./ldblk_1kg_eur/snpinfo_1kg_hm3 ...
... 16464 SNPs on chromosome 22 read from ./ldblk_1kg_eur/snpinfo_1kg_hm3 ...
... parse bim file: test_data/test.bim ...
... 1000 SNPs on chromosome 22 read from test_data/test.bim ...
... parse sumstats file: test_data/sumstats_se.txt ...
... 1000 SNPs read from test_data/sumstats_se.txt ...
... 1000 common SNPs in the reference, sumstats, and validation set ...
Traceback (most recent call last):
  File "/XXX/envs/prscs_env/lib/python3.12/site-packages/scipy/__init__.py", line 137, in __getattr__
    return globals()[name]
           ~~~~~~~~~^^^^^^
KeyError: 'sqrt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "XXX/PRScs/PRScs.py", line 115, in <module>
    main()
  File "XXX/PRScs/PRScs.py", line 104, in main
    sst_dict = parse_genet.parse_sumstats(ref_dict, vld_dict, param_dict['sst_file'], param_dict['n_gwas'])
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "XXX/PRScs/parse_genet.py", line 86, in parse_sumstats
    n_sqrt = sp.sqrt(n_subj)
             ^^^^^^^
  File "/XXX/envs/prscs_env/lib/python3.12/site-packages/scipy/__init__.py", line 139, in __getattr__
    raise AttributeError(
AttributeError: Module 'scipy' has no attribute 'sqrt'

It's likely that some numpy functionality that was passed through scipy no longer exists in the latest version of scipy.
You could try using an earlier version of scipy and we will update some scipy functionality to numpy sometime soon.

Perfect, thank you very much!

I got the exact same error too. Any suggestions which scipy version I should use?

I actually think it's more likely to be a package loading issue rather than an issue of the python version. For example, make sure you don't have scripts named as scipy.py in your working directory. You could also test different versions of python; the software should work for pretty much all versions.

The SciPy version I was using was 1.13.0, after downgrading to 1.11.1 the script worked. I randomly picked about a year old version. Thank you!