Network analysis

library(LorMe)
library(ggplot2)

What we can get in Network Analysis from LorMe?

LorMe provides traditional network as well as meta-network across treatment. Additionally, network various network visualization, module analysis were optional.

##Traditional Network For traditional network, at least eight samples are required. Ten to twelve samples are recommended.

### Data preparation 
data("Two_group") #contained all Treatment

Treat_obj<- sub_tax_summary(taxobj =Two_group, Group=="Treatment") # select samples from 'Treatment'
Control_obj<- sub_tax_summary(taxobj =Two_group, Group=="Control") # select samples from 'Treatment'

### Analysis
Treat_network_results<- network_analysis(
    taxobj = Treat_obj,
    taxlevel = "Base",
    n = 4,
    threshold = 0.6
  )
## Total degree: 172 
## Total edges/links: 86 
## Total vertices: 141 
## Connectance: 0.008713273 
## Average degree: 1.219858 
## Diameter: 4 
## Average path length: 1.440945 
## Global clustering coefficient: 0 
## Number of clusters: 57 
## Betweenness centralization: 0.0006316987 
## Degree centralization: 0.0127153

#### Extract nodes_info
nodes_table <-Treat_network_results$Nodes_info

#### Extract Adjacency
Adjacency_table <-Treat_network_results$Adjacency_column_table

#### Extract Adjacency matirx
Adjacency_matrix <-Treat_network_results$Adjacency_matrix

### Same for Control group
Control_network_results<- network_analysis(
    taxobj = Control_obj,
    taxlevel = "Base",
    n = 4,
    threshold = 0.6
  )
## Total degree: 154 
## Total edges/links: 77 
## Total vertices: 132 
## Connectance: 0.008905852 
## Average degree: 1.166667 
## Diameter: 3 
## Average path length: 1.314286 
## Global clustering coefficient: 0 
## Number of clusters: 55 
## Betweenness centralization: 0.0005620974 
## Degree centralization: 0.01399491

Visualization

Treat_visual<- network_visual(
  network_obj=Treat_network_results,
  mode = "major_module", #Type of visualization, "major_module" or "major_tax".
  major_num = 5, #The number of  modules to display, by default
  taxlevel = NULL, #Taxonomy levels to display,only for "major_tax" mode
  select_tax = NULL, #specific taxa to display, only for "major_tax" mode
  palette = "Set1", #Palette, by default
  vertex.size = 6 #The size of the vertices, by default
)

### same for 'Control'
Control_visual<- network_visual(
  network_obj=Control_network_results #Other parameters are set as default
)

### Other types please explore by '?network_visual'

Module Analysis

### Module composition

module_results <- Module_composition(
    network_obj = Treat_network_results,
    No.module = c(2, 6), #Module number to analysis
    taxlevel = "Phylum", #summarise level
    palette = "Plan10",  
    rmprefix = "p__"
)
module_results$Module2$Pie_plot_Module2

module_results$Module6$Pie_plot_Module6

### Module abundance
module_rel<- Module_abundance(Treat_network_results,No.module = c(2,6))

module_rel$rowframe # not available for visualization here
##    SampleID     Group Rep     Module2     Module6
## 1   Sample1 Treatment   1 0.001796945 0.002524280
## 11  Sample2 Treatment   2 0.001782683 0.003862479
## 25 Sample11 Treatment   3 0.002042379 0.002467875
## 26 Sample12 Treatment   4 0.004119071 0.003736889
## 27 Sample13 Treatment   5 0.005723877 0.004475813
## 28 Sample14 Treatment   6 0.001237360 0.001877373
## 29 Sample15 Treatment   7 0.001701331 0.003572796
## 30 Sample16 Treatment   8 0.001488538 0.001786246

Meta Network

Meta network constructs co-occurrence network across all samples. Combined with differential analysis, we can evaluate the sensitivity of network module to different treatment.

#### Analysis
network_results <- network_analysis(
  taxobj = Two_group,
  taxlevel = "Genus",
  n = 10,
  threshold = 0.8
)
## Total degree: 278 
## Total edges/links: 139 
## Total vertices: 115 
## Connectance: 0.02120519 
## Average degree: 2.417391 
## Diameter: 10 
## Average path length: 3.735019 
## Global clustering coefficient: 0.2988281 
## Number of clusters: 23 
## Betweenness centralization: 0.08704612 
## Degree centralization: 0.1103738

indicator_results <- indicator_analysis(
  taxobj = Two_group,
  taxlevel = "Genus"
)
## Calculating.......
#### Visualize
network_diff_obj <- network_withdiff(
  network_obj = network_results,
  diff_frame = indicator_results
)

##   xchar= 0.07946,0.07946,0.07946 ; (yextra, ychar)= 0,0,0, 0.1059,0.1059,0.1059 
##   points2( 1.285 1.285 1.285 , 1.006 0.9005 0.7946 , pch= 16 16 16 , ...)
#### Check contained tags for each model
print(network_diff_obj$tag_statistics$sum_of_tags)
##    No.module sum_tag_number
## 1          1             18
## 4          4             15
## 3          3              7
## 6          6              5
## 8          8              4
## 2          2              2
## 9          9              2
## 13        14              2
## 14        16              2
## 15        17              2
## 16        20              2
## 17        22              2
## 18        23              2
## 5          5              1
## 7          7              1
## 10        10              1
## 11        11              1
## 12        13              1
# Check contained different tags for each model
print(network_diff_obj$tag_statistics$detailed_tags)
##    No.module Control Treatment
## 1          1      12         6
## 2          2       0         2
## 3          3       4         3
## 4          4      12         3
## 5          5       1         0
## 6          6       5         0
## 7          7       1         0
## 8          8       4         0
## 9          9       1         1
## 10        10       0         1
## 11        11       1         0
## 12        13       1         0
## 13        14       2         0
## 14        16       2         0
## 15        17       1         1
## 16        20       2         0
## 17        22       0         2
## 18        23       1         1
#### Re-visualize
network_visual_re(
  network_visual_obj = network_diff_obj,
  module_paint = TRUE,
  module_num = c(1, 4)
)  # Show module with most Treatment indicators

##   xchar= 0.07946,0.07946,0.07946 ; (yextra, ychar)= 0,0,0, 0.1059,0.1059,0.1059 
##   points2( 1.285 1.285 1.285 , 1.006 0.9005 0.7946 , pch= 16 16 16 , ...)
###other types please explore from '?network_withdiff'
#### Module composition analaysis were conducted as above
#### Module abundance analsyis 

moduleframe<- Module_abundance(network_obj =network_results,No.module = c(1,4) )
## ###Distribution hypothesis####
## Normality Test (Shapiro-Wilk): Failed (P =  0.005569698 )
## Equal Variance Test (Brown-Forsythe):    Failed  (P =  0.04888781 )
##   Treatment_Name N     Median         Q1         Q3
## 1        Control 8 0.07400502 0.06723764 0.07317343
## 2      Treatment 8 0.11297729 0.09800371 0.13201030
## 
## 
## ###Dependent Variable: Rel ####
## 
## ###Mann-Whitney Rank Sum Test#### 
## 
## ###Statistics#### 
## 
## Mann-Whitney U Statistic=  1  
## 
## n(small)=  8 , n(big)=  8 
## P_estimate =  0.001359376  ,P_exact =  0.001131326 
## 
## ###Conclusion####
## The difference in the median values between the two groups is greater than would be expected by chance; there is a statistically significant difference  (P =  0.001131326 ).
## 
## ###Distribution hypothesis####
## Normality Test (Shapiro-Wilk): Passed (P =  0.363 )
## 
## Equal Variance Test (Brown-Forsythe):    Passed  (P =  0.961 )
## ###T-test begin ####
## 
## ###Dependent Variable: Rel ####
## 
##   Treatment_Name N       Mean          Sd         SEM
## 1        Control 8 0.05318120 0.005723841 0.002023683
## 2      Treatment 8 0.02921835 0.007167693 0.002534162
## ###Statistics####
## 
##  Method: Welch Two Sample t-test (Two-tailed)
## 
## data:  Rel
## t = 7.389, df = 13.347, p-value = 4.522e-06
## alternative hypothesis: true difference in means between group Control and group Treatment is not equal to 0
## 95 percent confidence interval:
##  0.01697517 0.03095054
## sample estimates:
##   mean in group Control mean in group Treatment 
##              0.05318120              0.02921835 
## 
## ###Conclusion####
## The difference in the mean values of the two groups is greater than would be expected by chance;
##  There is a statistically significant difference between the input groups (P =  4.521846e-06 )
moduleframe$plotlist$Plotobj_Module1$Statistics #statistics
## $Data_description
##   Treatment_Name N     Median         Q1         Q3
## 1        Control 8 0.07400502 0.06723764 0.07317343
## 2      Treatment 8 0.11297729 0.09800371 0.13201030
## 
## $Statistics
## 
##  Wilcoxon rank sum test
## 
## data:  get(colnames(data)[value_col]) by get(colnames(data)[treatment_col])
## W = 1, p-value = 0.001131
## alternative hypothesis: true location shift is not equal to 0
moduleframe$plotlist$Plotobj_Module1$Barplot #extract plot

moduleframe$plotlist$Plotobj_Module1$Boxplot #extract plot

moduleframe$plotlist$Plotobj_Module1$Violinplot #extract plot

#### Same for module 4