Chapter 10 Functional differences

set.seed(1234) 
load("data/data_filtered.Rdata")
genome_counts_filt <- genome_counts_filt[genome_counts_filt$genome %in% rownames(genome_gifts),]
genome_counts_filt <- genome_counts_filt %>%
    select(genome, all_of(sample_metadata$sample)) %>%
  column_to_rownames(., "genome") %>%
  filter(rowSums(. != 0, na.rm = TRUE) > 0) %>%
  select_if(~!all(. == 0))%>%
  rownames_to_column(., "genome")

genome_gifts <- genome_gifts[rownames(genome_gifts) %in% genome_counts_filt$genome,]
genome_gifts <- genome_gifts[, colSums(genome_gifts != 0) > 0]

#Aggregate bundle-level GIFTs into the compound level
GIFTs_elements <- to.elements(genome_gifts,GIFT_db)
GIFTs_elements_filtered <- GIFTs_elements[rownames(GIFTs_elements) %in% genome_counts_filt$genome,]
GIFTs_elements_filtered <- as.data.frame(GIFTs_elements_filtered) %>% 
  select_if(~ !is.numeric(.) || sum(.) != 0)

#Aggregate element-level GIFTs into the function level
GIFTs_functions <- to.functions(GIFTs_elements_filtered,GIFT_db)

#Aggregate function-level GIFTs into overall Biosynthesis, Degradation and Structural GIFTs
GIFTs_domains <- to.domains(GIFTs_functions,GIFT_db)

#Get community-weighed average GIFTs per sample
genome_counts_row <- genome_counts_filt %>%
  mutate_at(vars(-genome),~./sum(.)) %>% 
  column_to_rownames(., "genome") 
GIFTs_elements_community <- to.community(GIFTs_elements_filtered,genome_counts_row,GIFT_db)
GIFTs_functions_community <- to.community(GIFTs_functions,genome_counts_row,GIFT_db)
GIFTs_domains_community <- to.community(GIFTs_domains,genome_counts_row,GIFT_db)

10.1 Bd_status

GIFTs_functions_community %>%
  rowMeans() %>%
  as_tibble(., rownames = "sample") %>%
  left_join(sample_metadata, by = join_by(sample == sample)) %>%
  group_by(Bd_status) %>%
  summarise(MCI = mean(value), sd = sd(value)) %>%
  tt()
Bd_status MCI sd
Bd_negative 0.3219424 0.07763271
Bd_positive 0.3231682 0.07291823
element_gift <- GIFTs_elements_community %>% 
  as.data.frame() %>% 
  rownames_to_column(., "sample") %>% 
  left_join(sample_metadata %>% select(sample,Bd_status), by="sample")

uniqueGIFT_db<- unique(GIFT_db[c(2,4,5,6)]) %>% unite("Function",Function:Element, sep= "_", remove=FALSE)

element_gift %>%
    pivot_longer(-c(sample,Bd_status), names_to = "trait", values_to = "value") %>%
    group_by(trait) %>%
    summarise(p_value = wilcox.test(value ~ Bd_status)$p.value) %>%
    mutate(p_adjust=p.adjust(p_value, method="BH")) %>%
    filter(p_adjust < 0.05)
# A tibble: 0 × 3
# ℹ 3 variables: trait <chr>, p_value <dbl>, p_adjust <dbl>

10.2 region

GIFTs_functions_community %>%
  rowMeans() %>%
  as_tibble(., rownames = "sample") %>%
  left_join(sample_metadata, by = join_by(sample == sample)) %>%
  group_by(region) %>%
  summarise(MCI = mean(value), sd = sd(value)) %>%
  tt()
region MCI sd
Matra mountains 0.3089298 0.07701910
None 0.3742051 0.03806951
element_gift <- GIFTs_elements_community %>% 
  as.data.frame() %>% 
  rownames_to_column(., "sample") %>% 
  left_join(sample_metadata %>% select(sample,region), by="sample")

uniqueGIFT_db<- unique(GIFT_db[c(2,4,5,6)]) %>% unite("Function",Function:Element, sep= "_", remove=FALSE)

element_gift %>%
  pivot_longer(-c(sample,region), names_to = "trait", values_to = "value") %>%
  group_by(trait) %>%
  summarise(p_value = wilcox.test(value ~ region)$p.value) %>%
  mutate(p_adjust=p.adjust(p_value, method="BH")) %>%
  filter(p_adjust < 0.05) %>% 
  left_join(uniqueGIFT_db, by=join_by("trait"=="Code_element")) %>% 
  tt()
trait p_value p_adjust Domain Function Element
B0102 1.607509e-04 2.459489e-03 Biosynthesis Nucleic acid biosynthesis_Uridylic acid (UMP) Uridylic acid (UMP)
B0103 2.368841e-03 1.510136e-02 Biosynthesis Nucleic acid biosynthesis_UDP/UTP UDP/UTP
B0105 7.615693e-03 2.841954e-02 Biosynthesis Nucleic acid biosynthesis_ADP/ATP ADP/ATP
B0208 4.078490e-03 1.890936e-02 Biosynthesis Amino acid biosynthesis_Valine Valine
B0209 1.501505e-02 4.176913e-02 Biosynthesis Amino acid biosynthesis_Isoleucine Isoleucine
B0210 1.501505e-02 4.176913e-02 Biosynthesis Amino acid biosynthesis_Leucine Leucine
B0213 3.574002e-03 1.763943e-02 Biosynthesis Amino acid biosynthesis_Proline Proline
B0215 4.642370e-03 1.973007e-02 Biosynthesis Amino acid biosynthesis_Histidine Histidine
B0216 1.308763e-04 2.224897e-03 Biosynthesis Amino acid biosynthesis_Tryptophan Tryptophan
B0217 1.531441e-03 1.115764e-02 Biosynthesis Amino acid biosynthesis_Phenylalanine Phenylalanine
B0218 2.383470e-04 2.853772e-03 Biosynthesis Amino acid biosynthesis_Tyrosine Tyrosine
B0220 1.853853e-02 4.807450e-02 Biosynthesis Amino acid biosynthesis_Beta-alanine Beta-alanine
B0221 9.635304e-04 7.371007e-03 Biosynthesis Amino acid biosynthesis_Ornithine Ornithine
B0302 1.501505e-02 4.176913e-02 Biosynthesis Amino acid derivative biosynthesis_Betaine Betaine
B0704 3.465329e-04 3.787109e-03 Biosynthesis Vitamin biosynthesis_Pantothenate (B5) Pantothenate (B5)
B0706 4.949633e-04 4.733087e-03 Biosynthesis Vitamin biosynthesis_Biotin (B7) Biotin (B7)
B0707 6.956988e-04 5.602206e-03 Biosynthesis Vitamin biosynthesis_Tetrahydrofolate (B9) Tetrahydrofolate (B9)
B0708 1.669973e-02 4.482559e-02 Biosynthesis Vitamin biosynthesis_Cobalamin (B12) Cobalamin (B12)
B0709 1.325761e-02 4.042673e-02 Biosynthesis Vitamin biosynthesis_Tocopherol/tocotorienol (E) Tocopherol/tocotorienol (E)
B0801 2.082392e-03 1.385244e-02 Biosynthesis Aromatic compound biosynthesis_Salicylate Salicylate
B0802 3.124387e-03 1.648383e-02 Biosynthesis Aromatic compound biosynthesis_Gallate Gallate
B1004 3.120746e-06 1.591581e-04 Biosynthesis Antibiotic biosynthesis_Bacilysin Bacilysin
B1028 2.275544e-07 2.582133e-05 Biosynthesis Antibiotic biosynthesis_Pyocyanin Pyocyanin
D0102 1.347558e-02 4.042673e-02 Degradation Lipid degradation_Fatty acid Fatty acid
D0103 5.878380e-04 5.290542e-03 Degradation Lipid degradation_Oleate Oleate
D0104 4.642370e-03 1.973007e-02 Degradation Lipid degradation_Dicarboxylic acids Dicarboxylic acids
D0202 3.574002e-03 1.763943e-02 Degradation Polysaccharide degradation_Xyloglucan Xyloglucan
D0203 1.501505e-02 4.176913e-02 Degradation Polysaccharide degradation_Starch Starch
D0206 1.776355e-03 1.235374e-02 Degradation Polysaccharide degradation_Alpha galactan Alpha galactan
D0207 3.332047e-05 7.282902e-04 Degradation Polysaccharide degradation_Beta-galactan Beta-galactan
D0208 4.078490e-03 1.890936e-02 Degradation Polysaccharide degradation_Mixed-Linkage glucans Mixed-Linkage glucans
D0210 3.124387e-03 1.648383e-02 Degradation Polysaccharide degradation_Beta-mannan Beta-mannan
D0211 8.571779e-03 3.122577e-02 Degradation Polysaccharide degradation_Alpha-mannan Alpha-mannan
D0213 3.124387e-03 1.648383e-02 Degradation Polysaccharide degradation_Mucin Mucin
D0302 2.723956e-03 1.602944e-02 Degradation Sugar degradation_Sucrose Sucrose
D0305 2.584368e-05 6.590138e-04 Degradation Sugar degradation_D-Mannose D-Mannose
D0310 5.412544e-05 1.035149e-03 Degradation Sugar degradation_NeuAc NeuAc
D0505 6.752157e-03 2.792108e-02 Degradation Amino acid degradation_Valine Valine
D0506 1.961844e-04 2.728747e-03 Degradation Amino acid degradation_Isoleucine Isoleucine
D0507 7.615693e-03 2.841954e-02 Degradation Amino acid degradation_Leucine Leucine
D0508 2.723956e-03 1.602944e-02 Degradation Amino acid degradation_Lysine Lysine
D0513 7.615693e-03 2.841954e-02 Degradation Amino acid degradation_Tryptophan Tryptophan
D0517 1.684932e-05 5.155893e-04 Degradation Amino acid degradation_Ornithine Ornithine
D0518 9.627079e-03 3.273207e-02 Degradation Amino acid degradation_GABA GABA
D0604 1.079076e-02 3.512737e-02 Degradation Nitrogen compound degradation_GlcNAc GlcNAc
D0606 9.493061e-03 3.273207e-02 Degradation Nitrogen compound degradation_Allantoin Allantoin
D0611 1.823517e-02 4.807450e-02 Degradation Nitrogen compound degradation_Phenylethylamine Phenylethylamine
D0702 1.207020e-02 3.768859e-02 Degradation Alcohol degradation_Ethanol Ethanol
D0706 3.375338e-07 2.582133e-05 Degradation Alcohol degradation_Ethylene glycol Ethylene glycol
D0801 7.615693e-03 2.841954e-02 Degradation Xenobiotic degradation_Toluene Toluene
D0802 1.669973e-02 4.482559e-02 Degradation Xenobiotic degradation_Xylene Xylene
D0816 4.949633e-04 4.733087e-03 Degradation Xenobiotic degradation_Phenylacetate Phenylacetate
D0819 1.605023e-05 5.155893e-04 Degradation Xenobiotic degradation_Mercury Mercury
D0904 9.558810e-03 3.273207e-02 Degradation Antibiotic degradation_Oxacillin Oxacillin
D0907 1.079076e-02 3.512737e-02 Degradation Antibiotic degradation_Tetracycline Tetracycline
D0908 4.580016e-03 1.973007e-02 Degradation Antibiotic degradation_Macrolide Macrolide
D0910 2.424774e-04 2.853772e-03 Degradation Antibiotic degradation_Chloramphenicol Chloramphenicol
S0101 6.956988e-04 5.602206e-03 Structure Cellular structure_Peptidoglycan Peptidoglycan
S0105 1.207020e-02 3.768859e-02 Structure Cellular structure_Lipopolysaccharide Lipopolysaccharide