I will provide an example below. But first, there is a vignette for biomaRt (actually two), and it has extensive examples of how to use the package. When you are trying to figure out how to use a package, reading the vignette (possible multiple times) should be your first step. What you want to do could easily be extrapolated from the information there, and if you want to learn how to use R/Bioconductor, reading examples and inferring how to do what you want from those examples is an invaluable skill.
Another skill is asking good questions. You don't say what species, so I am going to assume human. When asking a question, it's best to try to think of what relevant information somebody else might need to answer your question, and try to provide that.
## instanciate a mart object
> library(biomaRt)
> mart <- useEnsembl("ensembl","hsapiens_gene_ensembl")
## get some UniProt IDs
> library(UniProt.ws)
> univals <- head(keys(z, "UniProtKB"))
> univals
[1] "A0A0C5B5G6" "A0A1B0GTW7" "A0JNW5" "A0JP26" "A0PK11"
[6] "A1A4S6"
> getBM(c("ensembl_gene_id","uniprot_gn_id"), "uniprot_gn_id", univals, mart)
ensembl_gene_id uniprot_gn_id
1 ENSG00000283654 A0A1B0GTW7
2 ENSG00000111647 A0JNW5
3 ENSG00000278699 A0JP26
4 ENSG00000278522 A0JP26
5 ENSG00000249581 A0PK11
6 ENSG00000071205 A1A4S6
It's important to remember to ask getBM
to return your input IDs, so you know which Ensembl gene ID matches up to a given UniProt ID.
Note that this can also be done via the
UniProt.ws
package:Though the IDs appear different...