| Title: | Compare Microbial Networks of 'trans_network' Class of 'microeco' Package |
|---|---|
| Description: | Compare microbial co-occurrence networks created from 'trans_network' class of 'microeco' package <https://github.com/ChiLiubio/microeco>. This package is the extension of 'trans_network' class of 'microeco' package and especially useful when different networks are constructed and analyzed simultaneously. |
| Authors: | Chi Liu [aut, cre], Minjie Yao [ctb], Xiangzhen Li [ctb] |
| Maintainer: | Chi Liu <[email protected]> |
| License: | GPL-3 |
| Version: | 0.8.0 |
| Built: | 2026-05-15 02:47:38 UTC |
| Source: | https://github.com/chiliubio/meconetcomp |
Calculating modularity of networks and assign the modules to nodes for each network.
cal_module( network_list, undirected_method = "cluster_fast_greedy", directed_method = "cluster_optimal", ... )cal_module( network_list, undirected_method = "cluster_fast_greedy", directed_method = "cluster_optimal", ... )
network_list |
a list with multiple networks; all the networks should be trans_network object created from |
undirected_method |
default "cluster_fast_greedy"; the modularity algorithm for undirected network;
see |
directed_method |
default 'cluster_optimal'; the modularity algorithm for directed network. |
... |
other parameters (except for method) passed to |
list, with module attribute in nodes of each network
data(soil_amp_network) soil_amp_network <- cal_module(soil_amp_network)data(soil_amp_network) soil_amp_network <- cal_module(soil_amp_network)
Calculate the topological properties of all the networks and merge the results into one table.
cal_network_attr(network_list)cal_network_attr(network_list)
network_list |
a list with multiple networks; all the networks should be trans_network object created from |
data.frame
data(soil_amp_network) test <- cal_network_attr(soil_amp_network)data(soil_amp_network) test <- cal_network_attr(soil_amp_network)
The cohesion is a method for quantifying the connectivity of microbial communities <doi:10.1038/ismej.2017.91>. It is defined:
where is the positive cohesion, and is the negative cohesion.
is the relative abundance of species i in sample j.
denotes the mean weight (correlation coefficient, interaction strength) of all the edges (related with species i) with positive association.
new()
cohesion$new(network_list)
network_lista list with multiple networks; all the networks should be trans_network object
created from trans_network class of microeco package.
res_list, stored in the object.
It includes two tables: res_feature and res_sample. In res_feature, the r_pos and r_neg columns mean the and .
In res_sample, the c_pos and c_neg columns denote and .
t1 <- cohesion$new(soil_amp_network)
cal_diff()
Differential test.
cohesion$cal_diff(
measure = "c_pos",
method = c("anova", "KW", "KW_dunn", "wilcox", "t.test")[1],
...
)measuredefault "c_pos"; "c_pos" or "c_neg" in the res_list$sample; "r_pos" or "r_neg" in the res_list$feature.
methoddefault "anova"; see the following available options:
Duncan's multiple range test for anova
KW: Kruskal-Wallis Rank Sum Test for all groups (>= 2)
Dunn's Kruskal-Wallis Multiple Comparisons, see dunnTest function in FSA package
Wilcoxon Rank Sum and Signed Rank Tests for all paired groups
Student's t-Test for all paired groups
...parameters passed to cal_diff function of trans_alpha class of microeco package.
res_diff in object. See the Return of cal_diff function in trans_alpha class of microeco package.
\donttest{
t1$cal_diff(method = "wilcox")
}
plot()
Plot the result.
cohesion$plot(measure = "c_pos", ...)
measuredefault "c_pos"; "c_pos" or "c_neg" in the res_list$sample; "r_pos" or "r_neg" in the res_list$feature.
...parameters pass to plot_alpha function of trans_alpha class of microeco package.
ggplot.
\donttest{
t1$plot(boxplot_add = "none", add_sig = TRUE)
}
clone()
The objects of this class are cloneable with this method.
cohesion$clone(deep = FALSE)
deepWhether to make a deep clone.
## ------------------------------------------------ ## Method `cohesion$new` ## ------------------------------------------------ t1 <- cohesion$new(soil_amp_network) ## ------------------------------------------------ ## Method `cohesion$cal_diff` ## ------------------------------------------------ t1$cal_diff(method = "wilcox") ## ------------------------------------------------ ## Method `cohesion$plot` ## ------------------------------------------------ t1$plot(boxplot_add = "none", add_sig = TRUE)## ------------------------------------------------ ## Method `cohesion$new` ## ------------------------------------------------ t1 <- cohesion$new(soil_amp_network) ## ------------------------------------------------ ## Method `cohesion$cal_diff` ## ------------------------------------------------ t1$cal_diff(method = "wilcox") ## ------------------------------------------------ ## Method `cohesion$plot` ## ------------------------------------------------ t1$plot(boxplot_add = "none", add_sig = TRUE)
The cohesion is a method for quantifying the connectivity of microbial communities <doi:10.1038/ismej.2017.91>. It is defined:
where is the positive cohesion, and is the negative cohesion.
is the relative abundance of species i in sample j.
denotes the mean weight (correlation coefficient, interaction strength) of all the edges (related with species i) with positive association.
new()
cohesionclass$new(network_list)
network_lista list with multiple networks; all the networks should be trans_network object
created from trans_network class of microeco package.
res_list, stored in the object.
It includes two tables: res_feature and res_sample. In res_feature, the r_pos and r_neg columns mean the and .
In res_sample, the c_pos and c_neg columns denote and .
t1 <- cohesionclass$new(soil_amp_network)
cal_diff()
Differential test.
cohesionclass$cal_diff(
measure = "c_pos",
method = c("anova", "KW", "KW_dunn", "wilcox", "t.test")[1],
...
)measuredefault "c_pos"; "c_pos" or "c_neg" in the res_list$sample; "r_pos" or "r_neg" in the res_list$feature.
methoddefault "anova"; see the following available options:
Duncan's multiple range test for anova
KW: Kruskal-Wallis Rank Sum Test for all groups (>= 2)
Dunn's Kruskal-Wallis Multiple Comparisons, see dunnTest function in FSA package
Wilcoxon Rank Sum and Signed Rank Tests for all paired groups
Student's t-Test for all paired groups
...parameters passed to cal_diff function of trans_alpha class of microeco package.
res_diff in object. See the Return of cal_diff function in trans_alpha class of microeco package.
\donttest{
t1$cal_diff(measure = "c_pos", method = "wilcox")
}
plot()
Plot the result.
cohesionclass$plot(measure = "c_pos", ...)
measuredefault "c_pos"; "c_pos" or "c_neg" in the res_list$sample; "r_pos" or "r_neg" in the res_list$feature.
This argument only takes effect when cal_diff function has not been used (i.e. res_diff is not in the object).
For the case that cal_diff function is performed, please change the measure parameter in cal_diff function.
...parameters pass to plot_alpha function of trans_alpha class of microeco package.
ggplot.
\donttest{
t1$plot(boxplot_add = "none", add_sig = TRUE)
}
clone()
The objects of this class are cloneable with this method.
cohesionclass$clone(deep = FALSE)
deepWhether to make a deep clone.
## ------------------------------------------------ ## Method `cohesionclass$new` ## ------------------------------------------------ t1 <- cohesionclass$new(soil_amp_network) ## ------------------------------------------------ ## Method `cohesionclass$cal_diff` ## ------------------------------------------------ t1$cal_diff(measure = "c_pos", method = "wilcox") ## ------------------------------------------------ ## Method `cohesionclass$plot` ## ------------------------------------------------ t1$plot(boxplot_add = "none", add_sig = TRUE)## ------------------------------------------------ ## Method `cohesionclass$new` ## ------------------------------------------------ t1 <- cohesionclass$new(soil_amp_network) ## ------------------------------------------------ ## Method `cohesionclass$cal_diff` ## ------------------------------------------------ t1$cal_diff(measure = "c_pos", method = "wilcox") ## ------------------------------------------------ ## Method `cohesionclass$plot` ## ------------------------------------------------ t1$plot(boxplot_add = "none", add_sig = TRUE)
microtable object with paired nodes distributions of edges across networksGenerate a microtable object with paired nodes distributions of edges across networks. Useful for the edge comparisons across different networks.
The return otu_table in microtable object has the binary numbers in which 1 represents the presence of the edge in the corresponding network.
edge_comp(network_list)edge_comp(network_list)
network_list |
a list with multiple networks; all the networks should be trans_network object created from |
microtable object
data(soil_amp_network) test <- edge_comp(soil_amp_network) # test is a microtable objectdata(soil_amp_network) test <- edge_comp(soil_amp_network) # test is a microtable object
This class is a wrapper for a series of analysis on the distance values of paired nodes in edges across networks, including distance matrix conversion, the differential test and the visualization.
new()
edge_node_distance$new( network_list, dis_matrix = NULL, label = "+", with_module = FALSE, module_thres = 2 )
network_lista list with multiple networks; all the networks should be trans_network object
created from trans_network class of microeco package.
dis_matrixdefault NULL; the distance matrix of nodes, used for the value extraction; must be a symmetrical matrix (or data.frame object) with both colnames and rownames (i.e. feature names).
labeldefault "+"; "+" or "-" or c("+", "-"); the edge label used for the selection of edges.
with_moduledefault FALSE; whether show the module classification of nodes in the result.
module_thresdefault 2; the threshold of the nodes number of modules remained when with_module = TRUE.
data_table, stored in the object
\donttest{
data(soil_amp_network)
data(soil_amp)
# filter useless features to speed up the calculation
node_names <- unique(unlist(lapply(soil_amp_network, function(x){colnames(x$data_abund)})))
filter_soil_amp <- microeco::clone(soil_amp)
filter_soil_amp$otu_table <- filter_soil_amp$otu_table[node_names, ]
filter_soil_amp$tidy_dataset()
# obtain phylogenetic distance matrix
phylogenetic_distance <- as.matrix(cophenetic(filter_soil_amp$phylo_tree))
# choose the positive labels
t1 <- edge_node_distance$new(network_list = soil_amp_network,
dis_matrix = phylogenetic_distance, label = "+")
}
cal_diff()
Differential test across networks.
edge_node_distance$cal_diff(
method = c("anova", "KW", "KW_dunn", "wilcox", "t.test")[1],
...
)methoddefault "anova"; see the following available options:
Duncan's multiple range test for anova
KW: Kruskal-Wallis Rank Sum Test for all groups (>= 2)
Dunn's Kruskal-Wallis Multiple Comparisons, see dunnTest function in FSA package
Wilcoxon Rank Sum and Signed Rank Tests for all paired groups
Student's t-Test for all paired groups
...parameters passed to cal_diff function of trans_alpha class of microeco package.
res_diff in object. See the Return of cal_diff function in trans_alpha class of microeco package.
\donttest{
t1$cal_diff(method = "wilcox")
}
plot()
Plot the distance.
edge_node_distance$plot(...)
...parameters pass to plot_alpha function of trans_alpha class of microeco package.
ggplot.
\donttest{
t1$plot(boxplot_add = "none", add_sig = TRUE)
}
clone()
The objects of this class are cloneable with this method.
edge_node_distance$clone(deep = FALSE)
deepWhether to make a deep clone.
## ------------------------------------------------ ## Method `edge_node_distance$new` ## ------------------------------------------------ data(soil_amp_network) data(soil_amp) # filter useless features to speed up the calculation node_names <- unique(unlist(lapply(soil_amp_network, function(x){colnames(x$data_abund)}))) filter_soil_amp <- microeco::clone(soil_amp) filter_soil_amp$otu_table <- filter_soil_amp$otu_table[node_names, ] filter_soil_amp$tidy_dataset() # obtain phylogenetic distance matrix phylogenetic_distance <- as.matrix(cophenetic(filter_soil_amp$phylo_tree)) # choose the positive labels t1 <- edge_node_distance$new(network_list = soil_amp_network, dis_matrix = phylogenetic_distance, label = "+") ## ------------------------------------------------ ## Method `edge_node_distance$cal_diff` ## ------------------------------------------------ t1$cal_diff(method = "wilcox") ## ------------------------------------------------ ## Method `edge_node_distance$plot` ## ------------------------------------------------ t1$plot(boxplot_add = "none", add_sig = TRUE)## ------------------------------------------------ ## Method `edge_node_distance$new` ## ------------------------------------------------ data(soil_amp_network) data(soil_amp) # filter useless features to speed up the calculation node_names <- unique(unlist(lapply(soil_amp_network, function(x){colnames(x$data_abund)}))) filter_soil_amp <- microeco::clone(soil_amp) filter_soil_amp$otu_table <- filter_soil_amp$otu_table[node_names, ] filter_soil_amp$tidy_dataset() # obtain phylogenetic distance matrix phylogenetic_distance <- as.matrix(cophenetic(filter_soil_amp$phylo_tree)) # choose the positive labels t1 <- edge_node_distance$new(network_list = soil_amp_network, dis_matrix = phylogenetic_distance, label = "+") ## ------------------------------------------------ ## Method `edge_node_distance$cal_diff` ## ------------------------------------------------ t1$cal_diff(method = "wilcox") ## ------------------------------------------------ ## Method `edge_node_distance$plot` ## ------------------------------------------------ t1$plot(boxplot_add = "none", add_sig = TRUE)
Taxonomic sum of linked nodes in edges across networks.
edge_tax_comp( network_list, taxrank = "Phylum", label = "+", rel = TRUE, sep = " -- " )edge_tax_comp( network_list, taxrank = "Phylum", label = "+", rel = TRUE, sep = " -- " )
network_list |
a list with multiple networks; all the networks should be trans_network object created from |
taxrank |
default "Phylum"; Which taxonomic level is used for the sum of nodes in edges. |
label |
default "+"; "+" or "-" or |
rel |
default |
sep |
default " – "; The separator for two taxonomic names shown in the result. |
data.frame
data(soil_amp_network) test <- edge_tax_comp(soil_amp_network) # test is a microtable objectdata(soil_amp_network) test <- edge_tax_comp(soil_amp_network) # test is a microtable object
Get edge property table for each network in the list with multiple networks.
get_edge_table(network_list)get_edge_table(network_list)
network_list |
a list with multiple networks; all the networks should be trans_network object created from |
list, with res_edge_table in each network
data(soil_amp_network) soil_amp_network <- get_edge_table(soil_amp_network)data(soil_amp_network) soil_amp_network <- get_edge_table(soil_amp_network)
Get node property table for each network in the list with multiple networks.
get_node_table(network_list, ...)get_node_table(network_list, ...)
network_list |
a list with multiple networks; all the networks should be trans_network object created from |
... |
parameter passed to get_node_table function of |
list, with res_node_table in each network
data(soil_amp_network) soil_amp_network <- get_node_table(soil_amp_network, node_roles = FALSE)data(soil_amp_network) soil_amp_network <- get_node_table(soil_amp_network, node_roles = FALSE)
For the detailed tutorial on meconetcomp package, please follow the links:
Online tutorial website: https://chiliubio.github.io/microeco_tutorial/meconetcomp-package.html
Download tutorial: https://github.com/ChiLiubio/microeco_tutorial/releases
Please open the help document by using help function or by clicking the following links collected:cal_modulecal_network_attrget_node_tableget_edge_tablenode_compedge_compedge_node_distanceedge_tax_compsubset_networksubnet_propertyrobustnessvulnerabilitycohesionclass
To report bugs or discuss questions, please use Github Issues (https://github.com/ChiLiubio/meconetcomp/issues). Before creating a new issue, please read the guideline (https://chiliubio.github.io/microeco_tutorial/notes.html#github-issues).
To cite meconetcomp package in publications, please run the following command to get the reference: citation("meconetcomp")
Reference:
Chi Liu, Chaonan Li, Yanqiong Jiang, Raymond Jianxiong Zeng, Minjie Yao, and Xiangzhen Li. 2023.
A guide for comparing microbial co-occurrence networks. iMeta. 2(1): e71.
Generate a microtable object with node distributions across networks. Useful for the node information comparisons across different networks.
node_comp(network_list, property = "name")node_comp(network_list, property = "name")
network_list |
a list with multiple networks; all the networks should be trans_network object created from |
property |
default "name"; a colname of |
microtable object
data(soil_amp_network) test <- node_comp(soil_amp_network) # test is a microtable objectdata(soil_amp_network) test <- node_comp(soil_amp_network) # test is a microtable object
This class is a wrapper for robustness calculation and visualization.
new()
robustness$new(
network_list,
remove_strategy = c("edge_rand", "edge_strong", "edge_weak", "node_rand", "node_hub",
"node_hubcon", "node_nethub", "node_modhub", "node_con", "node_degree_high",
"node_degree_low")[1],
remove_ratio = seq(0, 1, 0.1),
remove_number = NULL,
measure = c("Eff", "Eigen", "Pcr")[1],
run = 10,
delete_unlinked_nodes = FALSE
)network_lista list with multiple networks; all the networks should be trans_network object
created from trans_network class of microeco package.
remove_strategydefault "edge_rand";
The edges are randomly removed.
The edges are removed in decreasing order of weight.
The edges are removed in increasing order of weight.
The nodes are removed randomly.
The node hubs are randomly removed. The hubs include network hubs and module hubs.
The node hubs and connectors are randomly removed, including network hubs, module hubs and connectors.
The network hubs are randomly removed.
The module hubs are randomly removed.
The connectors are randomly removed.
nodes are removed in decreasing order of degree.
nodes are removed in increasing order of degree.
remove_ratiodefault seq(0, 1, 0.1). Removed ratio of nodes or edges according to the remove_strategy option.
remove_numberdefault NULL. Fixed number (e.g., 5 or c(1, 5)) instead of the ratio of remove_ratio parameter.
When it is provided, the parameter remove_ratio will be disabled.
measuredefault "Eff"; network robustness measures.
network efficiency. The average efficiency of the network is defined:
where N is the total number of nodes and d(i,j) is the shortest path between node i and node j.
When the weight is found in the edge attributes, denotes the weighted shortest path between node i and node j.
For more details, please read the references <doi: 10.1007/s11704-016-6108-z> and <doi: 10.1038/s41598-020-60298-7>.
natural connectivity <doi: 10.1007/s11704-016-6108-z>. The natural connectivity can be regarded as an average eigenvalue that changes strictly monotonically with the addition or deletion of edges. It is defined:
where is the th eigenvalue of the graph adjacency matrix. The larger the value of is, the more robust the network is.
critical removal fraction of vertices (edges) for the disintegration of networks
<doi: 10.1007/s11704-016-6108-z> <doi: 10.1103/PhysRevE.72.056130>.
This is a robustness measure based on random graph theory.
The critical fraction against random attacks is labeled as . It is defined:
where is the average nodal degree of the original network, and is the average of square of nodal degree.
rundefault 10. Replication number of simulation for the sampling method;
Only available when remove_strategy = "edge_rand", "node_rand", "node_hub", "node_hubcon", "node_nethub", "node_modhub" or "node_con".
delete_unlinked_nodesdefault FALSE; whether delete the nodes without any link when removing edges.
res_table and res_summary, stored in the object. The res_table is the original simulation result.
The Mean and SD in res_summary come from the res_table.
tmp <- robustness$new(soil_amp_network, remove_strategy = c("edge_rand"),
measure = c("Eff"), run = 3, remove_ratio = c(0.1, 0.5, 0.9))
plot()
Plot the simulation results.
robustness$plot( color_values = RColorBrewer::brewer.pal(8, "Dark2"), show_point = TRUE, point_size = 1, point_alpha = 0.6, show_errorbar = TRUE, errorbar_position = position_dodge(0), errorbar_size = 1, errorbar_width = 0.1, add_fitting = FALSE, ... )
color_valuescolors used for presentation.
show_pointdefault TRUE; whether show the point.
point_sizedefault .3; point size value.
point_alphadefault .6; point alpha value.
show_errorbardefault TRUE; whether show the errorbar by using the SD result.
errorbar_positiondefault position_dodge(0); Position adjustment, either as a string (such as "identity"), or the result of a call to a position adjustment function.
errorbar_sizedefault 1; errorbar line size.
errorbar_widthdefault 0.1; errorbar width.
add_fittingdefault FALSE; whether add fitted smooth line. FALSE denotes add line segment among points.
...parameters pass to ggplot2::geom_line (when add_fitting = FALSE) or ggplot2::geom_smooth (when add_fitting = TRUE).
ggplot.
\donttest{
tmp$plot(linewidth = 1)
}
clone()
The objects of this class are cloneable with this method.
robustness$clone(deep = FALSE)
deepWhether to make a deep clone.
## ------------------------------------------------ ## Method `robustness$new` ## ------------------------------------------------ tmp <- robustness$new(soil_amp_network, remove_strategy = c("edge_rand"), measure = c("Eff"), run = 3, remove_ratio = c(0.1, 0.5, 0.9)) ## ------------------------------------------------ ## Method `robustness$plot` ## ------------------------------------------------ tmp$plot(linewidth = 1)## ------------------------------------------------ ## Method `robustness$new` ## ------------------------------------------------ tmp <- robustness$new(soil_amp_network, remove_strategy = c("edge_rand"), measure = c("Eff"), run = 3, remove_ratio = c(0.1, 0.5, 0.9)) ## ------------------------------------------------ ## Method `robustness$plot` ## ------------------------------------------------ tmp$plot(linewidth = 1)
The soil_amp data is the 16S rRNA gene amplicon sequencing dataset of Chinese wetland soils. Reference: An et al. 2019 <doi:10.1016/j.geoderma.2018.09.035>; Liu et al. 2022 <10.1016/j.geoderma.2022.115866>
data(soil_amp)data(soil_amp)
The soil_amp_network data is a list storing three trans_network objects created based on soil_amp data. Three networks are created for IW, CW and TW groups, respectively.
data(soil_amp_network)data(soil_amp_network)
The soil_measure_diversity data is a table storing all the abiotic factors and functional diversity based on the metagenomic sequencing and MetaCyc pathway analysis.
data(soil_measure_diversity)data(soil_measure_diversity)
The stool_met data is the metagenomic species abundance dataset of stool samples selected from R ExperimentHub package. It has 198 samples, collected from the people with alcohol drinking habit, and 92 species.
data(stool_met)data(stool_met)
Extracting sub-network according to the presence of features in each sample across networks and calculate the sub-network properties.
subnet_property(network_list, ...)subnet_property(network_list, ...)
network_list |
a list with multiple networks; all the networks should be trans_network object created from |
... |
parameters pass to |
data.frame
data(soil_amp_network) test <- subnet_property(soil_amp_network)data(soil_amp_network) test <- subnet_property(soil_amp_network)
Extracting a network according to the edge intersection of networks.
subset_network(network_list, venn = NULL, name = NULL)subset_network(network_list, venn = NULL, name = NULL)
network_list |
a list with multiple networks; all the networks should be |
venn |
default NULL; a |
name |
default NULL; integer or character; must be a number or one of colnames of the |
trans_network object, with only the extracted edges in the network
data(soil_amp_network) # first obtain edge distribution tmp <- edge_comp(soil_amp_network) # obtain edge intersection using trans_venn class tmp1 <- microeco::trans_venn$new(tmp) # convert intersection result to microtable object tmp2 <- tmp1$trans_comm() # extract the intersection of all the three networks ("IW", "TW" and "CW") test <- subset_network(soil_amp_network, venn = tmp2, name = "IW&TW&CW") # test is a trans_network objectdata(soil_amp_network) # first obtain edge distribution tmp <- edge_comp(soil_amp_network) # obtain edge intersection using trans_venn class tmp1 <- microeco::trans_venn$new(tmp) # convert intersection result to microtable object tmp2 <- tmp1$trans_comm() # extract the intersection of all the three networks ("IW", "TW" and "CW") test <- subset_network(soil_amp_network, venn = tmp2, name = "IW&TW&CW") # test is a trans_network object
The vulnerability of each node represents the influence of the node on the global efficiency of the network, i.e. the efficiency of network after removing the targeted node.
For the detailed defination of global efficiency, please see the "Eff" option of measure parameter in robustness class.
vulnerability(network_list)vulnerability(network_list)
network_list |
a list with multiple networks; all the networks should be trans_network object created from |
data.frame
data(soil_amp_network) vulnerability_table <- vulnerability(soil_amp_network)data(soil_amp_network) vulnerability_table <- vulnerability(soil_amp_network)