text: user8713: I would like to ask if there is any tool or R script that translates Ensembl IDs to gene names in a gprofiler GO output. An example of this file is the following one:
  
  
  user9693: This is usually done using AnnotationDbi in combination with the annotation database for human org.Hs.eg.db.
  library(org.Hs.eg.db)
  genes <- c("ENSG00000102055", "ENSG00000232605", "ENSG00000136828",
             "ENSG00000159197", "ENSG00000201394", "ENSG00000278580",
             "ENSG00000213440", "ENSG00000166816", "ENSG00000275895",
             "ENSG00000105723")
  select(org.Hs.eg.db, genes, c("ENSEMBL", "ALIAS"), "ENSEMBL")
  
  This returns:
             ENSEMBL     ALIAS
  1  ENSG00000102055       I-4
  2  ENSG00000102055  PPP1R2P9
  3  ENSG00000102055   PPP1R2C
  4  ENSG00000232605      <NA>
  5  ENSG00000136828   RALGEF2
  6  ENSG00000136828  RALGPS1A
  7  ENSG00000136828   RALGPS1
  8  ENSG00000159197     ATFB4
  9  ENSG00000159197      LQT5
  10 ENSG00000159197      LQT6
  11 ENSG00000159197     MIRP1
  12 ENSG00000159197     KCNE2
  13 ENSG00000201394   RN5S140
  14 ENSG00000201394 RNA5SP140
  15 ENSG00000278580      <NA>
  16 ENSG00000213440      <NA>
  17 ENSG00000166816     DLACD
  18 ENSG00000166816       DLD
  19 ENSG00000166816      LDHD
  20 ENSG00000275895   U2AF1L5
  21 ENSG00000105723     GSK3A
  
  If you want to apply a 1:1 mapping of gene IDs to common names, you can use the "SYMBOL" column. In a data.frame, you can do something like this:
  ensembl_to_symbol <- function(e) {
    hits <- select(org.Hs.eg.db, e, "SYMBOL", "ENSEMBL")$SYMBOL
    # Gene IDs without symbols should just stay as IDs
    no_hit <- is.na(hits)
    hits[no_hit] <- e[no_hit]
    hits
  }
  
  recode_symbols <- function(s) {
    e <- ensembl_to_symbol(unlist(strsplit(s, split = ",")))
    paste(e, collapse = ",")
  }
  
  df <- data.frame(
    genes = c(paste(genes[1:5], collapse = ","),
              paste(genes[6:10], collapse = ",")
    )
  )
  
  df$genes <- sapply(df$genes, recode_symbols)
  
  This isn't the most vectorized (fast) solution, but it's probably easier to understand this way.
  
original_text: 8713: <p>I would like to ask if there is any tool or R script that translates Ensembl IDs to gene names in a gprofiler GO output. An example of this file is the following one:
  <a href="https://i.stack.imgur.com/1h2UP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1h2UP.png" alt="enter image description here" /></a></p>
   9693: <p>This is usually done using <a href="https://www.bioconductor.org/packages/release/bioc/html/AnnotationDbi.html" rel="nofollow noreferrer">AnnotationDbi</a> in combination with the annotation database for human <a href="https://bioconductor.org/packages/release/data/annotation/html/org.Hs.eg.db.html" rel="nofollow noreferrer">org.Hs.eg.db</a>.</p>
  <pre class="lang-r prettyprint-override"><code>library(org.Hs.eg.db)
  genes &lt;- c(&quot;ENSG00000102055&quot;, &quot;ENSG00000232605&quot;, &quot;ENSG00000136828&quot;,
             &quot;ENSG00000159197&quot;, &quot;ENSG00000201394&quot;, &quot;ENSG00000278580&quot;,
             &quot;ENSG00000213440&quot;, &quot;ENSG00000166816&quot;, &quot;ENSG00000275895&quot;,
             &quot;ENSG00000105723&quot;)
  select(org.Hs.eg.db, genes, c(&quot;ENSEMBL&quot;, &quot;ALIAS&quot;), &quot;ENSEMBL&quot;)
  </code></pre>
  <p>This returns:</p>
  <pre><code>           ENSEMBL     ALIAS
  1  ENSG00000102055       I-4
  2  ENSG00000102055  PPP1R2P9
  3  ENSG00000102055   PPP1R2C
  4  ENSG00000232605      &lt;NA&gt;
  5  ENSG00000136828   RALGEF2
  6  ENSG00000136828  RALGPS1A
  7  ENSG00000136828   RALGPS1
  8  ENSG00000159197     ATFB4
  9  ENSG00000159197      LQT5
  10 ENSG00000159197      LQT6
  11 ENSG00000159197     MIRP1
  12 ENSG00000159197     KCNE2
  13 ENSG00000201394   RN5S140
  14 ENSG00000201394 RNA5SP140
  15 ENSG00000278580      &lt;NA&gt;
  16 ENSG00000213440      &lt;NA&gt;
  17 ENSG00000166816     DLACD
  18 ENSG00000166816       DLD
  19 ENSG00000166816      LDHD
  20 ENSG00000275895   U2AF1L5
  21 ENSG00000105723     GSK3A
  </code></pre>
  <p>If you want to apply a 1:1 mapping of gene IDs to common names, you can use the &quot;SYMBOL&quot; column. In a <code>data.frame</code>, you can do something like this:</p>
  <pre class="lang-r prettyprint-override"><code>ensembl_to_symbol &lt;- function(e) {
    hits &lt;- select(org.Hs.eg.db, e, &quot;SYMBOL&quot;, &quot;ENSEMBL&quot;)$SYMBOL
    # Gene IDs without symbols should just stay as IDs
    no_hit &lt;- is.na(hits)
    hits[no_hit] &lt;- e[no_hit]
    hits
  }
  
  recode_symbols &lt;- function(s) {
    e &lt;- ensembl_to_symbol(unlist(strsplit(s, split = &quot;,&quot;)))
    paste(e, collapse = &quot;,&quot;)
  }
  
  df &lt;- data.frame(
    genes = c(paste(genes[1:5], collapse = &quot;,&quot;),
              paste(genes[6:10], collapse = &quot;,&quot;)
    )
  )
  
  df<span class="math-container">$genes &lt;- sapply(df$</span>genes, recode_symbols)
  </code></pre>
  <p>This isn't the most vectorized (fast) solution, but it's probably easier to understand this way.</p>
  