chr1swallace / coloc

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

Error if beta and/or varbeta contain `Inf` #133

Closed oborisov closed 6 months ago

oborisov commented 9 months ago

https://github.com/chr1swallace/coloc/blob/a44c817137daa0f4d0de56c9b77693f8228ab5fc/R/check.R#L131-L137

If beta and/or varbeta contain Inf, the error is thrown at line 137

Error in if (min(p) > warn.minp) warning("minimum p value is: ", format.pval(min(p)),  : 
  missing value where TRUE/FALSE needed

To make the error easier to debug, here is a suggestion to add check before line 132 (unless it is already checked elsewhere?)

any((d$beta %in% c(-Inf, Inf)) | (d$varbeta %in% c(-Inf, Inf)))
  stop("dataset ",suffix,": ","Infinite values in beta and/or varbeta")

Reproducible example

warn.minp <- 1e-6
d <- data.frame(beta = c(1.5, 2, Inf),
                varbeta = c(0.01, 0.9, Inf))
p=pnorm( -abs( d$beta/sqrt(d$varbeta) ) ) * 2
if(min(p) > warn.minp)
  warning("minimum p value is: ",format.pval(min(p)),"\nIf this is what you expected, this is not a problem.\nIf this is not as small as you expected, please check you supplied var(beta) and not sd(beta) for the varbeta argument. If that's not the explanation, please check the 02_data vignette.")

(Actual Inf values were found in GTExV8 raw eQTL summary statistics)

Best, Oleg

chr1swallace commented 9 months ago

The input data contains Inf?

-- https://chr1swallace.github.iohttps://chr1swallace.github.io/


From: oborisov @.> Sent: Friday, September 29, 2023 10:09 AM To: chr1swallace/coloc @.> Cc: Subscribed @.***> Subject: [chr1swallace/coloc] Error if beta and/or varbeta contain Inf (Issue #133)

https://github.com/chr1swallace/coloc/blob/a44c817137daa0f4d0de56c9b77693f8228ab5fc/R/check.R#L131-L137

If beta and/or varbeta contain Inf, the error is thrown at line 137

Error in if (min(p) > warn.minp) warning("minimum p value is: ", format.pval(min(p)), : missing value where TRUE/FALSE needed

To make the error easier to debug, here is a suggestion to add check before line 132 (unless it is already checked elsewhere?)

any((d$beta %in% c(-Inf, Inf)) | (d$varbeta %in% c(-Inf, Inf))) stop("dataset ",suffix,": ","Infinite values in beta and/or varbeta")

Reproducible example

warn.minp <- 1e-6 d <- data.frame(beta = c(1.5, 2, Inf), varbeta = c(0.01, 0.9, Inf)) p=pnorm( -abs( d$beta/sqrt(d$varbeta) ) ) * 2 if(min(p) > warn.minp) warning("minimum p value is: ",format.pval(min(p)),"\nIf this is what you expected, this is not a problem.\nIf this is not as small as you expected, please check you supplied var(beta) and not sd(beta) for the varbeta argument. If that's not the explanation, please check the 02_data vignette.")

(Actual Inf values were found in GTExV8 raw eQTL summary statistics)

Best, Oleg

— Reply to this email directly, view it on GitHubhttps://github.com/chr1swallace/coloc/issues/133, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAQWR2EJOZ7HQNZEKKWCJQTX42F5BANCNFSM6AAAAAA5MFJDXY. You are receiving this because you are subscribed to this thread.Message ID: @.***>

oborisov commented 9 months ago

Yes, the error happened when input vectors "beta" and "se" contained Inf.

chr1swallace commented 9 months ago

Well I'm not sure what the reasonable behaviour of coloc should be, except to give a better error message. coloc works by comparing evidence for/against hypotheses between snps, and you can't compare inf with non-inf

-- https://chr1swallace.github.iohttps://chr1swallace.github.io/


From: oborisov @.> Sent: Friday, September 29, 2023 10:30 AM To: chr1swallace/coloc @.> Cc: Chris Wallace @.>; Comment @.> Subject: Re: [chr1swallace/coloc] Error if beta and/or varbeta contain Inf (Issue #133)

Yes, the error happened when input vectors "beta" and "se" contained Inf.

— Reply to this email directly, view it on GitHubhttps://github.com/chr1swallace/coloc/issues/133#issuecomment-1740589218, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAQWR2A2WAO2KGJVSYT3HZDX42IMPANCNFSM6AAAAAA5MFJDXY. You are receiving this because you commented.Message ID: @.***>

oborisov commented 9 months ago

I agree, the point was only to add an error message which may help to debug (someone running into the same issue will see that the input dataset contains Inf which cannot be used by coloc anyway, therefore these Inf need to be removed prior to running coloc).

chr1swallace commented 9 months ago

agree. thanks for alerting me to this.

-- https://chr1swallace.github.iohttps://chr1swallace.github.io/


From: oborisov @.> Sent: Friday, September 29, 2023 10:53 AM To: chr1swallace/coloc @.> Cc: Chris Wallace @.>; Comment @.> Subject: Re: [chr1swallace/coloc] Error if beta and/or varbeta contain Inf (Issue #133)

I agree, the point was only to add an error message which may help to debug (someone running into the same issue will see that the input dataset contains Inf which cannot be used by coloc anyway, therefore these Inf need to be removed prior to running coloc).

— Reply to this email directly, view it on GitHubhttps://github.com/chr1swallace/coloc/issues/133#issuecomment-1740623435, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAQWR2A2AADCUP5OE4SBAADX42LCBANCNFSM6AAAAAA5MFJDXY. You are receiving this because you commented.Message ID: @.***>