Convert bfile to bgen files

130 views
Skip to first unread message

Z S

unread,
Apr 1, 2023, 9:05:45 PM4/1/23
to plink2-users
Hi expert,
Yesterday, I posted a question about converting bfiles to bgen files, and then the developer replied to me. However, after I sent files and a response, my message on the Google Groups has automatically been deleted. I am not sure why. So, I have to start a new conversation, so that the developer can receive these files and command lines that I used. Thanks.

Attached are the test files to replicate the negative allele frequency, including test_bfile.tar.gz, test_bgen.tar.gz and test_gwas.tar.gz.

Step 1: convert bfile to bgen (v1.2)

plink2 \

--bfile test \

--export bgen-1.2 \

--out test_bgen \

--extract five_snps.txt


bgenix \

-g test_bgen.bgen \

-index


After applying the above code on test_bfile.tar.gz, I got bgen files, which are saved in test_bgen.tar.gz. And then,


Step 2: run GWAS with bgenie

bgenie/v1.2/bgenie_v1.2_static1 \

--bgen test_bgen.bgen \

--pheno test_pheno.txt \

--out test_gwas

gunzip -c test_gwas.gz > test_gwas


We can get GWAS results, which are saved in test_gwas.tar.gz


So, we can see several SNPs have negative allele frequency, which is indicated by "af" in test_gwas file. PS. "af" is the short name of "allele frequency".


Do you have any thoughts about this error? Any thoughts are welcome.

Best,

Cain

test_gwas.tar.gz
test_bgen.tar.gz
test_bfile.tar.gz

Christopher Chang

unread,
Apr 2, 2023, 11:12:18 PM4/2/23
to plink2-users
I provided the .bgen file as input to "qctool -snp-stats", and that program did not report negative allele frequencies.  So the .bgen file is probably fine.

My first guess as to why bgenie mishandles the file is that "--export bgen-1.2" defaults to 16-bit precision, while the UK Biobank .bgen files which bgenie was tested on use 8-bit precision.  If this is the issue, you can make plink2 export 8-bit-precision .bgen files with "--export bgen-1.2 bits=8".

If this does not solve the problem, you will need to either try to get further support from the bgenie developers, or switch to regenie (which is one of Jonathan Marchini's current projects).

Z S

unread,
Apr 3, 2023, 9:17:42 AM4/3/23
to plink2-users
Hi expert,
Thanks for your reply. I just now converted bfile to bgen by specifying 'bits=8', but it still does not work. There is still some negative allele frequency in the output. However, I found something interesting.

If I convert bfile to bgen-v1.1 by PLINK2, the allele frequency computed by BGENIE becomes positive, but they are slightly different from what we compute by QCTOOL. For example, below are a comparison between the allele frequencies computed by BGENIE (with bgen-v1.1) and QCTOOL

Allele frequency from BGENIE (with bgen-v1.1)
chr rsid pos a_0 a_1 af
22 rs62224609 16051249 T C 0.0983403
22 rs376238049 16052962 C T 0.041445
22 rs62224614 16053862 C T 0.098356
22 rs7286962 16054454 C T 0.098197
22 rs117246541 16055122 G T 0.016502

Allele frequency from QCTOOL:
rsid chromosome position alleleA alleleB alleleA_frequency alleleB_frequency
rs62224609 22 16051249 T C 0.901058 0.0989423
rs376238049 22 16052962 C T 0.953012 0.0469879
rs62224614 22 16053862 C T 0.900509 0.0994909
rs7286962 22 16054454 C T 0.900246 0.0997541
rs117246541 22 16055122 G T 0.976636 0.0233639

Do you have any thoughts about the slight difference between the two sets of allele frequencies? Thanks

Chris Chang

unread,
Apr 3, 2023, 10:17:16 AM4/3/23
to Z S, plink2-users
My primary recommendation is to try to switch to regenie, which is actively maintained.  I’m not going to continue speculating about bgenie when its source code is not available.

--
You received this message because you are subscribed to the Google Groups "plink2-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to plink2-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/plink2-users/3d65b978-8b83-4c22-9c31-9412b5c7f04cn%40googlegroups.com.
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages