Clean up the environment

rm(list = ls())

Load required libraries for data reading, plotting, and data manipulation

library(readxl)       # For reading Excel files
library(ggpubr)       # For creating publication-ready plots
library(dplyr)        # For data manipulation
library(rstatix)      # For statistical analysis and adding significance markers
library(reshape2)     # For reshaping data between wide and long formats
library(knitr)        # For displaying tibbles in a nice table format
library(kableExtra)   # For enhancing table formatting

Load data

# Untargeted and targeted MS data
PP.untargeted.serum <- read_excel("Data/Data.xlsx", sheet = "PP_serum_untargetedMS")
PP.targeted.serum <- read_excel("Data/Data.xlsx", sheet = "PP_serum_MS")
# Pig info
PigInfo <- read_excel("Data/Data.xlsx", sheet = "PigInfo")

Data organization and create plots

# Create a plot for Total Essential Amino Acids (EAA)
Fig.EAA <- PP.untargeted.serum %>% inner_join(PigInfo, by = "PigID") %>%
            mutate(EAA = histidine + isoleucine + leucine + lysine + methionine + phenylalanine + threonine + tryptophan + valine) %>%
            mutate(TimePoint = factor(TimePoint, levels = c("baseline", "30 min", "60 min", "120 min"))) %>%
            mutate(Diet = factor(Diet, levels = c("ALAC", "WPI"))) %>%
            ggerrorplot(x = "TimePoint", y = "EAA", color = "Diet", ylab = "Total EAA (normalized intensity)", xlab = "", add = "mean", error.plot = "errorbar", size = 0.8, position = position_dodge(0.3), palette = c("turquoise3","purple")) + yscale("scientific")
# Create a plot for Tryptophan to other Large Neutral Amino Acid ratio (Trp:LNAA)
# LNAA calculated at the sum of valine, isoleucine, leucine, phenylalanine, and tyrosine.
Fig.Trp_to_LNAA <- PP.untargeted.serum %>% inner_join(PigInfo, by = "PigID") %>%
            mutate(Trp_to_LNAA = tryptophan / (valine + isoleucine + leucine + phenylalanine + tyrosine)) %>%
            mutate(TimePoint = factor(TimePoint, levels = c("baseline", "30 min", "60 min", "120 min"))) %>%
            mutate(Diet = factor(Diet, levels = c("ALAC", "WPI"))) %>%
            ggerrorplot(x = "TimePoint", y = "Trp_to_LNAA", color = "Diet", ylab = "Tryptophan:LNAA", xlab = "", add = "mean", error.plot = "errorbar", size = 0.8, position = position_dodge(0.3), palette = c("turquoise3","purple"))
# Create a plot for Tryptophan concentration
Fig.Trp <- PP.targeted.serum %>% inner_join(PigInfo, by = "PigID") %>%
            mutate(TimePoint = factor(TimePoint, levels = c("baseline", "30 min", "60 min", "120 min"))) %>%
            mutate(Diet = factor(Diet, levels = c("ALAC", "WPI"))) %>%
            ggerrorplot(x = "TimePoint", y = "Tryptophan", color = "Diet", ylab = "Tryptophan (uM)", xlab = "", add = "mean", error.plot = "errorbar", size = 0.8, position = position_dodge(0.3), palette = c("turquoise3","purple"))
# Create a plot for Kynurenine concentration
Fig.Kyn <- PP.targeted.serum %>% inner_join(PigInfo, by = "PigID") %>%
            mutate(TimePoint = factor(TimePoint, levels = c("baseline", "30 min", "60 min", "120 min"))) %>%
            mutate(Diet = factor(Diet, levels = c("ALAC", "WPI"))) %>%
            ggerrorplot(x = "TimePoint", y = "Kynurenine", color = "Diet", ylab = "Kynurenine (uM)", xlab = "", add = "mean", error.plot = "errorbar", size = 0.8, position = position_dodge(0.3), palette = c("turquoise3","purple"))
# Create a plot for Serotonin concentration
Fig.Sere <- PP.targeted.serum %>% inner_join(PigInfo, by = "PigID") %>%
            mutate(TimePoint = factor(TimePoint, levels = c("baseline", "30 min", "60 min", "120 min"))) %>%
            mutate(Diet = factor(Diet, levels = c("ALAC", "WPI"))) %>%
            ggerrorplot(x = "TimePoint", y = "Serotonin", color = "Diet", ylab = "Serotonin (uM)", xlab = "", add = "mean", error.plot = "errorbar", size = 0.8, position = position_dodge(0.3), palette = c("turquoise3","purple"))
# Arrange all the individual plots into a single figure
Fig.all <- ggarrange(Fig.EAA,Fig.Trp_to_LNAA, Fig.Trp, Fig.Kyn, Fig.Sere, nrow = 2, ncol = 3, common.legend = TRUE)

# save the figure to a pdf file:
ggsave(plot=Fig.all, height=7.5, width=11, dpi=300, filename="Figure 2/Fig2A-E.pdf", useDingbats=FALSE)

Fig.all

Group difference evaluation

#This function transforms the input values by the generalized #log function.
glog <- function(y) {
  #Using lambda = 1 
  yt <- log(y+sqrt(y^2+1))
  return(yt)
}

Total EAA

# Perform ANOVA for Total EAA
PP.untargeted.serum %>% 
    inner_join(PigInfo, by = "PigID") %>%
    mutate(EAA = histidine + isoleucine + leucine + lysine + methionine + phenylalanine + threonine + tryptophan + valine) %>% # Calculate total EAA
    mutate(glog.EAA = glog(EAA)) %>% # apply glog transformation
    select(SowID, glog.EAA, Diet, TimePoint) %>%
    group_by(TimePoint) %>%
    anova_test(glog.EAA ~ Diet + SowID, type = 1) %>%
    as_tibble() %>%
    filter(Effect == "Diet") %>% # Select relevant columns for reporting
    kable() %>% # Print the tibble in a nice table format
    kable_styling(bootstrap_options = c("striped", "hover")) # Enhance table formatting
TimePoint Effect DFn DFd F p p<.05 ges
120 min Diet 1 11 0.033 0.860 3.0e-03
30 min Diet 1 13 0.188 0.672 1.4e-02
60 min Diet 1 16 0.001 0.974 6.7e-05
baseline Diet 1 16 1.504 0.238 8.6e-02

Tryptophan:LNAA

# Perform ANOVA for Tryptophan:LNAA ratio
PP.untargeted.serum %>% 
    inner_join(PigInfo, by = "PigID") %>%
    mutate(Trp_to_LNAA = tryptophan / (valine + isoleucine + leucine + phenylalanine + tyrosine)) %>% # Calculate Trp to LNAA ratio
    mutate(glog.Trp_to_LNAA = glog(Trp_to_LNAA * 100)) %>% # Scale values by 100 and apply glog transformation
    select(SowID, glog.Trp_to_LNAA, Diet, TimePoint) %>%
    group_by(TimePoint) %>%
    anova_test(glog.Trp_to_LNAA ~ Diet + SowID, type = 1) %>%
    as_tibble() %>%
    filter(Effect == "Diet") %>% # Select relevant columns for reporting
    kable() %>% # Print the tibble in a nice table format
    kable_styling(bootstrap_options = c("striped", "hover")) # Enhance table formatting
TimePoint Effect DFn DFd F p p<.05 ges
120 min Diet 1 11 9.278 1.10e-02
0.458
30 min Diet 1 13 10.147 7.00e-03
0.438
60 min Diet 1 16 28.115 7.15e-05
0.637
baseline Diet 1 16 24.586 1.42e-04
0.606

Results from targeted metabolomics data (Tryptophan, Kynurenine,Serotonin)

# Perform ANOVA for targeted metabolomics data
PP.targeted.serum %>% 
    select(Tryptophan, Kynurenine, Serotonin) %>%
    mutate(across(everything(), ~ glog(.x * 10))) %>% # Scale values by 10 and apply generalized log 
    mutate(TimePoint = PP.targeted.serum$TimePoint) %>%
    mutate(PigID = PP.targeted.serum$PigID) %>%
    inner_join(PigInfo, by = "PigID") %>%
    select(Tryptophan, Kynurenine, Serotonin, Diet, TimePoint, SowID) %>%
    melt(id = c("TimePoint", "SowID", "Diet")) %>%
    group_by(TimePoint, variable) %>%
    anova_test(value ~ Diet + SowID, type = 1) %>%
    as_tibble() %>%
    filter(Effect == "Diet") %>%
    add_significance(p.col = "p", cutpoints = c(0, 0.05, 0.1, 1), symbols = c("*", "#", "ns")) %>%
    filter(p.signif != "ns") %>%
    select(TimePoint, variable, p, p.signif) %>% # Select relevant columns for reporting
    kable() %>% # Print the tibble in a nice table format
    kable_styling(bootstrap_options = c("striped", "hover")) # Enhance table formatting
TimePoint variable p p.signif
120 min Tryptophan 0.000253
30 min Tryptophan 0.020000
30 min Kynurenine 0.005000
60 min Tryptophan 0.000181
60 min Kynurenine 0.035000
baseline Tryptophan 0.005000
baseline Kynurenine 0.045000
sessionInfo()
## R version 4.2.2 (2022-10-31)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Big Sur ... 10.16
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] kableExtra_1.3.4 knitr_1.45       reshape2_1.4.4   rstatix_0.7.2   
## [5] dplyr_1.1.3      ggpubr_0.6.0     ggplot2_3.5.1    readxl_1.4.3    
## 
## loaded via a namespace (and not attached):
##  [1] tidyselect_1.2.0  xfun_0.40         bslib_0.5.1       purrr_1.0.2      
##  [5] carData_3.0-5     colorspace_2.1-0  vctrs_0.6.5       generics_0.1.3   
##  [9] viridisLite_0.4.2 htmltools_0.5.6.1 yaml_2.3.7        utf8_1.2.4       
## [13] rlang_1.1.2       jquerylib_0.1.4   pillar_1.9.0      glue_1.6.2       
## [17] withr_3.0.1       lifecycle_1.0.4   plyr_1.8.9        stringr_1.5.1    
## [21] munsell_0.5.1     ggsignif_0.6.4    gtable_0.3.5      cellranger_1.1.0 
## [25] ragg_1.2.6        rvest_1.0.3       evaluate_1.0.1    labeling_0.4.3   
## [29] fastmap_1.1.1     fansi_1.0.6       highr_0.10        broom_1.0.5      
## [33] Rcpp_1.0.11       scales_1.3.0      backports_1.4.1   cachem_1.0.8     
## [37] webshot_0.5.5     jsonlite_1.8.8    abind_1.4-5       farver_2.1.1     
## [41] systemfonts_1.0.5 textshaping_0.3.7 gridExtra_2.3     digest_0.6.33    
## [45] stringi_1.7.12    cowplot_1.1.1     grid_4.2.2        cli_3.6.2        
## [49] tools_4.2.2       magrittr_2.0.3    sass_0.4.7        tibble_3.2.1     
## [53] tidyr_1.3.0       car_3.1-2         pkgconfig_2.0.3   xml2_1.3.5       
## [57] svglite_2.1.2     rmarkdown_2.28    httr_1.4.7        rstudioapi_0.15.0
## [61] R6_2.5.1          compiler_4.2.2