Chapter 4 Calculating differential abundance (DA) table
Differential abundance of the metabolite data will also be done using custom functions.
4.1 Getting vectors with samples per each treatment group
Samples from time T0 will be used as control to compare the samples from all other time points of the two treatments: Water pulse (WP) and control (CTR).
Sample information will be loaded from a .csv
table.
<- read_csv('data/metadata.csv') metadata
4.2 Generating table with differential abundances per feature
Using the function get_diff_table()
to calculate differential abundance between the different sample groups. This function will calculate the log2FoldChange (log2FC) for each feature as well as a p-value and adjusted p-value.
Because multiple comparisons are needed, nested for()
loops will be used
# Samples at T0
<- metadata %>%
control_samples filter(time == 'T0') %>%
pull(SampleID)
# Initializing a df to store the results
<- as.data.frame(matrix(nrow = 0, ncol = 7))
diff_table
for(treat in c('WP', 'CTR')){
for(t in c('T1', 'T2', 'T3', 'T4')){
<- metadata %>%
treatment_samples filter(treatment == treat,
== t) %>%
time pull(SampleID)
<- get_diff_table(norm_abundances,
temp_diff_table control.sample_list = control_samples,
treatment.sample_list = treatment_samples,
log2_transformed = TRUE) %>%
mutate(comparison = paste0('T0_vs_', treat, '_', t))
<- rbind(diff_table, temp_diff_table)
diff_table
} }