Create microtable object to store and manage all the basic files.
This class is a wrapper for a series of operations on the original files and the basic manipulations,
including the microtable object creation, data reduction, data rarefaction based on Paul et al. (2013) <doi:10.1371/journal.pone.0061217>, taxa abundance calculation,
alpha and beta diversity calculation based on the An et al. (2019) <doi:10.1016/j.geoderma.2018.09.035> and
Lozupone et al. (2005) <doi:10.1128/AEM.71.12.8228–8235.2005> and other basic operations.
The tutorial website: https://chiliubio.github.io/microeco_tutorial/
microtable.
new()
microtable$new( otu_table, sample_table = NULL, tax_table = NULL, phylo_tree = NULL, rep_fasta = NULL, auto_tidy = FALSE )
otu_table
data.frame; necessary; The feature abundance table, rows are features, e.g. species, cols are samples.
sample_table
data.frame; default NULL; The sample information table, rows are samples, cols are sample metadata; If not provided, the function can generate a table automatically according to the sample names in otu_table.
tax_table
data.frame; default NULL; The taxonomic information table, rows are species, cols are taxonomic classes.
phylo_tree
phylo; default NULL; The phylogenetic tree; use read.tree function in ape package for input.
rep_fasta
list or DNAStringSet; default NULL; The representative sequences; use read.fasta function in seqinr package or readDNAStringSet function in Biostrings package for input.
auto_tidy
default FALSE; Whether trim the files in dataset automatically. If TRUE, all other operations that
an object of class "microtable" with the following components:
sample_table
The sample information table.
otu_table
The OTU table.
tax_table
The taxonomic table.
phylo_tree
The phylogenetic tree.
rep_fasta
The representative sequence.
taxa_abund
default NULL; use cal_abund function to calculate.
alpha_diversity
default NULL; use cal_alphadiv function to calculate.
beta_diversity
default NULL; use cal_betadiv function to calculate.
data(otu_table_16S) data(taxonomy_table_16S) data(sample_info_16S) data(phylo_tree_16S) dataset <- microtable$new(otu_table = otu_table_16S) dataset <- microtable$new(sample_table = sample_info_16S, otu_table = otu_table_16S, tax_table = taxonomy_table_16S, phylo_tree = phylo_tree_16S) # trim the files in the dataset dataset$tidy_dataset()
filter_pollution()
Filter the taxa considered as pollution from tax_table. This operation will remove any line of the tax_table containing any the word in taxa parameter regardless of word case.
microtable$filter_pollution(taxa = c("mitochondria", "chloroplast"))
taxa
default: c("mitochondria", "chloroplast"); filter mitochondria and chloroplast, or others as needed.
None
dataset$filter_pollution(taxa = c("mitochondria", "chloroplast"))
rarefy_samples()
Rarefy communities to make all samples have same species number. See also rrarefy
for the alternative method.
microtable$rarefy_samples(sample.size = NULL, rngseed = 123, replace = TRUE)
sample.size
default:NULL; species number, If not provided, use minimum number of all samples.
rngseed
random seed; default: 123.
replace
default: TRUE; See sample
for the random sampling.
None; rarefied dataset.
\donttest{ dataset$rarefy_samples(sample.size = min(dataset$sample_sums()), replace = TRUE) }
tidy_dataset()
Tidy the object of microtable Class. Trim files in the object to make taxa and samples consistent across all files in the object. So the results are intersections.
microtable$tidy_dataset(main_data = FALSE)
main_data
default FALSE; if TRUE, only basic files in microtable object is trimmed. Otherwise, all files, including taxa_abund, alpha_diversity and beta_diversity, are all trimed.
None, Object of microtable itself cleaned up.
dataset$tidy_dataset(main_data = TRUE)
add_rownames2taxonomy()
Add the rownames of tax_table as the last column of tax_table. This is especially useful when the rownames of tax_table are required as a taxonomic level for the following taxa_abund calculation and biomarker idenfification.
microtable$add_rownames2taxonomy(use_name = "OTU")
use_name
default "OTU"; The column name used in the tax_table.
new tax_table stored in object.
\donttest{ dataset$add_rownames2taxonomy() }
cal_abund()
Calculate the taxonomic abundance at each taxonomic rank.
microtable$cal_abund( select_cols = NULL, rel = TRUE, split_group = FALSE, split_by = "&&", split_column = NULL )
select_cols
default NULL; numeric vector or character vector of colnames of tax_table; used to select columns to merge and calculate abundances. This is very useful if there are commented columns or some columns with multiple structure that cannot be used directly.
rel
default TRUE; if TRUE, relative abundance is used; if FALSE, absolute abundance will be summed.
split_group
default FALSE; if TRUE, split the rows to multiple rows according to one or more columns in tax_table. Very useful when multiple mapping info exist.
split_by
default "&&"; Separator delimiting collapsed values; only useful when split_group == TRUE; see sep in separate_rows function.
split_column
default NULL; character vector or list; only useful when split_group == TRUE; character vector: fixed column or columns used for the splitting in tax_table in each abundance calculation; list: containing more character vectors to assign the column names to each calculation, such as list(c("Phylum"), c("Phylum", "Class")).
taxa_abund in object.
\donttest{ dataset$cal_abund() }
save_abund()
Save taxonomic abundance to the computer local place.
microtable$save_abund(dirpath = "taxa_abund")
dirpath
default "taxa_abund"; directory name to save the taxonomic abundance files.
\dontrun{ dataset$save_abund(dirpath = "taxa_abund") }
sample_sums()
Sum the species number for each sample.
microtable$sample_sums()
species number of samples.
\donttest{ dataset$sample_sums() }
taxa_sums()
Sum the species number for each taxa.
microtable$taxa_sums()
species number of taxa.
\donttest{ dataset$taxa_sums() }
sample_names()
Show sample names.
microtable$sample_names()
sample names.
\donttest{ dataset$sample_names() }
taxa_names()
Show taxa names of tax_table.
microtable$taxa_names()
taxa names.
\donttest{ dataset$taxa_names() }
rename_taxa()
Rename the taxa, including the rownames of otu_table, rownames of tax_table, tip labels of phylogenetic tree and representative sequences.
microtable$rename_taxa(newname_prefix = "ASV_")
newname_prefix
default "ASV_"; the prefix of new names; new names will be newname_prefix + numbers according to the rowname order of otu_table.
renamed dataset.
\donttest{ dataset$rename_taxa() }
merge_samples()
Merge samples according to specific group to generate a new microtable.
microtable$merge_samples(use_group)
use_group
the group column in sample_table.
a new merged microtable object.
\donttest{ dataset$merge_samples(use_group = "Group") }
merge_taxa()
Merge taxa according to specific taxonomic rank to generate a new microtable.
microtable$merge_taxa(taxa = "Genus")
taxa
the specific rank in tax_table.
a new merged microtable object.
\donttest{ dataset$merge_taxa(taxa = "Genus") }
cal_alphadiv()
Calculate alpha diversity in microtable object.
microtable$cal_alphadiv(measures = NULL, PD = FALSE)
measures
default NULL; one or more indexes from "Observed", "Coverage", "Chao1", "ACE", "Shannon", "Simpson", "InvSimpson", "Fisher", "PD"; If null, use all those measures. 'Shannon', 'Simpson' and 'InvSimpson' are calculated based on vegan::diversity function; 'Chao1' and 'ACE' depend on the function vegan::estimateR; 'PD' depends on the function picante::pd.
PD
TRUE or FALSE, whether phylogenetic tree should be calculated, default FALSE.
alpha_diversity stored in object.
\donttest{ dataset$cal_alphadiv(measures = NULL, PD = FALSE) class(dataset$alpha_diversity) }
save_alphadiv()
Save alpha diversity table to the computer.
microtable$save_alphadiv(dirpath = "alpha_diversity")
dirpath
default "alpha_diversity"; directory name to save the alpha_diversity.csv file.
cal_betadiv()
Calculate beta diversity in microtable object, including Bray-Curtis, Jaccard, and UniFrac. See An et al. (2019) <doi:10.1016/j.geoderma.2018.09.035> and Lozupone et al. (2005) <doi:10.1128/AEM.71.12.8228–8235.2005>.
microtable$cal_betadiv(method = NULL, unifrac = FALSE, binary = FALSE, ...)
method
default NULL; a character vector with one or more elements; If default, "bray" and "jaccard" will be used;
see vegdist
function and method parameter in vegan package.
unifrac
default FALSE; TRUE or FALSE, whether unifrac index should be calculated.
binary
default FALSE; TRUE is used for jaccard and unweighted unifrac; optional for other indexes.
...
parameters passed to vegdist
function.
beta_diversity stored in object.
\donttest{ dataset$cal_betadiv(unifrac = FALSE) class(dataset$beta_diversity) }
save_betadiv()
Save beta diversity matrix to the computer.
microtable$save_betadiv(dirpath = "beta_diversity")
dirpath
default "beta_diversity"; directory name to save the beta diversity matrix files.
print()
Print the microtable object.
microtable$print()
clone()
The objects of this class are cloneable with this method.
microtable$clone(deep = FALSE)
deep
Whether to make a deep clone.
## ------------------------------------------------ ## Method `microtable$new` ## ------------------------------------------------ data(otu_table_16S) data(taxonomy_table_16S) data(sample_info_16S) data(phylo_tree_16S) dataset <- microtable$new(otu_table = otu_table_16S) dataset <- microtable$new(sample_table = sample_info_16S, otu_table = otu_table_16S, tax_table = taxonomy_table_16S, phylo_tree = phylo_tree_16S) # trim the files in the dataset dataset$tidy_dataset() ## ------------------------------------------------ ## Method `microtable$filter_pollution` ## ------------------------------------------------ dataset$filter_pollution(taxa = c("mitochondria", "chloroplast")) ## ------------------------------------------------ ## Method `microtable$rarefy_samples` ## ------------------------------------------------ dataset$rarefy_samples(sample.size = min(dataset$sample_sums()), replace = TRUE) ## ------------------------------------------------ ## Method `microtable$tidy_dataset` ## ------------------------------------------------ dataset$tidy_dataset(main_data = TRUE) ## ------------------------------------------------ ## Method `microtable$add_rownames2taxonomy` ## ------------------------------------------------ dataset$add_rownames2taxonomy() ## ------------------------------------------------ ## Method `microtable$cal_abund` ## ------------------------------------------------ dataset$cal_abund() ## ------------------------------------------------ ## Method `microtable$save_abund` ## ------------------------------------------------ ## Not run: dataset$save_abund(dirpath = "taxa_abund") ## End(Not run) ## ------------------------------------------------ ## Method `microtable$sample_sums` ## ------------------------------------------------ dataset$sample_sums() ## ------------------------------------------------ ## Method `microtable$taxa_sums` ## ------------------------------------------------ dataset$taxa_sums() ## ------------------------------------------------ ## Method `microtable$sample_names` ## ------------------------------------------------ dataset$sample_names() ## ------------------------------------------------ ## Method `microtable$taxa_names` ## ------------------------------------------------ dataset$taxa_names() ## ------------------------------------------------ ## Method `microtable$rename_taxa` ## ------------------------------------------------ dataset$rename_taxa() ## ------------------------------------------------ ## Method `microtable$merge_samples` ## ------------------------------------------------ dataset$merge_samples(use_group = "Group") ## ------------------------------------------------ ## Method `microtable$merge_taxa` ## ------------------------------------------------ dataset$merge_taxa(taxa = "Genus") ## ------------------------------------------------ ## Method `microtable$cal_alphadiv` ## ------------------------------------------------ dataset$cal_alphadiv(measures = NULL, PD = FALSE) class(dataset$alpha_diversity) ## ------------------------------------------------ ## Method `microtable$cal_betadiv` ## ------------------------------------------------ dataset$cal_betadiv(unifrac = FALSE) class(dataset$beta_diversity)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.