Skip to content

Commit

Permalink
fixes #39
Browse files Browse the repository at this point in the history
  • Loading branch information
egeulgen committed Apr 23, 2020
1 parent 2575c7d commit 35cdc27
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pathfindR 1.5.0.9005
# pathfindR 1.5.0.9006
## to be released as 1.5.0

## Major Changes
Expand Down
10 changes: 10 additions & 0 deletions R/visualization_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-visualization_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 35cdc27

Please sign in to comment.