This class is a wrapper for a series of network analysis related methods, including the correlation based <doi:10.1186/1471-2105-13-113>, SpiecEasi <doi:10.1371/journal.pcbi.1004226>, and Probabilistic Graphical Models based <doi:10.1016/j.cels.2019.08.002> network construction approaches, network and node attributes analysis eigengene analysis, network subsetting and other network operations.
new()
This function is used to create the trans_network object, store the important intermediate data and calculate correlations if cal_cor parameter is selected.
trans_network$new( dataset = NULL, cor_method = c("pearson", "spearman", "kendall")[1], cal_cor = c("base", "WGCNA", "SparCC", NA)[1], taxa_level = "OTU", filter_thres = 0, nThreads = 1, SparCC_simu_num = 100, env_cols = NULL, add_data = NULL )
dataset
the object of microtable
Class.
cor_method
default "pearson"; "pearson", "spearman" or "kendall"; correlation algorithm, only use for correlation based network.
cal_cor
default "base"; "base", "WGCNA", "SparCC" or NA; correlation method; NA represent do not calculate correlations, used for non-correlation based network.
taxa_level
default "OTU"; taxonomic rank.
filter_thres
default 0; the relative abundance threshold.
nThreads
default 1; the thread number used for "WGCNA" and SparCC.
SparCC_simu_num
default 100; SparCC simulation number for bootstrap.
env_cols
default NULL; number or name vector to select the physicochemical data in dataset$sample_table.
add_data
default NULL; provide physicochemical table additionally.
res_cor_p list.
\donttest{ data(dataset) # correlation network t1 <- trans_network$new( dataset = dataset, cal_cor = "base", taxa_level = "OTU", filter_thres = 0.001) }
cal_network()
Calculate network either based on the correlation method or based on SpiecEasi or based on the Probabilistic Graphical Models (PGM) in julia FlashWeave; See Deng et al. (2012) <doi:10.1186/1471-2105-13-113> for correlation based method, Kurtz et al. (2015) <doi:doi:10.1371/journal.pcbi.1004226> for SpiecEasi method, Tackmann et al. (2019) <doi:10.1016/j.cels.2019.08.002> for PGM based method.
trans_network$cal_network( network_method = c("COR", "SpiecEasi", "PGM")[1], p_thres = 0.01, COR_weight = TRUE, COR_p_adjust = "fdr", COR_cut = 0.6, COR_low_threshold = 0.4, COR_optimization = FALSE, PGM_meta_data = FALSE, PGM_sensitive = "true", PGM_heterogeneous = "true", SpiecEasi_method = "mb", add_taxa_name = "Phylum", usename_rawtaxa_when_taxalevel_notOTU = FALSE, ... )
network_method
default "COR"; "COR", "SpiecEasi" or "PGM"; COR: correlation based method; PGM: Probabilistic Graphical Models based method.
p_thres
default .01; the p value threshold.
COR_weight
default TRUE; whether use correlation coefficient as the weight of edges.
COR_p_adjust
default "fdr"; p.adjust method, see p.adjust.methods.
COR_cut
default .6; correlation coefficient threshold.
COR_low_threshold
default .4; the lowest correlation coefficient threshold, use with COR_optimization = TRUE.
COR_optimization
default FALSE; whether use random matrix theory to optimize the choice of correlation coefficient, see https://doi.org/10.1186/1471-2105-13-113
PGM_meta_data
default FALSE; whether use env data for the optimization, If TRUE, will automatically find the env_data in the object.
PGM_sensitive
default "true"; whether use sensitive type in the PGM model.
PGM_heterogeneous
default "true"; whether use heterogeneous type in the PGM model.
SpiecEasi_method
default "mb"; either 'glasso' or 'mb';see spiec.easi in package SpiecEasi and https://github.com/zdk123/SpiecEasi.
add_taxa_name
default "Phylum"; NULL or a taxonomic rank name; used to add taxonomic rank name to network.
usename_rawtaxa_when_taxalevel_notOTU
default FALSE; whether replace the name of nodes using the taxonomic information.
...
paremeters pass to spiec.easi in package SpiecEasi for network_method = "SpiecEasi".
res_network in object.
\donttest{ t1$cal_network(p_thres = 0.01, COR_cut = 0.6) }
cal_module()
Add network modules to the network.
trans_network$cal_module( method = "cluster_fast_greedy", module_name_prefix = "M" )
method
default "cluster_fast_greedy"; the method used to find the optimal community structure of a graph; the following are available functions (options) from igraph package: "cluster_fast_greedy", "cluster_optimal", "cluster_edge_betweenness", "cluster_infomap", "cluster_label_prop", "cluster_leading_eigen", "cluster_louvain", "cluster_spinglass", "cluster_walktrap".
module_name_prefix
default "M"; the prefix of module names; module names are made of the module_name_prefix and numbers; numbers are assigned according to the sorting result of node numbers in modules with decreasing trend.
a network with modules, stored in object.
\donttest{ t1$cal_module() }
save_network()
Save network as gexf style, which can be opened by Gephi <https://gephi.org/>.
trans_network$save_network(filepath = "network.gexf")
filepath
default "network.gexf"; file path.
None.
cal_network_attr()
Calculate network properties.
trans_network$cal_network_attr()
res_network_attr in object.
\donttest{ t1$cal_network_attr() }
cal_node_type()
Calculate node properties.
Authors: Chi Liu, Umer Zeeshan Ijaz
trans_network$cal_node_type()
res_node_type in object.
\donttest{ t1$cal_node_type() }
cal_eigen()
Calculate eigengenes of modules, i.e. the first principal component based on PCA analysis, and the percentage of variance.
trans_network$cal_eigen()
res_eigen and res_eigen_expla in object.
\donttest{ t1$cal_eigen() }
plot_taxa_roles()
Plot the classification and importance of nodes, see object$res_node_type for the variable names used in the parameters.
trans_network$plot_taxa_roles( use_type = c(1, 2)[1], roles_colors = NULL, plot_module = FALSE, use_level = "Phylum", show_value = c("z", "p"), show_number = 1:10, plot_color = "Phylum", plot_shape = "taxa_roles", plot_size = "Abundance", color_values = RColorBrewer::brewer.pal(12, "Paired"), shape_values = c(16, 17, 7, 8, 15, 18, 11, 10, 12, 13, 9, 3, 4, 0, 1, 2, 14) )
use_type
default 1; 1 or 2; 1 represents taxa roles area plot; 2 represents the layered plot with taxa as x axis.
roles_colors
default NULL; for use_type 1; colors for each group.
plot_module
default FALSE; for use_type 1; whether plot the modules information.
use_level
default "Phylum"; for use_type 2; used taxonomic level in x axis.
show_value
default c("z", "p"); for use_type 2; used variable in y axis.
show_number
default 1:10; for use_type 2; showed number in x axis, sorting according to the nodes number.
plot_color
default "Phylum"; for use_type 2; used variable for color.
plot_shape
default "taxa_roles"; for use_type 2; used variable for shape.
plot_size
default "Abundance"; for use_type 2; used for point size; a fixed number (e.g. 5) is also available.
color_values
default RColorBrewer::brewer.pal(12, "Paired"); for use_type 2; color vector
shape_values
default c(16, 17, 7, 8, 15, 18, 11, 10, 12, 13, 9, 3, 4, 0, 1, 2, 14); for use_type 2; shape vector, see ggplot2 tutorial for the shape meaning.
ggplot.
\donttest{ t1$plot_taxa_roles() }
subset_network()
Subset of the network.
trans_network$subset_network(node = NULL, edge = NULL, rm_single = TRUE)
node
default NULL; provide the node names that you want to use in the sub-network.
edge
default NULL; provide the edge name needed; must be one of "+" or "-".
rm_single
default TRUE; whether remove the nodes without any edge in the sub-network.
a new network
\donttest{ t1$subset_network(node = t1$res_node_type %>% .[.$module == "M1", ] %>% rownames, rm_single = TRUE) # return a sub network that contains all nodes of module M1 }
get_edge_table()
Get the table of edges, including connected nodes, labels and weight.
trans_network$get_edge_table()
data.frame
\donttest{ t1$get_edge_table() }
cal_powerlaw_p()
Perform a bootstrapping hypothesis test to determine whether degrees follows a power law distribution; a significant p represents the distribution does not follow power law.
trans_network$cal_powerlaw_p(...)
...
paremeters pass to bootstrap_p in poweRlaw package.
two lists stored in object; see estimate_xmin and bootstrap_p in poweRlaw package for the details.
\donttest{ t1$cal_powerlaw_p() }
cal_powerlaw_fit()
Fit degrees to a power law distribution.
trans_network$cal_powerlaw_fit(xmin = NULL, ...)
xmin
default NULL; See xmin in fit_power_law function; suggest using the result res_powerlaw_min from cal_powerlaw_p function.
...
paremeters pass to fit_power_law function in igraph package.
list stored in object; see fit_power_law function for the details explanation.
\donttest{ t1$cal_powerlaw_fit() }
print()
Print the trans_network object.
trans_network$print()
clone()
The objects of this class are cloneable with this method.
trans_network$clone(deep = FALSE)
deep
Whether to make a deep clone.
# NOT RUN {
## ------------------------------------------------
## Method `trans_network$new`
## ------------------------------------------------
# }
# NOT RUN {
data(dataset)
# correlation network
t1 <- trans_network$new(
dataset = dataset,
cal_cor = "base",
taxa_level = "OTU",
filter_thres = 0.001)
# }
# NOT RUN {
## ------------------------------------------------
## Method `trans_network$cal_network`
## ------------------------------------------------
# }
# NOT RUN {
t1$cal_network(p_thres = 0.01, COR_cut = 0.6)
# }
# NOT RUN {
## ------------------------------------------------
## Method `trans_network$cal_module`
## ------------------------------------------------
# }
# NOT RUN {
t1$cal_module()
# }
# NOT RUN {
## ------------------------------------------------
## Method `trans_network$cal_network_attr`
## ------------------------------------------------
# }
# NOT RUN {
t1$cal_network_attr()
# }
# NOT RUN {
## ------------------------------------------------
## Method `trans_network$cal_node_type`
## ------------------------------------------------
# }
# NOT RUN {
t1$cal_node_type()
# }
# NOT RUN {
## ------------------------------------------------
## Method `trans_network$cal_eigen`
## ------------------------------------------------
# }
# NOT RUN {
t1$cal_eigen()
# }
# NOT RUN {
## ------------------------------------------------
## Method `trans_network$plot_taxa_roles`
## ------------------------------------------------
# }
# NOT RUN {
t1$plot_taxa_roles()
# }
# NOT RUN {
## ------------------------------------------------
## Method `trans_network$subset_network`
## ------------------------------------------------
# }
# NOT RUN {
t1$subset_network(node = t1$res_node_type %>% .[.$module == "M1", ] %>%
rownames, rm_single = TRUE)
# return a sub network that contains all nodes of module M1
# }
# NOT RUN {
## ------------------------------------------------
## Method `trans_network$get_edge_table`
## ------------------------------------------------
# }
# NOT RUN {
t1$get_edge_table()
# }
# NOT RUN {
## ------------------------------------------------
## Method `trans_network$cal_powerlaw_p`
## ------------------------------------------------
# }
# NOT RUN {
t1$cal_powerlaw_p()
# }
# NOT RUN {
## ------------------------------------------------
## Method `trans_network$cal_powerlaw_fit`
## ------------------------------------------------
# }
# NOT RUN {
t1$cal_powerlaw_fit()
# }
Run the code above in your browser using DataLab