Browse code

more robust content in geneinfo_2_html

Federico Marini authored on 12/02/2020 19:41:05
Showing 1 changed files

... ...
@@ -114,11 +114,19 @@ geneinfo_2_html <- function(gene_id,
114 114
   gene_genecards_button <- .link2genecards(gene_id)
115 115
 
116 116
   if (!is.null(res_de)) {
117
-    gene_adjpvalue <- format(res_de[match(gene_id, res_de$SYMBOL), "padj"])
118
-    gene_logfc <- format(round(res_de[match(gene_id, res_de$SYMBOL), "log2FoldChange"], 2), nsmall = 2)
117
+    gid <- match(gene_id, res_de$SYMBOL)
118
+    if (is.na(gid)) {
119
+      message("Could not find the specified gene (`", gene_id,  
120
+              "`) in the `res_de` object. \n",
121
+              "Still, the general HTML content has been generated.")
122
+      gene_adjpvalue <- tags$em("not found")
123
+      gene_logfc <- tags$em("not found")
124
+    } else {
125
+      gene_adjpvalue <- format(res_de[gid, "padj"])
126
+      gene_logfc <- format(round(res_de[gid, "log2FoldChange"], 2), nsmall = 2)
127
+    }
119 128
   }
120 129
 
121
-
122 130
   mycontent <- paste0(
123 131
     tags$b(gene_id), tags$br(),
124 132
     "Link to the NCBI Gene database: ", gene_ncbi_button, tags$br(),