Closed DrVijayKumar closed 2 years ago
Could you send me an example dataset and the full script that I can repeat?
install.packages("microeco")
install.packages("devtools")
devtools::install_github("ChiLiubio/microeco")
library(microeco)
packages <- c("reshape2", "MASS", "GUniFrac", "ggpubr", "randomForest", "ggdendro", "ggrepel", "agricolae", "gridExtra", "picante", "pheatmap", "igraph", "rgexf", "ggalluvial")
lapply(packages, function(x) { if(!require(x, character.only = TRUE)) { install.packages(x, dependencies = TRUE) }})
if (!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager") BiocManager::install("ggtree")
library("writexl") library(phyloseq) library(raster) library(ggplot2) library(vegan)
library(microeco)
data(sample_info_16S) data(otu_table_16S) data(taxonomy_table_16S) data(phylo_tree_16S)
data(env_data_16S)
library(magrittr)
set.seed(123)
library(ggplot2) theme_set(theme_bw())
class(otu_table_16S)
taxonomy_table_16S[1:5, 1:3]
taxonomy_table_16S %<>% tidy_taxonomy
class(sample_info_16S)
sample_info_16S[1:5, ]
VKS <- sample_info_16S[] fix(VKS)
VKS <- taxonomy_table_16S[] fix(VKS)
class(env_data_16S) env_data_16S
class(phylo_tree_16S) phylo_tree_16S
dataset <- microtable$new(otu_table = otu_table_16S)
class(dataset)
dataset
dataset <- microtable$new(sample_table = sample_info_16S, otu_table = otu_table_16S, tax_table = taxonomy_table_16S, phylo_tree = phylo_tree_16S) dataset
dataset$tidy_dataset() print(dataset)
dataset$tax_table %<>% base::subset(Kingdom == "kArchaea" | Kingdom == "kBacteria") print(dataset)
dataset$filter_pollution(taxa = c("mitochondria", "chloroplast"))
print(dataset)
dataset$tidy_dataset() print(dataset)
dataset$sample_sums() %>% range
dataset$rarefy_samples(sample.size = 10000)
dataset$sample_sums() %>% range
dataset$cal_abund()
class(dataset$taxa_abund)
dir.create("taxa_abund") dataset$save_abund(dirpath = "taxa_abund")
dataset$cal_alphadiv(PD = FALSE)
class(dataset$alpha_diversity)
dir.create("alpha_diversity") dataset$save_alphadiv(dirpath = "alpha_diversity")
dataset$cal_betadiv(unifrac = TRUE)
class(dataset$beta_diversity)
dir.create("beta_diversity") dataset$save_betadiv(dirpath = "beta_diversity")
library(microeco)
data(sample_info_16S) data(otu_table_16S) data(taxonomy_table_16S) data(phylo_tree_16S)
data(env_data_16S)
library(magrittr)
set.seed(123)
library(ggplot2) theme_set(theme_bw())
class(otu_table_16S) otu_table_16S[1:5, 1:5]
class(taxonomy_table_16S) taxonomy_table_16S[1:5, 1:3]
taxonomy_table_16S %<>% tidy_taxonomy
class(sample_info_16S) sample_info_16S[1:5, ]
class(env_data_16S)
class(phylo_tree_16S)
dataset <- microtable$new(otu_table = otu_table_16S)
class(dataset) dataset
dataset <- microtable$new(sample_table = sample_info_16S, otu_table = otu_table_16S, tax_table = taxonomy_table_16S, phylo_tree = phylo_tree_16S) dataset
dataset$tidy_dataset() print(dataset)
dataset$tax_table %<>% base::subset(Kingdom == "kArchaea" | Kingdom == "kBacteria") print(dataset)
dataset$filter_pollution(taxa = c("mitochondria", "chloroplast")) print(dataset)
dataset$tidy_dataset() print(dataset)
dataset$sample_sums() %>% range
dataset$rarefy_samples(sample.size = 10000)
dataset$sample_sums() %>% range
dataset$cal_abund()
class(dataset$taxa_abund)
dir.create("taxa_abund") dataset$save_abund(dirpath = "taxa_abund")
dataset$cal_alphadiv(PD = FALSE)
class(dataset$alpha_diversity)
dir.create("alpha_diversity") dataset$save_alphadiv(dirpath = "alpha_diversity")
dataset$cal_betadiv(unifrac = TRUE)
class(dataset$beta_diversity)
dir.create("beta_diversity") dataset$save_betadiv(dirpath = "beta_diversity")
t1 <- trans_abund$new(dataset = dataset, taxrank = "Phylum", ntaxa = 10)
t1$plot_bar(others_color = "grey70", facet = "Group", xtext_keep = FALSE, legend_text_italic = FALSE)
t1 <- trans_abund$new(dataset = dataset, taxrank = "Phylum", ntaxa = 10, groupmean = "Group") t1$plot_bar(others_color = "grey70", legend_text_italic = FALSE)
t1 <- trans_abund$new(dataset = dataset, taxrank = "Phylum", ntaxa = 8)
t1$plot_bar(use_alluvium = TRUE, clustering = TRUE, xtext_type_hor = FALSE, xtext_size = 6)
t1 <- trans_abund$new(dataset = dataset, taxrank = "Class", ntaxa = 15) t1$plot_box(group = "Group")
t1 <- trans_abund$new(dataset = dataset, taxrank = "Genus", ntaxa = 40) t1$plot_heatmap(facet = "Group", xtext_keep = FALSE, withmargin = FALSE)
t1 <- trans_abund$new(dataset = dataset, taxrank = "Phylum", ntaxa = 6, groupmean = "Group")
t1$plot_pie(facet_nrow = 1)
dataset1 <- dataset$merge_samples(use_group = "Group")
t1 <- trans_venn$new(dataset1, ratio = "seqratio") t1$plot_venn()
dataset1 <- dataset$merge_samples(use_group = "Type") t1 <- trans_venn$new(dataset1) t1$plot_venn(petal_plot = TRUE)
dataset1 <- dataset$merge_samples(use_group = "Group") t1 <- trans_venn$new(dataset1)
t2 <- t1$trans_venn_com(use_OTUs_frequency = TRUE)
class(t2)
t2$cal_abund()
t3 <- trans_abund$new(dataset = t2, taxrank = "Genus", ntaxa = 10) t3$plot_bar(bar_type = "part", legend_text_italic = T, ylab_title = "Frequency (%)", xtext_type_hor = FALSE)
t3 <- trans_abund$new(dataset = t2, taxrank = "Phylum", ntaxa = 8) t3$plot_pie(facet_nrow = 3, use_colors = rev(c(RColorBrewer::brewer.pal(8, "Dark2"), "grey50")))
t1 <- trans_alpha$new(dataset = dataset, group = "Group")
t1$alpha_stat[1:5, ]
t1$cal_diff(method = "KW")
t1$res_alpha_diff[1:5, ]
t1$cal_diff(method = "anova")
t1$res_alpha_diff
t1$plot_alpha(add_letter = T, measure = "Chao1", use_boxplot = FALSE)
t1$plot_alpha(pair_compare = TRUE, measure = "Chao1", shape = "Group")
t1 <- trans_alpha$new(dataset = dataset, group = "Group") t1$cal_diff(method = "anova", anova_set = "Group+Type")
t1 <- trans_beta$new(dataset = dataset, group = "Group", measure = "bray")
t1$cal_ordination(ordination = "PCoA")
class(t1$res_ordination)
t1$plot_ordination(plot_color = "Group", plot_shape = "Group", plot_group_ellipse = TRUE)
t1$cal_group_distance()
t1$plot_group_distance(distance_pair_stat = TRUE)
t1$cal_group_distance(within_group = FALSE) t1$plot_group_distance(distance_pair_stat = TRUE)
t1$plot_clustering(group = "Group", replace_name = c("Saline", "Type"))
t1$cal_manova(cal_manova_all = TRUE) t1$res_manova$aov.tab
t1$cal_manova(cal_manova_paired = TRUE) t1$res_manova
t1$cal_manova(cal_manova_set = "Group + Type") t1$res_manova$aov.tab
t1$cal_betadisper()
t1$res_betadisper
t1 <- trans_diff$new(dataset = dataset, method = "metastat", group = "Group", metastat_taxa_level = "Genus")
t1$plot_metastat(use_number = 1:10, qvalue = 0.05, choose_group = 1)
t1 <- trans_diff$new(dataset = dataset, method = "lefse", group = "Group", alpha = 0.01, lefse_subgroup = NULL)
t1$plot_lefse_bar(LDA_score = 4)
t1$res_lefse[1:5, ]
v <-t1$res_lefse[] fix(v)
t1$plot_diff_abund(use_number = 1:30)
t1$plot_lefse_cladogram(use_taxa_num = 200, use_feature_num = 50, clade_label_level = 5)
use_labels <- c("cDeltaproteobacteria", "cActinobacteria", "oRhizobiales", "pProteobacteria", "pBacteroidetes", "oMicrococcales", "pAcidobacteria", "pVerrucomicrobia", "pFirmicutes", "pChloroflexi", "cAcidobacteria", "cGammaproteobacteria", "cBetaproteobacteria", "cKD4-96", "cBacilli", "oGemmatimonadales", "fGemmatimonadaceae", "oBacillales", "o__Rhodobacterales")
t1$plot_lefse_cladogram(use_taxa_num = 200, use_feature_num = 50, select_show_labels = use_labels)
t1 <- trans_diff$new(dataset = dataset, method = "rf", group = "Group", rf_taxa_level = "Genus")
t2 <- t1$plot_diff_abund(use_number = 1:20, only_abund_plot = FALSE) gridExtra::grid.arrange(t2$p1, t2$p2, ncol=2, nrow = 1, widths = c(2,2))
t1 <- trans_env$new(dataset = dataset, add_data = env_data_16S[, 4:11])
t1$cal_rda(use_dbrda = TRUE, use_measure = "bray")
t1$trans_rda(adjust_arrow_length = TRUE, max_perc_env = 10)
t1$plot_rda(plot_color = "Group")
t1$cal_rda(use_dbrda = FALSE, taxa_level = "Genus")
t1$trans_rda(show_taxa = 10, adjust_arrow_length = TRUE, max_perc_env = 1500, max_perc_tax = 3000, min_perc_env = 200, min_perc_tax = 300)
t1$plot_rda(plot_color = "Group")
t1$cal_rda(use_dbrda = FALSE, taxa_level = "Genus")
t1$trans_rda(show_taxa = 10, adjust_arrow_length = TRUE, max_perc_env = 1500, max_perc_tax = 3000, min_perc_env = 200, min_perc_tax = 300)
t1$plot_rda(plot_color = "Group")
t1$cal_mantel(use_measure = "bray")
t1$res_mantel
t1 <- trans_env$new(dataset = dataset, add_data = env_data_16S[, 4:11]) t1$cal_cor(use_data = "Genus", p_adjust_method = "fdr")
t1$res_cor
t1$plot_cor()
t1$plot_cor()
t2 <- trans_diff$new(dataset = dataset, method = "rf", group = "Group", rf_taxa_level = "Genus")
t1 <- trans_env$new(dataset = dataset, add_data = env_data_16S[, 4:11])
t1$cal_cor(use_data = "other", p_adjust_method = "fdr", other_taxa = t2$res_rf$Taxa[1:40])
t1$plot_cor()
t1$plot_cor(pheatmap = TRUE)
t1$cal_cor(by_group = "Group", use_data = "other", p_adjust_method = "fdr", other_taxa = t2$res_rf$Taxa[1:40])
t1$plot_cor()
t1 <- trans_env$new(dataset = dataset, add_data = env_data_16S[, 4:11])
t1$cal_cor(add_abund_table = dataset$alpha_diversity) t1$plot_cor()
t1$plot_scatterfit( x = "pH", y = dataset$beta_diversity$bray[rownames(t1$env_data), rownames(t1$env_data)], alpha = .1, x_axis_title = "Euclidean distance of pH", y_axis_title = "Bray-Curtis distance", text_x_pos = 4, text_y_pos = .4)
t1 <- trans_nullmodel$new(dataset, taxa_number = 1000, add_data = env_data_16S)
t1$cal_mantel_corr(use_env = "pH")
t1$plot_mantel_corr()
t1$cal_ses_betampd(runs=500, abundance.weighted = TRUE)
dataset$beta_diversity[["betaNRI"]] <- t1$res_ses_betampd
t2 <- trans_beta$new(dataset = dataset, group = "Group", measure = "betaNRI")
t2$cal_group_distance()
g1 <- t2$plot_group_distance(distance_pair_stat = TRUE) g1 + geom_hline(yintercept = -2, linetype = 2) + geom_hline(yintercept = 2, linetype = 2)
#
sesbeta_each <- list() group_col <- "Group" all_groups <- unique(dataset$sample_table[, group_col])
for(i in all_groups){
test <- trans_nullmodel$new(dataset, group = group_col, select_group = i, taxa_number = 1000, add_data = env_data_16S) test$cal_ses_betampd(runs = 500, abundance.weighted = TRUE) sesbeta_each[[i]] <- test$res_ses_betampd }
test <- lapply(sesbeta_each, melt) %>% do.call(rbind, .) %>%
reshape2::dcast(., Var1~Var2, value.var = "value") %>% row.names<-
(.[,1]) %>% .[, -1, drop = FALSE]
dataset$beta_diversity[["betaNRI"]] <- test t2 <- trans_beta$new(dataset = dataset, group = "Group", measure = "betaNRI") t2$cal_group_distance() g1 <- t2$plot_group_distance(distance_pair_stat = TRUE) g1 + geom_hline(yintercept = -2, linetype = 2) + geom_hline(yintercept = 2, linetype = 2)
install.packages("microeco")
install.packages("devtools")
devtools::install_github("ChiLiubio/microeco")
library(microeco)
packages <- c("reshape2", "MASS", "GUniFrac", "ggpubr", "randomForest", "ggdendro", "ggrepel", "agricolae", "gridExtra", "picante", "pheatmap", "igraph", "rgexf", "ggalluvial")
lapply(packages, function(x) { if(!require(x, character.only = TRUE)) { install.packages(x, dependencies = TRUE) }})
if (!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager") BiocManager::install("ggtree")
library("writexl") library(phyloseq) library(raster) library(ggplot2) library(vegan)
library(microeco)
data(sample_info_16S) data(otu_table_16S) data(taxonomy_table_16S) data(phylo_tree_16S)
data(env_data_16S)
library(magrittr)
set.seed(123)
library(ggplot2) theme_set(theme_bw())
class(otu_table_16S) otu_table_16S[1:5, 1:5]
class(taxonomy_table_16S) taxonomy_table_16S[1:5, 1:3]
taxonomy_table_16S %<>% tidy_taxonomy
class(sample_info_16S) sample_info_16S[1:5, ]
class(env_data_16S)
class(phylo_tree_16S)
dataset <- microtable$new(otu_table = otu_table_16S)
class(dataset) dataset
dataset <- microtable$new(sample_table = sample_info_16S, otu_table = otu_table_16S, tax_table = taxonomy_table_16S, phylo_tree = phylo_tree_16S) dataset
dataset$tidy_dataset() print(dataset)
dataset$tax_table %<>% base::subset(Kingdom == "kArchaea" | Kingdom == "kBacteria") print(dataset)
dataset$filter_pollution(taxa = c("mitochondria", "chloroplast")) print(dataset)
dataset$tidy_dataset() print(dataset)
dataset$sample_sums() %>% range
dataset$rarefy_samples(sample.size = 10000)
dataset$sample_sums() %>% range
dataset$cal_abund()
class(dataset$taxa_abund)
dir.create("taxa_abund") dataset$save_abund(dirpath = "taxa_abund")
dataset$cal_alphadiv(PD = FALSE)
class(dataset$alpha_diversity)
dir.create("alpha_diversity") dataset$save_alphadiv(dirpath = "alpha_diversity")
dataset$cal_betadiv(unifrac = TRUE)
class(dataset$beta_diversity)
dir.create("beta_diversity") dataset$save_betadiv(dirpath = "beta_diversity")
t1 <- trans_alpha$new(dataset = dataset, group = "Group")
t1$alpha_stat[1:5, ]
t1$cal_diff(method = "KW")
t1$res_alpha_diff[1:5, ]
t1$cal_diff(method = "anova")
t1$res_alpha_diff
t1$plot_alpha(add_letter = T, measure = "Chao1", use_boxplot = FALSE)
t1$plot_alpha(pair_compare = TRUE, measure = "Chao1", shape = "Group")
t1 <- trans_alpha$new(dataset = dataset, group = "Group") t1$cal_diff(method = "anova", anova_set = "Group+Type")
t1 <- trans_beta$new(dataset = dataset, group = "Group", measure = "bray")
t1$cal_ordination(ordination = "PCoA")
class(t1$res_ordination)
t1$plot_ordination(plot_color = "Group", plot_shape = "Group", plot_group_ellipse = TRUE)
t1$cal_group_distance()
t1$plot_group_distance(distance_pair_stat = TRUE)
t1$cal_group_distance(within_group = FALSE) t1$plot_group_distance(distance_pair_stat = TRUE)
t1$plot_clustering(group = "Group", replace_name = c("Saline", "Type"))
t1$cal_manova(cal_manova_all = TRUE) t1$res_manova$aov.tab
t1$cal_manova(cal_manova_paired = TRUE) t1$res_manova
t1$cal_manova(cal_manova_set = "Group + Type") t1$res_manova$aov.tab
I am running the following code
manova for all groups
t1$cal_manova(cal_manova_all = TRUE) t1$res_manova$aov.tab
manova for each paired groups
t1$cal_manova(cal_manova_paired = TRUE) t1$res_manova
manova for specified group set: here "Group + Type"
t1$cal_manova(cal_manova_set = "Group + Type") t1$res_manova$aov.tab
And getting the below error, Please help
Error in
colnames<-
(*tmp*
, value = colnames(lhs)) : attempt to set 'colnames' on an object with less than two dimensions