Code for the multipartite
This commit is contained in:
parent
e6c38905b3
commit
96db7c5169
1 changed files with 42 additions and 0 deletions
42
multipartite_taxtable.R
Normal file
42
multipartite_taxtable.R
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
library(sbm)
|
||||||
|
library(phyloseq)
|
||||||
|
library(biomformat)
|
||||||
|
library(here)
|
||||||
|
source("utils.R")
|
||||||
|
|
||||||
|
options(parallelly.availableCores.custom = function() {
|
||||||
|
ncores <- min(parallelly::availableCores(), 64)
|
||||||
|
max(1L, ncores)
|
||||||
|
})
|
||||||
|
|
||||||
|
message(paste("Number of cores available:", parallelly::availableCores()))
|
||||||
|
args <- commandArgs(trailingOnly = TRUE)
|
||||||
|
if (length(args) == 0) {
|
||||||
|
author <- "mach"
|
||||||
|
} else {
|
||||||
|
author <- args[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
message("For author: ", author)
|
||||||
|
the_data <- import_biom(here("data", author, paste0(author, ".biom")))
|
||||||
|
|
||||||
|
epoch <- as.integer(Sys.time())
|
||||||
|
|
||||||
|
per_taxa_networks <- collapse_otu_at_taxo(the_data)
|
||||||
|
per_taxa_networks <- per_taxa_networks[-1]
|
||||||
|
|
||||||
|
lbm_list <- lapply(seq_along(per_taxa_networks), function(idx) {
|
||||||
|
defineSBM(per_taxa_networks[[idx]], model = "poisson", dimLabels = c(row = paste0("Rank", idx + 1), col = "Sample"))
|
||||||
|
})
|
||||||
|
|
||||||
|
lbm_list_covariates <- lapply(seq_along(per_taxa_networks), function(idx) {
|
||||||
|
covar_sd <- log(rep(1, nrow(per_taxa_networks[[idx]])) %*% t(colSums(per_taxa_networks[[idx]])))
|
||||||
|
defineSBM(per_taxa_networks[[idx]], model = "poisson", dimLabels = c(row = paste0("Rank", idx + 1), col = "Sample"), covariates = list(covar_sd))
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
multipartite_fit <- estimateMultipartiteSBM(listSBM = lbm_list, estimOptions = list(initBM = FALSE))
|
||||||
|
|
||||||
|
multipartite_covariates_fit <- estimateMultipartiteSBM(listSBM = lbm_list_covariates, estimOptions = list(initBM = FALSE))
|
||||||
|
|
||||||
|
plot(multipartite_covariates_fit)
|
||||||
Loading…
Add table
Reference in a new issue