Question: R org.Hs.eg.db matching ensembl gene ids with gene symbol
1
gravatar for User6891
3.7 years ago by
User6891250
Europe
User6891250 wrote:

Hi,

I want to add a column with the gene symbol corresponding to the Ensembl Gene ID to a dataframe in R

resOrdered$symbol <- mapIds(org.Hs.eg.db,
                     keys=row.names(resOrdered),
                     column="SYMBOL",
                     keytype="ENSEMBL",
                     multiVals="first")

I'm using org.Hs.eg.db from BioConductor for this.

I get the following error:

Error in .testForValidKeys(x, keys, keytype, fks) : 
  None of the keys entered are valid keys for 'ENSEMBL'. Please use the keys method to see a listing of valid arguments.

I think this is because my row.names from my dataframe resOrdered look like this:

[9997] "ENSG00000100601.5"  "ENSG00000178826.6"  "ENSG00000243663.1"  "ENSG00000138231.8"

I think the problem is that there are ., that signify the version, after the actual ENGS. Is there a way to still find a match with the ENSEMBL key from org.Hs.eg.db?

bioconductor R • 11k views
ADD COMMENTlink modified 14 months ago by RamRS24k • written 3.7 years ago by User6891250
3

Otherwise, you can always remove the string after the period.

tmp=gsub("\\..*","",row.names(resOrdered)​)
ADD REPLYlink modified 14 months ago by RamRS24k • written 3.7 years ago by Sukhdeep Singh9.9k

hello Sukhdeep,

I have exactly the same question as User6891 and after i try to remove the decimal i get an error.

Error: unexpected input in "tmp=gsub("\\..*","",row.names(res)�"

Could you please help me with this?

ADD REPLYlink modified 14 months ago by RamRS24k • written 3.5 years ago by saamar.rajput50
1

Command should work, I see you have some unidentified symbol in the command you pasted.

Try to write it and see if it works!

ADD REPLYlink modified 14 months ago by RamRS24k • written 3.5 years ago by Sukhdeep Singh9.9k
tmp=gsub("\\..*","",row.names(res)​)

this is my command ...and it shows a question mark in the error.

Error: unexpected input in "tmp=gsub("\\..*","",row.names(res)�"
ADD REPLYlink modified 14 months ago by RamRS24k • written 3.5 years ago by saamar.rajput50

As I said, the above command should work, unless you have a copy-paste error, or the object res has some issue. Check row.names(res), what does it outputs!

ADD REPLYlink written 3.5 years ago by Sukhdeep Singh9.9k

Its working thanks alot :) and thanks for your patience.

But 1 more question how do i put the edited ENSEMBL id from tmp back to my res column?

I know it is a very basic question but I am new to R.

ADD REPLYlink modified 14 months ago by RamRS24k • written 3.5 years ago by saamar.rajput50

Thanks alot Sukhdeep ...it all worked fine :)

ADD REPLYlink written 3.5 years ago by saamar.rajput50

Great, good luck then!

ADD REPLYlink written 3.5 years ago by Sukhdeep Singh9.9k

How did you eventually add tmp back to the res row.names? The answer is not in this thread and I can't figure it out.

Also, is it possible to edit the gene ids in-place instead of creating 'tmp'?

ADD REPLYlink modified 2.2 years ago • written 2.2 years ago by Mthabisi Moyo0

can you explain what does it "\\..*","",

ADD REPLYlink written 2.6 years ago by krushnach80630

remove the string after the period i.e. delete (technically substitute) everything that follows. See this.

ADD REPLYlink modified 2.6 years ago • written 2.6 years ago by genomax74k
6
gravatar for Kevin Blighe
15 months ago by
Kevin Blighe51k
Kevin Blighe51k wrote:

Just use biomaRt - it is a lot easier:

require("biomaRt")
mart <- useMart("ENSEMBL_MART_ENSEMBL")
mart <- useDataset("hsapiens_gene_ensembl", mart)

ens <- c("ENSG00000100601.5", "ENSG00000178826.6", "ENSG00000243663.1", "ENSG00000138231.8")
ensLookup <- gsub("\\.[0-9]*$", "", ens)
ensLookup
[1] "ENSG00000100601" "ENSG00000178826" "ENSG00000243663" "ENSG00000138231"

annotLookup <- getBM(
  mart=mart,
  attributes=c("ensembl_transcript_id", "ensembl_gene_id", "gene_biotype", "external_gene_name"),
  filter="ensembl_gene_id",
  values=ensLookup,
  uniqueRows=TRUE)

annotLookup <- data.frame(
  ens[match(annotLookup$ensembl_gene_id, ensLookup)],
  annotLookup)

colnames(annotLookup) <- c(
  "original_id",
  c("ensembl_transcript_id", "ensembl_gene_id", "gene_biotype", "external_gene_name"))

annotLookup

         original_id ensembl_transcript_id ensembl_gene_id         gene_biotype
1  ENSG00000100601.5       ENST00000216489 ENSG00000100601       protein_coding
2  ENSG00000100601.5       ENST00000557057 ENSG00000100601       protein_coding
3  ENSG00000100601.5       ENST00000555100 ENSG00000100601       protein_coding
4  ENSG00000100601.5       ENST00000554097 ENSG00000100601       protein_coding
5  ENSG00000138231.8       ENST00000260803 ENSG00000138231       protein_coding
6  ENSG00000138231.8       ENST00000460271 ENSG00000138231       protein_coding
7  ENSG00000138231.8       ENST00000477557 ENSG00000138231       protein_coding
8  ENSG00000138231.8       ENST00000463982 ENSG00000138231       protein_coding
9  ENSG00000178826.6       ENST00000409102 ENSG00000178826       protein_coding
10 ENSG00000178826.6       ENST00000487419 ENSG00000178826       protein_coding
11 ENSG00000178826.6       ENST00000359333 ENSG00000178826       protein_coding
12 ENSG00000178826.6       ENST00000480421 ENSG00000178826       protein_coding
13 ENSG00000178826.6       ENST00000409244 ENSG00000178826       protein_coding
14 ENSG00000178826.6       ENST00000409541 ENSG00000178826       protein_coding
15 ENSG00000178826.6       ENST00000410004 ENSG00000178826       protein_coding
16 ENSG00000178826.6       ENST00000482420 ENSG00000178826       protein_coding
17 ENSG00000178826.6       ENST00000471161 ENSG00000178826       protein_coding
18 ENSG00000243663.1       ENST00000493072 ENSG00000243663 processed_pseudogene
   external_gene_name
1              ALKBH1
2              ALKBH1
3              ALKBH1
4              ALKBH1
5                DBR1
6                DBR1
7                DBR1
8                DBR1
9             TMEM139
10            TMEM139
11            TMEM139
12            TMEM139
13            TMEM139
14            TMEM139
15            TMEM139
16            TMEM139
17            TMEM139
18           RPS4XP14

...or without ensembl_transcript_id:

annotLookup <- getBM(
  mart=mart,
  attributes=c("ensembl_gene_id", "gene_biotype", "external_gene_name"),
  filter="ensembl_gene_id",
  values=ensLookup,
  uniqueRows=TRUE)

annotLookup <- data.frame(
  ens[match(annotLookup$ensembl_gene_id, ensLookup)],
  annotLookup)

colnames(annotLookup) <- c(
  "original_id",
  c("ensembl_gene_id", "gene_biotype", "external_gene_name"))

annotLookup
    original_id ensembl_gene_id         gene_biotype external_gene_name
1 ENSG00000100601.5 ENSG00000100601       protein_coding             ALKBH1
2 ENSG00000138231.8 ENSG00000138231       protein_coding               DBR1
3 ENSG00000178826.6 ENSG00000178826       protein_coding            TMEM139
4 ENSG00000243663.1 ENSG00000243663 processed_pseudogene           RPS4XP14
ADD COMMENTlink modified 7 months ago • written 15 months ago by Kevin Blighe51k

Hi,

Thanks for your comment. I need your guide. I have "original_id" column and alse "gene_name"(e.g. ENSG00000100601.5 and ALKBH1) and I need their "Entrez ID". could you please guide me how do I get "Entrez ID" by biomaRt or other package from "original_id" ? I appreciate if you share your comment with me. Best Regards

ADD REPLYlink written 13 months ago by modarzi90
2

Take a look at this example, which will obtain Entrez IDs for you:

require("biomaRt")
mart <- useMart("ENSEMBL_MART_ENSEMBL")
mart <- useDataset("hsapiens_gene_ensembl", mart)

ens <- c("ENSG00000100601.5", "ENSG00000178826.6", "ENSG00000243663.1", "ENSG00000138231.8")
ensLookup <- gsub("\\.[0-9]*$", "", ens)


annotLookup <- getBM(
  mart=mart,
  attributes=c("ensembl_transcript_id", "ensembl_gene_id", "gene_biotype", "external_gene_name", "entrezgene_id"),
  filter="ensembl_gene_id",
  values=ensLookup,
  uniqueRows=TRUE)

annotLookup <- data.frame(
  ens[match(annotLookup$ensembl_gene_id, ensLookup)],
  annotLookup)

colnames(annotLookup) <- c(
  "original_id",
  c("ensembl_transcript_id", "ensembl_gene_id", "gene_biotype", "external_gene_name", "EntrezID"))

annotLookup
ADD REPLYlink modified 12 weeks ago • written 13 months ago by Kevin Blighe51k

Hi,

This is a very useful script, thank you!

I have a question about the result that I got. I run this script for my 58283 Ensembl gene ids (eg. ENSG00000000003) , however, I end up with 57714 converted hgnc_symbol. Do you have any idea why it is happening and if there is way to get the deleted gene ids?

Kind regards

ADD REPLYlink written 12 weeks ago by berry10

You could obtain the IDs that do not match via inference of the ones that do match. For example, take a look at the which() command.

The different organisations that maintain annotations, e.g., Ensembl, HGNC, Entrez, Riken, UCSC, etc., each has different rules about which to annotate or not, based on evidence. Between Ensembl and HGNC, the differences likely relate to non-coding transcripts that Ensembl has decided should be annotated, whereas, HGNC has decided that there is not yet enough evidence to support the existence of the transcript.

ADD REPLYlink written 12 weeks ago by Kevin Blighe51k

Can you confirm that you're getting hgnc_symbol, and not external_gene_name as Kevin suggests. hgnc_symbol will only get you HGNC, which means a lot of non-coding genes, which are named by Rfam, will not return a gene name if you get hgnc_symbol. If you get external_gene_name, you should get a name for everything as it will get whatever gene name there is.

If you're using external_gene_name and still not getting names for a bunch of them, please can you send the list to helpdesk@ensembl.org and we'll take a look. We have had some problems in recent releases with HGNC mapping, so this may be the cause of the missing names.

ADD REPLYlink written 12 weeks ago by Emily_Ensembl19k

Hi @Emily_Ensembl,

I tried both and I got even less results with external_gene_name. I will send you an email with the list.

From what I can tell those IDs that were not found in the database are either:

  • IDs that finish with _PAR_Y, which I don’t know what it means. Do you have any idea? Is it okay to completely remove that part from the ID?
  • IDs that were deprecated and are not in the current ENSEMBL database anymore.

I want to map the deprecated ones to their new updated genes but I'm not sure if it's even possible. Do you know if there is a way to do that?

Many thanks.

ADD REPLYlink written 11 weeks ago by berry10

PAR_Y likely relates to the pseudo-autosomal region on chromosome Y in males, i.e., the region on chromosome Y that pairs that with the PAR on chromosome X during meiosis in males. Take a look:

You can decid if you need them or not; otherwise, state in your methods that you removed them.

ADD REPLYlink modified 11 weeks ago • written 11 weeks ago by Kevin Blighe51k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2125 users visited in the last hour