diff --git a/DESCRIPTION b/DESCRIPTION index 7481c347..88eec8d0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: pathfindR Type: Package Title: Enrichment Analysis Utilizing Active Subnetworks -Version: 1.5.0.9005 +Version: 1.5.0.9006 Authors@R: c(person("Ege", "Ulgen", role = "cre", email = "egeulgen@gmail.com", diff --git a/NEWS.md b/NEWS.md index 32c91306..3591ae1b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# pathfindR 1.5.0.9005 +# pathfindR 1.5.0.9006 ## to be released as 1.5.0 ## Major Changes diff --git a/R/visualization_functions.R b/R/visualization_functions.R index 0a1225ec..8a2d1a1f 100644 --- a/R/visualization_functions.R +++ b/R/visualization_functions.R @@ -1050,10 +1050,19 @@ term_gene_heatmap <- function(result_df, genes_df, num_terms = 10, which(colnames(result_df) == "Up_regulated")) down_genes <- apply(result_df, 1, parse_genes, which(colnames(result_df) == "Down_regulated")) + + if (length(down_genes) == 0) { + down_genes <- rep(NA, nrow(result_df)) + } + if (length(up_genes) == 0) { + up_genes <- rep(NA, nrow(result_df)) + } + names(up_genes) <- names(down_genes) <- result_df[, ID_column] ############ Create terms-by-genes matrix and order all_genes <- unique(c(unlist(up_genes), unlist(down_genes))) + all_genes <- all_genes[!is.na(all_genes)] all_terms <- result_df[, ID_column] term_genes_mat <- matrix(0, @@ -1063,6 +1072,7 @@ term_gene_heatmap <- function(result_df, genes_df, num_terms = 10, for (i in seq_len(nrow(term_genes_mat))) { current_term <- rownames(term_genes_mat)[i] current_genes <- c(up_genes[[current_term]], down_genes[[current_term]]) + current_genes <- current_genes[!is.na(current_genes)] term_genes_mat[i, match(current_genes, colnames(term_genes_mat))] <- 1 } diff --git a/tests/testthat/test-visualization_functions.R b/tests/testthat/test-visualization_functions.R index 8baaedbb..c505e063 100644 --- a/tests/testthat/test-visualization_functions.R +++ b/tests/testthat/test-visualization_functions.R @@ -374,6 +374,12 @@ test_that("`term_gene_heatmap()` produces a ggplot object using the correct data expect_is(p <- term_gene_heatmap(RA_output, num_terms = 3), "ggplot") expect_equal(length(unique(p$data$Enriched_Term)), 3) + # No genes in "Down_regulated" + res_df <- RA_output + res_df$Down_regulated <- "" + expect_is(p <- term_gene_heatmap(RA_output, num_terms = 3), "ggplot") + expect_equal(length(unique(p$data$Enriched_Term)), 3) + # All terms expect_is(p <- term_gene_heatmap(RA_output, num_terms = NULL), "ggplot") expect_equal(length(unique(p$data$Enriched_Term)), nrow(RA_output))