omerwe / polyfun

PolyFun (POLYgenic FUNctionally-informed fine-mapping)
MIT License
89 stars 22 forks source link

finemapper.py BGEN files #68

Closed zhangpicb closed 2 years ago

zhangpicb commented 3 years ago

Hi! Thanks for your wonderful code! I want to know is LD matrix produced by LDstorev2 different from produced by Plink? So I want to use LDstore v2 ,so I converted example date to BGEN1.2 format. And I got this message

[ERROR]  Error : The database file is locked (using BGEN index file '/home/polyfun_finemapper_test/ldstore/chr1.bgen.bgi')!

My shell code,

plink2 --bfile example_data/chr1 --export bgen-1.2 --out chr1

bgenix -index -g chr1.bgen

mkdir -p LD_cache
mkdir -p output

python finemapper.py \
    --geno chr1.bgen \
    --sample-file chr1.sample \
    --sumstats example_data/chr1.finemap_sumstats.txt.gz \
    --n 383290 \
    --chr 1 \
    --start 46000001 \
    --end 49000001 \
    --method finemap \
    --finemap-exe finemap_v1.4_x86_64 \
    --ldstore2 ldstore_v2.0_x86_64 \
    --max-num-causal 5 \
    --cache-dir LD_cache \
    --out output/finemap.finemap_exe.1.46000001.49000001.gz

Thanks in advanced!

omerwe commented 3 years ago

I actually get a different error message:

[ERROR]  Error : SNP with rsID 'rs1105456' in file '/tmp/tmp0txl0gbt/chr1.46000001_49000001.z' could not be matched with SNP in BGEN file 'chr1.bgen'!

I believe the problem is that the chromosome names are encoded as "01" in the FINEMAP .z file, but as "1" in the bgen file. I just pushed commit ecc80ad98b8db0a731762e14956688e5c71ac8c5 to fix this issue. Can you please git pull and retry? Please note that you'll need to install the bgen package (pip install bgen).

zhangpicb commented 3 years ago

I git pull the code and pip install bgen.And still get the error message

sqlite3.OperationalError: database is locked
omerwe commented 3 years ago

Hi,

The code doesn't use SQLite... Can you please add the flag --verbose to your command, and copy-paste the entire output?

zhangpicb commented 3 years ago

sorry for reply late. I think this error may caused by BGEN,and I am unfamiliar with BGEN.

''' [INFO] Loading sumstats file... [INFO] Loaded sumstats for 966 SNPs in 0.42 seconds [DEBUG] opening bgen index: /home/polyfun_finemapper_test/ldstore/chr1.bgen.bgi [DEBUG] opening BgenFile from /home/polyfun_finemapper_test/ldstore/chr1.bgen Traceback (most recent call last): File "/home/polyfun/finemapper.py", line 1233, in residual_var=args.susie_resvar, residual_var_init=args.susie_resvar_init, hess_resvar=args.susie_resvar_hess) File "/home/polyfun/finemapper.py", line 954, in finemap ld_data = self.get_ld_data(locus_start, locus_end, need_bcor=True, verbose=verbose) File "/home/polyfun/finemapper.py", line 571, in get_ld_data ld_file = self.compute_ld_bgen(locus_start, locus_end, verbose=verbose) File "/home/polyfun/finemapper.py", line 397, in compute_ld_bgen bgen_chromosomes = bfile.chroms() File "src/bgen/bgen.pyx", line 463, in bgen.reader.BgenFile.chroms File "/picb/lilab4/miniconda3/envs/polyfun/lib/python3.6/site-packages/bgen/index.py", line 101, in chroms query = conn.execute("SELECT chromosome FROM Variant") sqlite3.OperationalError: database is locked

omerwe commented 3 years ago

It looks like something locks the bgen file. I would just try to restart the computer you're working on and then try again...

AlisaBIG commented 2 years ago

Hi,Omer!I met the same problem. I wan to calculate LD matrix using LDstore, but got error message: Error : SNP with rsID '12:89675376:A:G' in file 'chr12_block167.z' could not be matched with SNP in BGEN file 'chr12_block167.bgen'! However chromosome id and rsid are same in my BGEN file and Z file. Do you know where the problem is?

omerwe commented 2 years ago

Hi @AlisaBIG, I'm not sure what's causing the problem. Can you please add the flag --verbose to your command, and copy-paste the entire output?