jbisanz / qiime2R

Import qiime2 artifacts to R
MIT License
156 stars 53 forks source link

taxa_barplot plots all taxa as remainder when a sample has 0 reads #47

Open jthmiller opened 2 years ago

jthmiller commented 2 years ago

Very low priority but easy update: if there are any failed samples (0 reads) for taxa_barplot, the normalization functions produce NaNs from dividing by zero. This results in all taxa plotted as 'remainder'. I imagine that most would filter out samples with no reads before plotting. But, if taxa_barplot is used for diagnostics in a pipeline (as we do), it can be a difficult to determine why it is happening. I overwrite the qiime2R::make_proportion function to return the 0's for failed samples.

make_proportion2 <- function (features) 
{
    features <- apply(features, 2, function(x) {
        if (sum(x) > 0) { x/sum(x) } else { x }
    })
    return(features)
}

assignInNamespace("make_proportion", value = make_proportion2, ns = "qiime2R")

The same could be done with make_percent Thanks!