Skip to content

Commit 5975da9

Browse files
committedJan 3, 2024
Refactor code for generating taxa change heatmap
This commit refactors the code for generating a taxa change heatmap in R. The changes include: - Simplifying the code for selecting top features to plot. - Cleaning up the data transformation steps. - Calculating mean values for each combination of feature level, group variable, and time variable in a more efficient way. These changes improve the readability and maintainability of the code while preserving its functionality.
1 parent 66e6ed8 commit 5975da9

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed
 

‎R/generate_taxa_change_heatmap_long.R

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@
7474
#' generate_taxa_change_heatmap_long(
7575
#' data.obj = ecam.obj,
7676
#' subject.var = "studyid",
77-
#' time.var = "month_num",
78-
#' t0.level = NULL,
79-
#' ts.levels = NULL,
77+
#' time.var = "month",
78+
#' t0.level = unique(ecam.obj$meta.dat$month)[1],
79+
#' ts.levels = unique(ecam.obj$meta.dat$month)[-1],
8080
#' group.var = "antiexposedall",
8181
#' strata.var = "diet",
8282
#' feature.level = c("Family","Class"),
@@ -222,15 +222,8 @@ generate_taxa_change_heatmap_long <- function(data.obj,
222222
features.plot <- names(sort(computed_values, decreasing = TRUE)[1:top.k.plot])
223223
}
224224

225-
otu_tab_norm <-
226-
otu_tax_agg %>%
227-
column_to_rownames(var = feature.level) %>%
228-
as.matrix()
229-
230225
# Calculate the mean_value for each combination of feature.level, group.var, and time.var
231-
df_mean_value <- otu_tab_norm %>%
232-
as.data.frame() %>%
233-
rownames_to_column(var = feature.level) %>%
226+
df_mean_value <- otu_tax_agg %>%
234227
tidyr::gather(key = "sample", value = "value",-one_of(feature.level)) %>%
235228
dplyr::left_join(meta_tab %>%
236229
rownames_to_column("sample"), "sample") %>%

0 commit comments

Comments
 (0)