Learn R Programming

microeco (version 0.5.1)

trans_network: Create trans_network object for co-occurrence network analysis.

Description

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.

Arguments

Methods

Public methods

Method 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.

Usage

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
)

Arguments

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.

Returns

res_cor_p list.

Examples

\donttest{
data(dataset)
# correlation network
t1 <- trans_network$new(
		dataset = dataset, 
		cal_cor = "base", 
		taxa_level = "OTU", 
		filter_thres = 0.001)
}

Method 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.

Usage

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,
  ...
)

Arguments

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".

Returns

res_network in object.

Examples

\donttest{
t1$cal_network(p_thres = 0.01, COR_cut = 0.6)
}

Method cal_module()

Add network modules to the network.

Usage

trans_network$cal_module(module_name_prefix = "M")

Arguments

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.

Returns

a network with modules, stored in object.

Examples

\donttest{
t1$cal_module()
}

Method save_network()

Save network as gexf style, which can be opened by Gephi <https://gephi.org/>.

Usage

trans_network$save_network(filepath = "network.gexf")

Arguments

filepath

default "network.gexf"; file path.

Returns

None.

Method cal_network_attr()

Calculate network properties.

Usage

trans_network$cal_network_attr()

Returns

res_network_attr in object.

Examples

\donttest{
t1$cal_network_attr()
}

Method cal_node_type()

Calculate node properties.

Usage

trans_network$cal_node_type()

Returns

res_node_type in object.

Examples

\donttest{
t1$cal_node_type()
}

Method cal_eigen()

Calculate eigengenes of modules, i.e. the first principal component based on PCA analysis, and the percentage of variance.

Usage

trans_network$cal_eigen()

Returns

res_eigen and res_eigen_expla in object.

Examples

\donttest{
t1$cal_eigen()
}

Method plot_taxa_roles()

Plot the classification and importance of nodes, see object$res_node_type for the variable names used in the parameters.

Usage

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)
)

Arguments

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.

Returns

ggplot.

Examples

\donttest{
t1$plot_taxa_roles()
}

Method subset_network()

Subset of the network.

Usage

trans_network$subset_network(node = NULL, edge = NULL, rm_single = TRUE)

Arguments

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.

Returns

a new network

Examples

\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
}

Method print()

Print the trans_network object.

Usage

trans_network$print()

Method clone()

The objects of this class are cloneable with this method.

Usage

trans_network$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

Run this code
# 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
# }

Run the code above in your browser using DataLab