Commit d29cc4ca authored by Erwan DELAGE's avatar Erwan DELAGE
Browse files

Add the possibility to give a percetage rather a count for the prevalence threshold

parent fb4de32c
......@@ -32,6 +32,16 @@ library(grid)
# FILTERING FUNCTIONS #
#######################
isInt <-function(x) {
#' Test if numeric x is an integer
#'
#' @param x a numeric
#' @return TRUE if x is an integer, FALSE if it's a float.
return (x%%1==0)
}
# We can filter the abundance table in several ways (based on abundance, prevalence, quantiles etc...)
# We describe here some functions that allows for different filtering mechanism
......@@ -45,8 +55,10 @@ filter_on_prevalence <- function(abundance_table, prevalence_threshold){
#' @param prevalence_threshold int prevalence threshold
#' @return Filtered abundance table.
filtered_df <- abundance_table[rowSums(abundance > 0) >= prevalence_threshold, ]
if (!isInt(prevalence_threshold)){
prevalence_threshold = ceil(prevalence_threshold * dim(abundance_table)[2])
}
filtered_df <- abundance_table[rowSums(abundance_table > 0) >= prevalence_threshold, ]
return(filtered_df)
}
......@@ -62,14 +74,17 @@ filter_on_prevalence_per_condition <- function(abundance_table, prevalence_thres
#' @param conidtionCol string condition describing groups of samples
#' @return Filtered abundance table.
if (!isInt(prevalence_threshold)){
prevalence_threshold = ceil(prevalence_threshold * dim(abundance_table)[2])
}
category = levels(factor(contextual_table[,conditionCol]))
# Get an initial FALSE boolean vector
prev_filter_df = rowSums(abundance) < 0
prev_filter_df = rowSums(abundance_table) < 0
# Then keep only ASVS found at least in N samples in at least one condition
for (i in 2:length(category)){
min_df = abundance[,rownames(context[context[, conditionCol] == category[i],])]
min_df = abundance_table[,rownames(contextual_table[contextual_table[, conditionCol] == category[i],])]
filter_df = rowSums(abundance_table > 0) >= prevalence_threshold
prev_filter_df = prev_filter_df | filter_df
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment