yijuanhu / LOCOM-Archive

A logistic regression model for testing differential abundance in compositional microbiome data
12 stars 2 forks source link

Bugs for calculating the ref.otu? #9

Open jamesjiadazhan opened 1 year ago

jamesjiadazhan commented 1 year ago

Hi,

Thanks for developing this package.

I was trying to use this package and was stuck for a long time to figure out an error: r$> result_HILIC <- locom( otu.table = cleaned_gut_mic, Y = Y, C = C, fdr.nominal = 0.2, seed = 1, adjustment = "BH", n.cores = 16 ) 1 OTU(s) with fewer than 36.2 in all samples are removed Error in otu.table + otu.table[, ref.otu] : non-conformable arrays

I looked around the original LOCOM code, and found that by fixing one part, adding na.rm = TRUE to colMeans, my error went away:

Original code: ` # find reference OTU

if (is.null(ref.otu)) {
    mean.freq <- colMeans(otu.table/rowSums(otu.table))
    ref.otu <- which.max(mean.freq)
}`

My updated version: ` # find reference OTU

if (is.null(ref.otu)) {
    mean.freq <- colMeans(otu.table/rowSums(otu.table), na.rm = TRUE)
    ref.otu <- which.max(mean.freq)
}

`

I think it is a bug, because although it may be rare, one of the rowSums(otu.table) results could be 0. If so, the colMeans would be messed up since the denominator is 0.

yijuanhu commented 1 year ago

Thank you so much for reporting this bug! We will fix it in our next version.

Yijuan

On Apr 9, 2023, at 11:55 PM, James Jiada Zhan @.**@.>> wrote:

Hi,

Thanks for developing this package.

I was trying to use this package and was stuck for a long time to figure out an error: r$> result_HILIC <- locom( otu.table = cleaned_gut_mic, Y = Y, C = C, fdr.nominal = 0.2, seed = 1, adjustment = "BH", n.cores = 16 ) 1 OTU(s) with fewer than 36.2 in all samples are removed Error in otu.table + otu.table[, ref.otu] : non-conformable arrays

I looked around the original LOCOM code, and found that by fixing one part, adding na.rm = TRUE to colMeans, my error went away:

Original code: ` # find reference OTU

if (is.null(ref.otu)) { mean.freq <- colMeans(otu.table/rowSums(otu.table)) ref.otu <- which.max(mean.freq) }`

My updated version: ` # find reference OTU

if (is.null(ref.otu)) { mean.freq <- colMeans(otu.table/rowSums(otu.table), na.rm = TRUE) ref.otu <- which.max(mean.freq) }

`

I think it is a bug, because although it may be rare, one of the rowSums(otu.table) results could be 0. If so, the colMeans would be messed up since the denominator is 0.

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