Skip to content

Commit

Permalink
Update ggpicrust2.R
Browse files Browse the repository at this point in the history
  • Loading branch information
cafferychen777 committed Nov 4, 2023
1 parent 2184a69 commit b4abba0
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions R/ggpicrust2.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@ ggpicrust2 <- function(file = NULL,
# Create an empty list
plot_result_list <- list()

cat("Starting the ggpicrust2 analysis...\n")
message("Starting the ggpicrust2 analysis...\n")

if (ko_to_kegg == TRUE){
cat("Converting KO to KEGG...\n")
message("Converting KO to KEGG...\n")
plot_result_list <- list()
abundance <- if (!is.null(file)) {
ko2kegg_abundance(file)
} else {
ko2kegg_abundance(data = data)
}
cat("Performing pathway differential abundance analysis...\n")
message("Performing pathway differential abundance analysis...\n")
daa_results_df <- pathway_daa(
abundance = abundance,
metadata = metadata,
Expand All @@ -142,11 +142,11 @@ ggpicrust2 <- function(file = NULL,
message(paste("Success: Found", num_significant_biomarkers, "statistically significant biomarker(s) in the dataset."))
}

cat("Annotating pathways...\n")
message("Annotating pathways...\n")
daa_results_df <-
pathway_annotation(daa_results_df = daa_results_df, ko_to_kegg = TRUE)
j <- 1
cat("Creating pathway error bar plots...\n")
message("Creating pathway error bar plots...\n")
for (i in unique(daa_results_df$method)) {
daa_sub_method_results_df <-
daa_results_df[daa_results_df[, "method"] == i, ]
Expand All @@ -167,13 +167,13 @@ ggpicrust2 <- function(file = NULL,
list(plot = combination_bar_plot, results = daa_sub_method_results_df)
# Add sublists to the main list
plot_result_list[[j]] <- sub_list
cat(sprintf("Plot %d created.\n", j))
message(sprintf("Plot %d created.\n", j))
j <- j + 1
}
cat("ggpicrust2 analysis completed.\n")
message("ggpicrust2 analysis completed.\n")
return(plot_result_list)
} else {
cat("Reading input file or using provided data...\n")
message("Reading input file or using provided data...\n")
plot_result_list <- list()
abundance <- if (!is.null(file)) {
readr::read_delim(
Expand All @@ -188,7 +188,7 @@ ggpicrust2 <- function(file = NULL,
abundance <- as.data.frame(abundance)
rownames(abundance) <- abundance[, 1]
abundance <- abundance[, -1]
cat("Performing pathway differential abundance analysis...\n")
message("Performing pathway differential abundance analysis...\n")
daa_results_df <- pathway_daa(
abundance = abundance,
metadata = metadata,
Expand All @@ -201,15 +201,15 @@ ggpicrust2 <- function(file = NULL,
if(daa_method == "Lefse") {
stop("The 'Lefse' method is not suitable for the ggpicrust2() function as Lefse in R does not output p-values, only effect sizes.")
}
cat("Annotating pathways...\n")
message("Annotating pathways...\n")
daa_results_df <-
pathway_annotation(
pathway = pathway,
ko_to_kegg = ko_to_kegg,
daa_results_df = daa_results_df
)
j <- 1
cat("Creating pathway error bar plots...\n")
message("Creating pathway error bar plots...\n")
for (i in unique(daa_results_df$method)) {
daa_sub_method_results_df <-
daa_results_df[daa_results_df[, "method"] == i, ]
Expand All @@ -230,10 +230,10 @@ ggpicrust2 <- function(file = NULL,
list(plot = combination_bar_plot, results = daa_sub_method_results_df)
# Add sublists to the main list
plot_result_list[[j]] <- sub_list
cat(sprintf("Plot %d created.\n", j))
message(sprintf("Plot %d created.\n", j))
j <- j + 1
}
cat("ggpicrust2 analysis completed.\n")
message("ggpicrust2 analysis completed.\n")
return(plot_result_list)
}

Expand Down

0 comments on commit b4abba0

Please sign in to comment.