Feature Analysis

library(LorMe)
library(ggplot2)

Community Feature Analysis

LorMe provide community feature analysis including alpha diversity, beta/structure analysis and community composition analysis. All feature analysis was based on encapsulated object. (How to encapsulate)?

Alpha diversity

##data preparation####
data("Two_group") # tax summary objects with configuration

##Alpha diversirt analysis
Alpha_results<- Alpha_diversity_calculator(taxobj = Two_group, 
                                           taxlevel = "Base"  #analysis level
                                           ) 
## ###Distribution hypothesis####
## Normality Test (Shapiro-Wilk): Failed (P =  0.04441989 )
## Equal Variance Test (Brown-Forsythe):    Passed  (P =  0.528 )
##   Treatment_Name N   Median       Q1       Q3
## 1        Control 8 6.608076 6.486807 6.545958
## 2      Treatment 8 6.455881 6.390880 6.450683
## 
## 
## ###Dependent Variable: Indexvalue ####
## 
## ###Mann-Whitney Rank Sum Test#### 
## 
## ###Statistics#### 
## 
## Mann-Whitney U Statistic=  48  
## 
## n(small)=  8 , n(big)=  8 
## P_estimate =  0.1035619  ,P_exact =  0.09289194 
## 
## ###Conclusion####
## The difference in the median values between the two groups is not great enough to exclude the possibility that the difference is due to random sampling variability; there is not a statistically significant difference  (P =  0.09289194 ).
## Analysis finished
## ###Distribution hypothesis####
## Normality Test (Shapiro-Wilk): Passed (P =  0.589 )
## 
## Equal Variance Test (Brown-Forsythe):    Passed  (P =  0.137 )
## ###T-test begin ####
## 
## ###Dependent Variable: Indexvalue ####
## 
##   Treatment_Name N     Mean       Sd      SEM
## 1        Control 8 1348.875 103.6938 36.66131
## 2      Treatment 8 1231.500 152.1212 53.78296
## ###Statistics####
## 
##  Method: Welch Two Sample t-test (Two-tailed)
## 
## data:  Indexvalue
## t = 1.8033, df = 12.35, p-value = 0.09578
## alternative hypothesis: true difference in means between group Control and group Treatment is not equal to 0
## 95 percent confidence interval:
##  -23.99857 258.74857
## sample estimates:
##   mean in group Control mean in group Treatment 
##                1348.875                1231.500 
## 
## ###Conclusion####
## The difference in the mean values of the two groups is not great enough to reject the possibility that the difference is due to random sampling variability. There is not a statistically significant difference between the input groups (P =  0.09577966 )
## Analysis finished
## ###Distribution hypothesis####
## Normality Test (Shapiro-Wilk): Passed (P =  0.718 )
## 
## Equal Variance Test (Brown-Forsythe):    Passed  (P =  0.994 )
## ###T-test begin ####
## 
## ###Dependent Variable: Indexvalue ####
## 
##   Treatment_Name N      Mean         Sd         SEM
## 1        Control 8 0.9085666 0.01379727 0.004878073
## 2      Treatment 8 0.9075135 0.01342757 0.004747362
## ###Statistics####
## 
##  Method: Welch Two Sample t-test (Two-tailed)
## 
## data:  Indexvalue
## t = 0.15472, df = 13.99, p-value = 0.8793
## alternative hypothesis: true difference in means between group Control and group Treatment is not equal to 0
## 95 percent confidence interval:
##  -0.01354710  0.01565335
## sample estimates:
##   mean in group Control mean in group Treatment 
##               0.9085666               0.9075135 
## 
## ###Conclusion####
## The difference in the mean values of the two groups is not great enough to reject the possibility that the difference is due to random sampling variability. There is not a statistically significant difference between the input groups (P =  0.8792553 )
## Analysis finished
## ###Distribution hypothesis####
## Normality Test (Shapiro-Wilk): Failed (P =  0.00407253 )
## Equal Variance Test (Brown-Forsythe):    Passed  (P =  0.839 )
##   Treatment_Name N    Median        Q1        Q3
## 1        Control 8 0.9977593 0.9972547 0.9974599
## 2      Treatment 8 0.9970120 0.9967638 0.9969616
## 
## 
## ###Dependent Variable: Indexvalue ####
## 
## ###Mann-Whitney Rank Sum Test#### 
## 
## ###Statistics#### 
## 
## Mann-Whitney U Statistic=  52  
## 
## n(small)=  8 , n(big)=  8 
## P_estimate =  0.04056886  ,P_exact =  0.0356919 
## 
## ###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.0356919 ).
## Analysis finished
## ###Distribution hypothesis####
## Normality Test (Shapiro-Wilk): Passed (P =  0.62 )
## 
## Equal Variance Test (Brown-Forsythe):    Passed  (P =  0.145 )
## ###T-test begin ####
## 
## ###Dependent Variable: Indexvalue ####
## 
##   Treatment_Name N     Mean       Sd      SEM
## 1        Control 8 1357.496 109.5964 38.74817
## 2      Treatment 8 1241.538 161.1087 56.96052
## ###Statistics####
## 
##  Method: Welch Two Sample t-test (Two-tailed)
## 
## data:  Indexvalue
## t = 1.6832, df = 12.336, p-value = 0.1174
## alternative hypothesis: true difference in means between group Control and group Treatment is not equal to 0
## 95 percent confidence interval:
##  -33.68965 265.60577
## sample estimates:
##   mean in group Control mean in group Treatment 
##                1357.496                1241.538 
## 
## ###Conclusion####
## The difference in the mean values of the two groups is not great enough to reject the possibility that the difference is due to random sampling variability. There is not a statistically significant difference between the input groups (P =  0.1174497 )
## Analysis finished
## ###Distribution hypothesis####
## Normality Test (Shapiro-Wilk): Passed (P =  0.577 )
## 
## Equal Variance Test (Brown-Forsythe):    Passed  (P =  0.144 )
## ###T-test begin ####
## 
## ###Dependent Variable: Indexvalue ####
## 
##   Treatment_Name N     Mean       Sd      SEM
## 1        Control 8 1368.366 113.8825 40.26355
## 2      Treatment 8 1249.384 166.6579 58.92247
## ###Statistics####
## 
##  Method: Welch Two Sample t-test (Two-tailed)
## 
## data:  Indexvalue
## t = 1.6672, df = 12.367, p-value = 0.1206
## alternative hypothesis: true difference in means between group Control and group Treatment is not equal to 0
## 95 percent confidence interval:
##  -35.99884 273.96411
## sample estimates:
##   mean in group Control mean in group Treatment 
##                1368.366                1249.384 
## 
## ###Conclusion####
## The difference in the mean values of the two groups is not great enough to reject the possibility that the difference is due to random sampling variability. There is not a statistically significant difference between the input groups (P =  0.1205737 )
## Analysis finished
head(Alpha_results$alphaframe,5) # alpha diversity frame
##   SampleID     Group Rep Indexname Indexvalue
## 1  Sample1 Treatment   1   Shannon   6.555904
## 2  Sample2 Treatment   2   Shannon   6.351143
## 3  Sample3   Control   1   Shannon   6.528515
## 4  Sample4   Control   2   Shannon   6.650545
## 5  Sample5   Control   3   Shannon   6.639492
names(Alpha_results$plotlist) #check plotlist
## [1] "Plotobj_Shannon"        "Plotobj_Species number" "Plotobj_Simpson"       
## [4] "Plotobj_Evenness"       "Plotobj_Chao"           "Plotobj_ACE"
Alpha_results$plotlist$Plotobj_Shannon$Barplot #extract plot

Alpha_results$plotlist$Plotobj_Shannon$Boxplot

Alpha_results$plotlist$Plotobj_Shannon$Violinplot

Beta/Structure

##Community structure
community_structure<- structure_plot(taxobj = Two_group,
                                     taxlevel = "Base", #Analysis level
                                     diagram = "stick" #Style of plot
                                     )
## Run 0 stress 0.08827856 
## Run 1 stress 0.09171458 
## Run 2 stress 0.09459435 
## Run 3 stress 0.09216234 
## Run 4 stress 0.1106779 
## Run 5 stress 0.09459425 
## Run 6 stress 0.0951984 
## Run 7 stress 0.1078229 
## Run 8 stress 0.1091765 
## Run 9 stress 0.09171461 
## Run 10 stress 0.09216223 
## Run 11 stress 0.09327251 
## Run 12 stress 0.0932725 
## Run 13 stress 0.09459423 
## Run 14 stress 0.09216244 
## Run 15 stress 0.09327266 
## Run 16 stress 0.09459422 
## Run 17 stress 0.09328546 
## Run 18 stress 0.1091763 
## Run 19 stress 0.08984926 
## Run 20 stress 0.09171461 
## *** Best solution was not repeated -- monoMDS stopping criteria:
##     20: stress ratio > sratmax
###check PERMANOVA results
print(community_structure$PERMANOVA_statistics)
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 999
## 
## adonis2
##          Df SumOfSqs     R2      F Pr(>F)    
## Group     1   0.6802 0.2045 3.5991  0.001 ***
## Residual 14   2.6460 0.7955                  
## Total    15   3.3263 1.0000                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
###extract plot
community_structure$PCA_Plot

community_structure$PCoA_Plot

community_structure$NMDS_Plot

##extract coordinates frame
PCA_coord<- community_structure$PCA_coordinates
head(PCA_coord,5)
##          PC1       PC2 SampleID     Group Rep     cent1     cent2
## 1 -23.580643  24.36589  Sample1 Treatment   1 -15.56312  18.49638
## 2 -13.599862  11.10910  Sample2 Treatment   2 -15.56312  18.49638
## 3   4.124383 -18.15145  Sample3   Control   1  15.56312 -18.49638
## 4   2.665482 -20.85253  Sample4   Control   2  15.56312 -18.49638
## 5   3.174064 -83.61568  Sample5   Control   3  15.56312 -18.49638

Composition

require(magrittr)
phylum10 <- community_plot(
    taxobj = Two_group,
    taxlevel = "Phylum", #Analysis level
    n = 10, #Displaying number of top taxon, by default
    rmprefix = "p__", #prefix to remove, optional
    palette = "Paired" #paletter, optional
  )
##extract results
phylum10$barplot  # Check bar plot

phylum10$areaplot  # Check area plot

phylum10$alluvialplot  # Check alluvial plot

phylum10$Top10Phylum %>% head(10)  # Check top taxa data frame
##                        Phylum    Sample1     Sample2     Sample3     Sample4
## 35             Proteobacteria 0.44405938 0.338073005 0.487765642 0.410655391
## 3               Acidobacteria 0.15564968 0.318251273 0.107018881 0.150951374
## 4              Actinobacteria 0.11966799 0.081324278 0.139615613 0.131289641
## 22                Chloroflexi 0.09245711 0.086587436 0.075988485 0.113361522
## 30           Gemmatimonadetes 0.06588799 0.037648557 0.063246126 0.062917548
## 29                 Firmicutes 0.04488085 0.057767402 0.046312759 0.048287526
## 40            Verrucomicrobia 0.01446113 0.022198642 0.019558039 0.026088795
## 33                Nitrospirae 0.02173448 0.021307301 0.017737702 0.011881607
## 8               Bacteroidetes 0.01390493 0.010271647 0.012996359 0.014545455
## 14 Candidatus Latescibacteria 0.00397895 0.004414261 0.004360342 0.003551797
##       Sample5     Sample6     Sample7     Sample8     Sample9    Sample10
## 35 0.37162880 0.440284601 0.462802915 0.488301248 0.385030831 0.475244176
## 3  0.16793374 0.108377096 0.114048466 0.099005712 0.182989581 0.109255423
## 4  0.10367382 0.156657632 0.149042535 0.124772583 0.097257070 0.123969388
## 22 0.11633043 0.121251906 0.096805626 0.064819124 0.129194131 0.077628853
## 30 0.06001274 0.046035914 0.047364853 0.106409985 0.050648522 0.097501163
## 29 0.06468465 0.046544130 0.041814947 0.032494182 0.047969381 0.034036616
## 40 0.04506265 0.029264781 0.025673615 0.009985191 0.034998937 0.012938142
## 33 0.01652155 0.012324242 0.012031859 0.029193992 0.020497555 0.024650121
## 8  0.01295392 0.016135863 0.017920691 0.014470066 0.012842866 0.013191831
## 14 0.00798471 0.003430459 0.002075919 0.001565475 0.004720391 0.001606697
##       Sample11    Sample12    Sample13    Sample14    Sample15   Sample16
## 35 0.437069186 0.435942078 0.343949045 0.400477877 0.353111310 0.38204398
## 3  0.213896690 0.179795320 0.161473575 0.199513590 0.221598401 0.24288691
## 4  0.090460386 0.096776933 0.098424858 0.118914537 0.085236698 0.11623357
## 22 0.090332738 0.116183277 0.210965743 0.102146179 0.111182000 0.07919024
## 30 0.046464131 0.047263153 0.050955414 0.053633144 0.085321764 0.04257219
## 29 0.033656710 0.045012527 0.048287141 0.047702351 0.049083408 0.04384808
## 40 0.018934559 0.015457132 0.024832157 0.023339165 0.020798775 0.03461915
## 33 0.025827589 0.024034991 0.021690480 0.018816401 0.028709966 0.01867052
## 8  0.019019658 0.011125738 0.009812360 0.010880232 0.011186253 0.01305661
## 14 0.004340056 0.003949212 0.002539163 0.002005376 0.007400791 0.00506103
phylum10$Grouped_Top10Phylum %>% head(10)  # Check grouped top taxa data frame
##    SampleID     Group Rep            tax rel_abundance
## 1   Sample1 Treatment   1 Proteobacteria     0.4440594
## 2   Sample2 Treatment   2 Proteobacteria     0.3380730
## 3   Sample3   Control   1 Proteobacteria     0.4877656
## 4   Sample4   Control   2 Proteobacteria     0.4106554
## 5   Sample5   Control   3 Proteobacteria     0.3716288
## 6   Sample6   Control   4 Proteobacteria     0.4402846
## 7   Sample7   Control   5 Proteobacteria     0.4628029
## 8   Sample8   Control   6 Proteobacteria     0.4883012
## 9   Sample9   Control   7 Proteobacteria     0.3850308
## 10 Sample10   Control   8 Proteobacteria     0.4752442
print(phylum10$filled_color)  # Check mapping colors
##             Proteobacteria              Acidobacteria 
##                  "#A6CEE3"                  "#2D82AF" 
##             Actinobacteria                Chloroflexi 
##                  "#98D277"                  "#6F9E4C" 
##           Gemmatimonadetes                 Firmicutes 
##                  "#F16667"                  "#F06C45" 
##            Verrucomicrobia                Nitrospirae 
##                  "#FE982C"                  "#D9A295" 
##              Bacteroidetes Candidatus Latescibacteria 
##                  "#7D54A5"                  "#F0EB99" 
##                     Others 
##                  "#B15928"

Continue with differential analysis