chr1swallace / coloc

Repo for the R package coloc
139 stars 44 forks source link

Run coloc.abf for multiple loci together with for loop or other alternatives #88

Closed zillurbmb51 closed 2 years ago

zillurbmb51 commented 2 years ago

Hi,

I have datasets of multiple loci (144). I can run them one by one and get results. How could I run them all together and get summary for each locus in a single data frame?

So far I have tried ad follows:

res_scz_baso=data.frame()
for (i in 1:length(baso5)){res_scz_baso=coloc.abf(dataset1 = scz_baso5[[i]], dataset2 = baso5[[i]])}  

It prints out all the summaries but does not save them. If I use res_scz_baso$summary It only prints the summary results of the last locus But how could I save the summary for all the loci together in a single data frame? I want something like below:

"nsnps" "PP.H0.abf" "PP.H1.abf" "PP.H2.abf" "PP.H3.abf" "PP.H4.abf"
462 0.153403253624482   0.0750327200520324  0.0244112446998648  0.0112040985219617  0.735948683101659
58  7.57925241078212e-05    2.0055118707626e-06 0.517528340121885   0.0132249155533116  0.469168946288825
120 0.00155157723719096 0.00164083907913843 0.471694966221208   0.498805149617641   0.0263074678448224
230 0.0118292163680997  0.344346968122185   0.00350649992795145 0.101534979893137   0.538782335688627
1999    4.06462494440946e-13    2.02295899738764e-09    0.000200881646569529    0.999785551665708   1.35646643574586e-05
308 0.000137637038014421    0.34169686678901    7.70186509453464e-05    0.190738680876463   0.467349796645568
388 1.27038454844658e-31    1.47762533245564e-31    0.375238887379552   0.436263982075452   0.188497130544997
chr1swallace commented 2 years ago

untested code, but try:

res_scz_base=lapply(1:length(baso5), function(i) coloc.abf(dataset1 = scz_baso5[[i]], dataset2 = baso5[[i]])$summary)

do.call("rbind", res_scz_base)

On Fri, 2022-05-13 at 07:18 -0700, zillurbmb51 wrote:

Hi, I have datasets of multiple loci (144). I can run them one by one and get results. How could I run them all together and get summary for each locus in a single data frame? So far I have tried ad follows: res_scz_baso=data.frame() for (i in 1:length(baso5)){res_scz_baso=coloc.abf(dataset1 = scz_baso5[[i]], dataset2 = baso5[[i]])}
It prints out all the summaries but does not save them. If I use res_scz_baso$summary It only prints the summary results of the last locus But how could I save the summary for all the loci together in a single data frame? I want something like below: "nsnps" "PP.H0.abf" "PP.H1.abf" "PP.H2.abf" "PP.H3.abf" "PP.H4.abf" 462 0.153403253624482 0.0750327200520324 0.0244112446 998648 0.0112040985219617 0.735948683101659 58 7.57925241078212e-05 2.0055118707626e- 06 0.517528340121885 0.0132249155533116 0.469168946288825 120 0.00155157723719096 0.00164083907913843 0.4716949662 21208 0.498805149617641 0.0263074678448224 230 0.0118292163680997 0.344346968122185 0.0035064999 2795145 0.101534979893137 0.538782335688627 1999 4.06462494440946e-13 2.02295899738764e- 09 0.000200881646569529 0.999785551665708 1.35646643574586e-05 308 0.000137637038014421 0.34169686678901 7.7018650945 3464e-05 0.190738680876463 0.467349796645568 388 1.27038454844658e-31 1.47762533245564e- 31 0.375238887379552 0.436263982075452 0.188497130544997

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

zillurbmb51 commented 2 years ago

Thank you so much. It works!

manL23 commented 1 year ago

Hi, I tried this code for loop with multiple SNPs, res_scz_base=lapply(1:length(df), function(i) coloc.abf(dataset1 = dataset1list[[i]], dataset2 = dataset2list[[i]])$summary)

but get Error in check_dataset(d = dataset1, 1) : dataset 1: is not a list my dataset1 and dataset 2 are indeed a list including $beta, $varbeta, $MAF,$snp, $type. it seems when set dataset1list[[i]] in the coloc.abf, then dataset is not a list anymore. Any suggestion to fix it? Many thanks