trans_network {microeco}R Documentation

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> and Probabilistic Graphical Models based <doi:10.1016/j.cels.2019.08.002> network construction approaches, network and node attributes analysis and other network operations.

Methods

Public methods


Method new()

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.

cal_cor

default "base"; "base", "WGCNA", "SparCC" or NA; correlation method; NA represent do not calculate.

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)
t1 <- trans_network$new(dataset = dataset, cal_cor = "SparCC", 
  taxa_level = "OTU", filter_thres = 0.001)
t1 <- trans_network$new(dataset = dataset, cal_cor = "WGCNA", 
  taxa_level = "OTU", filter_thres = 0.0001)
# PGM network
t1 <- trans_network$new(dataset = dataset, cal_cor = NA, taxa_level = "OTU",
  filter_thres = 0.0001)
}

Method replace_name()

Replace names in res_cor_p of trans_network object.

Usage
trans_network$replace_name()
Returns

a new res_cor_p in trans_network object.

Examples
\donttest{
t1$replace_name()
}

Method cal_network()

Calculate network either based on the correlation method or based on the Probabilistic Graphical Models (PGM) in julia FlashWeave; see Deng et al. (2012) <10.1186/1471-2105-13-113> for correlation based method; see 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", "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",
  with_module = TRUE,
  add_taxa_name = "Phylum",
  usename_rawtaxa_when_taxalevel_notOTU = FALSE
)
Arguments
network_method

default "COR"; "COR" 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.

with_module

default TRUE; whether calculate modules.

add_taxa_name

default "Phylum"; add taxonomic rank name to the result.

usename_rawtaxa_when_taxalevel_notOTU

default FALSE; whether replace the name of nodes using the taxonomic information.

Returns

res_network in object.

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

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.

Examples
\donttest{
t1$save_network(filepath = "network.gexf")
}

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.

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 = NULL,
  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 represent the traditional taxa roles plot; 2 represent the plot with taxa names 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 NULL; for use_type 2; used variable for shape.

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

Sum the linkages among taxa.

Usage
trans_network$cal_sum_links(taxa_level = "Phylum")
Arguments
taxa_level

default "Phylum"; taxonomic rank.

Returns

res_sum_links_pos and res_sum_links_neg in object.

Examples
\donttest{
t1$cal_sum_links(taxa_level = "Phylum")
}

Method plot_sum_links()

Plot the summed linkages among taxa using chorddiag package <https://github.com/mattflor/chorddiag>.

Usage
trans_network$plot_sum_links(
  plot_pos = TRUE,
  plot_num = NULL,
  color_values = NULL
)
Arguments
plot_pos

default TRUE; plot the summed positive or negative linkages.

plot_num

default NULL; number of taxa presented in the plot.

color_values

default NULL; If not provided, use default.

Returns

chorddiag plot

Examples
\donttest{
t1$plot_sum_links(plot_pos = TRUE, plot_num = 10)
}

Method subset_network()

Subset of the network.

Usage
trans_network$subset_network(node = NULL, rm_single = TRUE)
Arguments
node

default NULL; provide the names of the nodes that you want to use in the sub-network.

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


## ------------------------------------------------
## Method `trans_network$new`
## ------------------------------------------------


data(dataset)
# correlation network
t1 <- trans_network$new(dataset = dataset, cal_cor = "base", 
  taxa_level = "OTU", filter_thres = 0.001)
t1 <- trans_network$new(dataset = dataset, cal_cor = "SparCC", 
  taxa_level = "OTU", filter_thres = 0.001)
t1 <- trans_network$new(dataset = dataset, cal_cor = "WGCNA", 
  taxa_level = "OTU", filter_thres = 0.0001)
# PGM network
t1 <- trans_network$new(dataset = dataset, cal_cor = NA, taxa_level = "OTU",
  filter_thres = 0.0001)


## ------------------------------------------------
## Method `trans_network$replace_name`
## ------------------------------------------------


t1$replace_name()


## ------------------------------------------------
## Method `trans_network$cal_network`
## ------------------------------------------------


t1$cal_network(p_thres = 0.01, COR_cut = 0.6)


## ------------------------------------------------
## Method `trans_network$save_network`
## ------------------------------------------------


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


## ------------------------------------------------
## Method `trans_network$cal_network_attr`
## ------------------------------------------------


t1$cal_network_attr()


## ------------------------------------------------
## Method `trans_network$cal_node_type`
## ------------------------------------------------


t1$cal_node_type()


## ------------------------------------------------
## Method `trans_network$cal_eigen`
## ------------------------------------------------


t1$cal_eigen()


## ------------------------------------------------
## Method `trans_network$plot_taxa_roles`
## ------------------------------------------------


t1$plot_taxa_roles()


## ------------------------------------------------
## Method `trans_network$cal_sum_links`
## ------------------------------------------------


t1$cal_sum_links(taxa_level = "Phylum")


## ------------------------------------------------
## Method `trans_network$plot_sum_links`
## ------------------------------------------------


t1$plot_sum_links(plot_pos = TRUE, plot_num = 10)


## ------------------------------------------------
## Method `trans_network$subset_network`
## ------------------------------------------------


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


[Package microeco version 0.2.1 Index]