<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>

CC BY-SA 4.0
2020-11-09T10:47:40.690Z
Yes I know the package. My problem is to use it in the format of gprofiler file. How could I  isolate each ensemble ID and replace it with a gene name, when ensembl ids are in one cell of a column of dataframe?THANKS!
marilu
CC BY-SA 4.0
2020-11-09T11:28:11.020Z
I added an example of how you can use this in a `data.frame`.
Bastian Schiffthaler
CC BY-SA 4.0
2020-11-09T12:03:39.487Z
Thnak you so much!!!
marilu
CC BY-SA 4.0
2020-11-09T09:34:06.813Z
2020-11-09T11:27:33.687Z
2020-11-09T11:27:33.687Z
Bastian Schiffthaler
<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.sstatic.net/1h2UP.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/1h2UP.png" alt="enter image description here" /></a></p>

<gene-ontology>
gprofiler output ENSG to gene name
# gprofiler output ENSG to gene name

(Asked by: username_0 on 2020-11-09)

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:
[![enter image description here](https://i.sstatic.net/1h2UP.png)](https://i.sstatic.net/1h2UP.png)

**Tags:** gene-ontology

---

## 1 answers

### Answer by username_1 on 2020-11-09. Score: 1 | Accepted answer

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      
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      
16 ENSG00000213440      
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.

> **Comments:**
> **username_0**: Yes I know the package. My problem is to use it in the format of gprofiler file. How could I  isolate each ensemble ID and replace it with a gene name, when ensembl ids are in one cell of a column of dataframe?THANKS!  
> **username_1**: I added an example of how you can use this in a `data.frame`.  
> **username_0**: Thnak you so much!!!  

---

