#'Filter features by FC
#' @export
filter_features_by_FC <- function(x, group, delta = 1E-10,
threshold = 1,
as_cpm = TRUE, as_log = TRUE) {
summary_mat <- t(apply(x, 1, function(x) tapply(x, group, sum)))
if(as_cpm) {
summatry_mat <- normalize_counts_extra(summary_mat, "cpm")
}
combin <- combn(ncol(summary_mat), m = 2)
summary_mat <- summary_mat + delta
out <- list()
for( i in seq_len(ncol(combin))) {
dat <- summary_mat[, combin[, i]]
if(as_log) {
dat <- log(dat[, 1], 2) - log(dat[, 2], 2)
} else {
dat <- dat[, 1] / dat[, 2]
}
out[[i]] <- dat
}
out <- do.call("cbind", out)
out <- abs(out)
good_features <- apply(apply(out, 1, function(x) x > threshold), 2, sum) != 0
cat(sum(!good_features ), " features filtered...\n")
list(counts = x[good_features , ], good_features = good_features)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.