Is there a way to access a specific coding sequence of a gene of interest on ENSEMBL in R?

Viewed 94

I am trying to find a way to retrieve the coding sequence (CDS) of a specific gene of interest and load it into R. I tried my luck with the BioMart package, but it doesn't let me specify which gene I am interested in.

Any help is appreciated!

Best, Heiko

1 Answers

This should work:

library(biomaRt)
library(Biostrings)
mart <- useMart("ensembl", dataset="hsapiens_gene_ensembl")
cds_seq = getSequence(id = "APOE", 
                   type = "hgnc_symbol", 
                   seqType = "cdna", 
                   mart = mart)

We can translate the CDS:

AAs = sapply(cds_seq$coding,function(i)if(i=="Sequence unavailable"){NA}else{translate(DNAString(i))})

Get peptide sequence:

pep_seq = getSequence(id = "APOE", 
                   type = "hgnc_symbol", 
                   seqType = "peptide", 
                   mart = mart)

And check they are similar:

lapply(which(pep_seq$peptide!="Sequence unavailable"),function(i){
pep_seq$peptide[i] == as.character(AAs[[i]])
})

[[1]]
[1] TRUE

[[2]]
[1] TRUE

[[3]]
[1] TRUE

[[4]]
[1] TRUE

If you want to get the refseq, do:

cds_seq = getSequence(id = "NM_000041", 
                      type = "refseq_mrna", 
                      seqType = "coding", 
                      mart = mart)
Related