knitr::opts_chunk$set(echo = TRUE)
library(metacoder)
library(profvis)
library(ggplot2)
x = parse_tax_data(hmp_otus, class_cols = "lineage", class_sep = ";",
                   class_key = c(tax_rank = "info", tax_name = "taxon_name"),
                   class_regex = "^(.+)__(.+)$")
profvis({
  calc_taxon_abund_new(x, "tax_data")
})

Effect of column number

run_time <- vapply(1:50, FUN.VALUE = numeric(1), function(n) {
  x <- select_obs(x, "tax_data", 1:n + 3)
  system.time(calc_taxon_abund_new(x, "tax_data"))[1]
})
data <- data.frame(col_num = 1:50, 
                   run_time = run_time)
ggplot(data, aes(x = col_num, y = run_time)) +
  geom_point()

linear, needs parallel processing

Effect of row number

run_time <- vapply(seq(1, 1000, by = 20), FUN.VALUE = numeric(1), function(n) {
  x <- x$sample_n_obs("tax_data", n)
  system.time(calc_taxon_abund_new(x, "tax_data"))[1]
})
data <- data.frame(col_num = 1:50, 
                   run_time = run_time)
ggplot(data, aes(x = col_num, y = run_time)) +
  geom_point()

Effect of taxon number

data <- lapply(seq(.05, 1, by = 0.05), function(p) {
  x = x$clone(deep = T)
  x$sample_frac_taxa(size = p, supertaxa = TRUE)
  c(run_time = system.time(calc_taxon_abund_new(x, "tax_data"))[1], n_taxa = length(taxon_names(x)))
})
data <- do.call( rbind, data)
ggplot(as.data.frame(data), aes(x = n_taxa, y = run_time.user.self)) +
  geom_point()


grunwaldlab/metacoder documentation built on Feb. 22, 2024, 3:47 a.m.