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)