genome_counts_filt <- genome_counts_filt %>%
column_to_rownames(var = "genome") %>%
select(any_of(c("genome",intersect(sample_metadata$Tube_code, colnames(read_counts))))) %>%
filter(rowSums(. != 0, na.rm = TRUE) > 0)%>%
select(where(~ sum(.) > 0)) %>%
rownames_to_column(., "genome")
genome_tree <- keep.tip(genome_tree, tip=genome_counts_filt$genome)
table <- genome_counts_filt %>%
t() %>%
row_to_names(row_number = 1) %>%
as.data.frame() %>%
mutate_if(is.character,as.numeric) %>%
rownames_to_column(., "sample")
master_table <- sample_metadata %>%
mutate(time_point = case_when(time_point %in% c("Transplant1") ~ "Inoculum1", TRUE ~ time_point)) %>%
mutate(time_point = case_when(time_point %in% c("Transplant2") ~ "Inoculum2", TRUE ~ time_point)) %>%
mutate(Population = case_when(Population %in% c("Cold_wet") ~ "Cold", TRUE ~ Population)) %>%
mutate(Population = case_when(Population %in% c("Hot_dry") ~ "Warm", TRUE ~ Population)) %>%
mutate(type = case_when(type %in% c("Hot_control") ~ "Warm_control", TRUE ~ type)) %>%
mutate(type = case_when(type %in% c("Control") ~ "Cold_control", TRUE ~ type)) %>%
mutate(type = case_when(type %in% c("Treatment") ~ "Cold_intervention", TRUE ~ type)) %>%
mutate(sample = Tube_code) %>%
mutate(Tube_code = str_remove_all(Tube_code, "_a")) %>%
filter(Tube_code %in% table$sample) %>%
# mutate(treatment = sub("^\\d+_", "", time_point)) %>%
left_join(., table, by = join_by("Tube_code" == "sample"))
sample_metadata <- master_table %>%
select(1,2,3,4:8,10,12)
genome_counts_filt <- master_table %>%
select(12,13:322) %>%
t() %>%
row_to_names(row_number = 1) %>%
as.data.frame() %>%
mutate_if(is.character,as.numeric) %>%
filter(rowSums(. != 0, na.rm = TRUE) > 0)%>%
dplyr::select(where(~ !all(. == 0)))%>%
rownames_to_column(., "genome")
genome_tree <- keep.tip(genome_tree, tip=genome_counts_filt$genome)
genome_metadata <- genome_metadata %>%
filter(genome %in% genome_counts_filt$genome)
Functional data
# 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)
elements <- GIFTs_elements_filtered %>%
as.data.frame()
# Aggregate element-level GIFTs into the function level
GIFTs_functions <- to.functions(GIFTs_elements_filtered, GIFT_db)
functions <- GIFTs_functions %>%
as.data.frame()
# Aggregate function-level GIFTs into overall Biosynthesis, Degradation and Structural GIFTs
GIFTs_domains <- to.domains(GIFTs_functions, GIFT_db)
domains <- GIFTs_domains %>%
as.data.frame()
# Get community-weighed average GIFTs per sample
GIFTs_elements_community <- to.community(GIFTs_elements_filtered, genome_counts_filt %>% column_to_rownames(., "genome") %>% tss(), GIFT_db)
GIFTs_functions_community <- to.community(GIFTs_functions, genome_counts_filt %>% column_to_rownames(., "genome") %>% tss(), GIFT_db)
GIFTs_domains_community <- to.community(GIFTs_domains, genome_counts_filt %>% column_to_rownames(., "genome") %>% tss(), GIFT_db)
uniqueGIFT_db <- unique(GIFT_db[c(2,3,4,5,6)]) %>% unite("Function",Function:Element, sep= "_", remove=FALSE)
element_gift <- GIFTs_elements_community %>%
as.data.frame() %>%
rownames_to_column(., "Tube_code") %>%
left_join(sample_metadata[c(1, 3, 7, 9)], by = "Tube_code")
save(sample_metadata,
genome_metadata,
genome_counts_filt,
genome_tree,
phylum_colors,
data_stats,
genome_gifts,
master_table,
physeq_all,
GIFTs_elements_filtered,
GIFTs_elements_community,
GIFTs_functions_community,
GIFTs_domains_community,
element_gift,
uniqueGIFT_db,
file = "data/objects_03122025.Rdata")