Browse code

Merge branch 'master' into heatmap_winsorized

# Conflicts:
# DESCRIPTION

Federico Marini authored on 06/10/2022 16:13:21
Showing 4 changed files

... ...
@@ -2,7 +2,7 @@ Package: GeneTonic
2 2
 Title: Enjoy Analyzing And Integrating The Results From Differential Expression 
3 3
     Analysis And Functional Enrichment Analysis
4 4
 Version: 2.1.4
5
-Date: 2022-09-21
5
+Date: 2022-10-05
6 6
 Authors@R: 
7 7
     c(
8 8
         person(
... ...
@@ -8,6 +8,7 @@
8 8
 
9 9
 * Fixed the behavior of the reactive elements after uploading the `GeneTonicList` object at runtime. 
10 10
 * Fixed the label namings for the `gs_heatmap` function
11
+* The `enhance_table()` function can handle the case where a gene is in the enrichment results table but not present in the annotation (e.g. annotations are updated, so some correspondences might get lost). It also presents an informative message on which genesets/genes are potentially responsible for the behavior. 
11 12
 
12 13
 # GeneTonic 2.0.0
13 14
 
... ...
@@ -94,18 +94,32 @@ enhance_table <- function(res_enrich,
94 94
     genes_thisset <- unlist(strsplit(genes_thisset, ","))
95 95
 
96 96
     genesid_thisset <- annotation_obj$gene_id[match(genes_thisset, annotation_obj$gene_name)]
97
-
98
-    res_thissubset <- res_de[genesid_thisset, ]
97
+    
98
+    # removing the genes not finding a match in the annotation
99
+    no_anno_match <- is.na(genesid_thisset)
100
+    genes_thisset_anno <- genes_thisset[!no_anno_match]
101
+    genesid_thisset_anno <- genesid_thisset[!no_anno_match]
102
+    # ... and informing on which genes might be troublesome
103
+    if (any(no_anno_match)) {
104
+      message("Could not find a match in the annotation for some genes. ",
105
+              "Please inspect your results in detail for geneset ",
106
+              gs,
107
+              " the gene(s) named: ",
108
+              paste0(genes_thisset[no_anno_match], collapse = ", "))
109
+    }
110
+    
111
+    res_thissubset <- res_de[genesid_thisset_anno, ]
99 112
 
100 113
     res_thissubset <- as.data.frame(res_thissubset)
101 114
 
102
-    res_thissubset$gene_name <- genes_thisset
115
+    res_thissubset$gene_name <- genes_thisset_anno
103 116
     res_thissubset$gs_desc <- as.factor(res_enrich[gs, "gs_description"])
104 117
     res_thissubset$gs_id <- res_enrich[gs, "gs_id"]
105 118
     # return(as.data.frame(res_thissubset))
106 119
     return(res_thissubset)
107 120
   })
108 121
   gs_fulllist <- do.call(rbind, gs_fulllist)
122
+  # message(dim(gs_fulllist)[1])
109 123
 
110 124
   this_contrast <- (sub(".*p-value: (.*)", "\\1", mcols(res_de, use.names = TRUE)["pvalue", "description"]))
111 125
 
... ...
@@ -28,14 +28,30 @@ test_that("Enhanced table is created", {
28 28
   with_scores <- get_aggrscores(gtl = gtl_macrophage)
29 29
   expect_is(with_scores, "data.frame")
30 30
 
31
-  p2 <- enhance_table(res_enrich_IFNg_vs_naive,
31
+  p2 <- enhance_table(with_scores,
32 32
     res_macrophage_IFNg_vs_naive,
33 33
     annotation_obj = anno_df,
34 34
     n_gs = 5,
35 35
     chars_limit = 60,
36
-    plot_title = "My custom title"
36
+    plot_title = "My custom title - with scores"
37 37
   )
38 38
   expect_is(p2, "gg")
39
+  
40
+  re_modified <- res_enrich_IFNg_vs_naive
41
+  # patching up some letters to mess up the name of a gene
42
+  re_modified$gs_genes[1] <- 
43
+    paste0(re_modified$gs_genes[1], "AAAAAAAA")
44
+  
45
+  expect_message({
46
+    p3 <- enhance_table(re_modified,
47
+                        res_macrophage_IFNg_vs_naive,
48
+                        annotation_obj = anno_df,
49
+                        n_gs = 5,
50
+                        chars_limit = 60,
51
+                        plot_title = "After modifying the genes assigned to gs1"
52
+    )
53
+  })
54
+  expect_is(p3, "gg")
39 55
 })
40 56
 
41 57
 test_that("The distillery is up and running", {