biomaRt Tutorial


Go to to chat with a life sciences focused ChatGPT.

Overview of biomaRt

Bioinformatics is a field that combines biology, computer science, and information technology to analyze and interpret biological data. One of the tools widely used in bioinformatics for accessing and retrieving data is biomaRt. biomaRt is an R package that interfaces with the BioMart data management system, which provides access to a diverse set of databases containing a wealth of genomic and proteomic data.

What is biomaRt?

biomaRt is a powerful and easy-to-use R package that allows researchers to extract data from the BioMart databases without any programming knowledge or understanding of the underlying database structure. BioMart itself is a web-based tool that facilitates the extraction of data, and biomaRt provides an interface to this tool directly from the R environment.

The BioMart system is organized into "marts," which are essentially databases containing specific types of data. For example, the Ensembl Genes mart contains gene-related data for all species included in the Ensembl database. Users can select a mart database, choose a dataset (usually a species), apply filters to restrict their query, and select attributes that define the desired output.

How does biomaRt work?

biomaRt works by allowing users to construct queries using a set of functions that specify the database (mart), the dataset (species), filters (query restrictions), and attributes (output fields). Once the query is defined, biomaRt retrieves the data from the BioMart database and returns it in a format that can be easily manipulated and analyzed within R.

The package is particularly useful for batch retrieval of data, where the same query needs to be run for multiple genes, proteins, or other biological entities. It also supports the integration of data from different databases, making it possible to combine gene expression data with annotation data, for example.

Why use biomaRt?

The main advantage of using biomaRt is its ability to streamline the data retrieval process. Instead of manually searching through databases and downloading data files, researchers can use biomaRt to programmatically access the data they need. This not only saves time but also ensures that the data retrieval process is reproducible and can be easily shared with others.

biomaRt is also regularly updated to reflect changes in the BioMart databases, ensuring that users have access to the latest data. Its integration with R means that it can be used in conjunction with other bioinformatics tools and packages available in R, providing a comprehensive environment for data analysis.

In the following sections, we will go through the installation process, provide a quick start guide, and explore some popular commands with code examples to help you get started with biomaRt.


To install biomaRt, you will need to have R installed on your computer. R is a free software environment for statistical computing and graphics. Once you have R installed, you can install biomaRt directly from the Bioconductor repository, which hosts packages specifically for bioinformatics.

Here's how you can install biomaRt:

if (!requireNamespace("BiocManager", quietly = TRUE))


This code checks if the BiocManager package is installed, which is required to install packages from Bioconductor. If it's not installed, the code installs it. Then, it uses BiocManager to install biomaRt.

Quick Start

Once biomaRt is installed, you can load the package and start using it to access BioMart databases. Here's a quick example to get you started:


# List available BioMart databases

# Connect to the Ensembl database
ensembl <- useMart("ensembl")

# List available datasets (species)

# Select a dataset, for example, human genes (hsapiens_gene_ensembl)
ensembl <- useDataset("hsapiens_gene_ensembl", mart = ensembl)

# Retrieve gene information based on a filter, such as a list of gene symbols
genes <- c("BRCA1", "BRCA2", "TP53")
attributes <- c("ensembl_gene_id", "external_gene_name", "chromosome_name", "start_position", "end_position", "strand")

# Get the data
gene_data <- getBM(attributes = attributes, filters = "external_gene_name", values = genes, mart = ensembl)

# View the results

This quick start example demonstrates how to list available BioMart databases, connect to the Ensembl database, select a dataset, and retrieve gene information based on a list of gene symbols.

Code Examples Of Popular Commands

In this section, we will explore five popular commands used with biomaRt and provide code examples for each.

1. Listing Available BioMart Databases

To see which BioMart databases are available, you can use the listMarts() function:


2. Selecting a Dataset

After choosing a BioMart database, you can select a specific dataset using the useDataset() function:

ensembl <- useMart("ensembl")
ensembl <- useDataset("hsapiens_gene_ensembl", mart = ensembl)

3. Retrieving Gene Information

To retrieve information about specific genes, you can use the getBM() function with appropriate filters and attributes:

attributes <- c("ensembl_gene_id", "external_gene_name", "chromosome_name", "start_position", "end_position", "strand")
gene_data <- getBM(attributes = attributes, filters = "external_gene_name", values = c("BRCA1", "BRCA2", "TP53"), mart = ensembl)

4. Batch Retrieval of Sequences

If you need to retrieve sequences for multiple genes, you can do so in a batch using the getSequence() function:

sequences <- getSequence(id = c("ENSG00000012048", "ENSG00000139618"), type = "ensembl_gene_id", seqType = "coding", mart = ensembl)

5. Combining Data from Different Databases

biomaRt allows you to combine data from different databases, such as Ensembl and UniProt, using the getBM() function:

attributes <- c("ensembl_gene_id", "external_gene_name", "uniprotswissprot")
gene_data <- getBM(attributes = attributes, filters = "external_gene_name", values = c("BRCA1", "BRCA2", "TP53"), mart = ensembl)

These code examples provide a glimpse into the functionality of biomaRt and how it can be used to streamline the data retrieval process in bioinformatics research. With biomaRt, you can access a vast array of genomic and proteomic data, which can be integrated into your analysis workflows in R.