Functional Annotation with Ensembl Biomart, GO, and KeGG

2018-01-02

Functional Annotation with Ensembl Biomart

The Ensembl Biomart database enables users to retrieve a vast diversity of annotation data for specific organisms. Initially, Steffen Durinck and Wolfgang Huber provide an powerful interface between the R language and Ensembl Biomart by providing the R package biomaRt. However, the biomartr package extends the functionality of the biomaRt package and introduces a more organism centered annotation retrieval concept.

The following sections will introduce users to the functionality and data retrieval precedures of biomartr and will show how biomartr extends the functionality of the initial biomaRt package.

Getting Started with biomartr

This query methodology provided by Ensembl Biomart and the biomaRt package is a very well defined approach for accurate annotation retrieval. Nevertheless, when learning this query methodology it (subjectively) seems non-intuitive from the user perspective. Therefore, the biomartr package provides another query methodology that aims to be more organism centric.

Taken together, the following workflow allows users to perform fast BioMart queries for attributes using the biomart() function implemented in this biomartr package:

  1. get attributes, datasets, and marts via : organismAttributes()

  2. choose available biological features (filters) via: organismFilters()

  3. specify a set of query genes: e.g. retrieved with getGenome(), getProteome() or getCDS()

  4. specify all arguments of the biomart() function using steps 1) - 3) and perform a BioMart query

Note that dataset names change very frequently due to the update of dataset versions. So in case some query functions do not work properly, users should check with organismAttributes(update = TRUE) whether or not their dataset name has been changed. For example, organismAttributes("Homo sapiens", topic = "id", update = TRUE) might reveal that the dataset ENSEMBL_MART_ENSEMBL has changed.

Retrieve marts, datasets, attributes, and filters with biomartr

Retrieve Available Marts

The getMarts() function allows users to list all available databases that can be accessed through BioMart interfaces.

# load the biomartr package
library(biomartr)

# list all available databases
getMarts()

Retrieve Available Datasets from a Specific Mart

Now users can select a specific database to list all available datasets that can be accessed through this database. In this example we choose the ENSEMBL_MART_ENSEMBL database.

head(getDatasets(mart = "ENSEMBL_MART_ENSEMBL") , 5)

Now you can select the dataset hsapiens_gene_ensembl and list all available attributes that can be retrieved from this dataset.

tail(getDatasets(mart = "ENSEMBL_MART_ENSEMBL") , 38)

Retrieve Available Attributes from a Specific Dataset

Now that you have selected a database (hsapiens_gene_ensembl) and a dataset (hsapiens_gene_ensembl), users can list all available attributes for this dataset using the getAttributes() function.

# show all elements of the data.frame
options(tibble.print_max = Inf)
# list all available attributes for dataset: hsapiens_gene_ensembl
head( getAttributes(mart    = "ENSEMBL_MART_ENSEMBL", 
                    dataset = "hsapiens_gene_ensembl"), 10 )

Retrieve Available Filters from a Specific Dataset

Finally, the getFilters() function allows users to list available filters for a specific dataset that can be used for a biomart() query.

# show all elements of the data.frame
options(tibble.print_max = Inf)
# list all available filters for dataset: hsapiens_gene_ensembl
head( getFilters(mart    = "ENSEMBL_MART_ENSEMBL", 
                 dataset = "hsapiens_gene_ensembl"), 10 )

Organism Specific Retrieval of Information

In most use cases, users will work with a single or a set of model organisms. In this process they will mostly be interested in specific annotations for this particular model organism. The organismBM() function addresses this issue and provides users with an organism centric query to marts and datasets which are available for a particular organism of interest.

Note that when running the following functions for the first time, the data retrieval procedure will take some time, due to the remote access to BioMart. The corresponding result is then saved in a *.txt file named _biomart/listDatasets.txt within the tempdir() folder, allowing subsequent queries to be performed much faster. The tempdir() folder, however, will be deleted after a new R session was established. In this case the inital call of the subsequent functions again will take time to retrieve all organism specific data from the BioMart database.

This concept of locally storing all organism specific database linking information available in BioMart into an internal file allows users to significantly speed up subsequent retrieval queries for that particular organism.

# show all elements of the data.frame
options(tibble.print_max = Inf)
# retrieving all available datasets and biomart connections for
# a specific query organism (scientific name)
organismBM(organism = "Homo sapiens")

The result is a table storing all marts and datasets from which annotations can be retrieved for Homo sapiens. Furthermore, a short description as well as the version of the dataset being accessed (very useful for publications) is returned.

Users will observe that 3 different marts provide 6 different datasets storing annotation information for Homo sapiens.

Please note, however, that scientific names of organisms must be written correctly! For ex. “Homo Sapiens” will be treated differently (not recognized) than “Homo sapiens” (recognized).

Similar to the biomaRt package query methodology, users need to specify attributes and filters to be able to perform accurate BioMart queries. Here the functions organismAttributes() and organismFilters() provide useful and intuitive concepts to obtain this information.

# show all elements of the data.frame
options(tibble.print_max = Inf)
# return available attributes for "Homo sapiens"
head(biomartr::organismAttributes("Homo sapiens"), 20)

Users will observe that the organismAttributes() function returns a data.frame storing attribute names, datasets, and marts which are available for Homo sapiens. After the ENSEMBL release 87 the ENSEMBL_MART_SEQUENCE service provided by Ensembl does not work properly and thus the organismAttributes() function prints out warning messages to make the user aware when certain marts provided bt Ensembl do not work properly, yet.

An additional feature provided by organismAttributes() is the topic argument. The topic argument allows users to to search for specific attributes, topics, or categories for faster filtering.

# show all elements of the data.frame
options(tibble.print_max = Inf)
# search for attribute topic "id"
head(organismAttributes("Homo sapiens", topic = "id"), 20)

Now, all attribute names having id as part of their name are being returned.

Another example is topic = "homolog".

# show all elements of the data.frame
options(tibble.print_max = Inf)
# search for attribute topic "homolog"
head(organismAttributes("Homo sapiens", topic = "homolog"), 20)

Or topic = "dn" and topic = "ds" for dn and ds value retrieval.

# show all elements of the data.frame
options(tibble.print_max = Inf)
# search for attribute topic "dn"
head(organismAttributes("Homo sapiens", topic = "dn"))
# show all elements of the data.frame
options(tibble.print_max = Inf)
# search for attribute topic "ds"
head(organismAttributes("Homo sapiens", topic = "ds"))

Analogous to the organismAttributes() function, the organismFilters() function returns all filters that are available for a query organism of interest.

# show all elements of the data.frame
options(tibble.print_max = Inf)
# return available filters for "Homo sapiens"
head(organismFilters("Homo sapiens"), 20)

The organismFilters() function also allows users to search for filters that correspond to a specific topic or category.

# show all elements of the data.frame
options(tibble.print_max = Inf)
# search for filter topic "id"
head(organismFilters("Homo sapiens", topic = "id"), 20)

Performing BioMart queries with biomartr

The short introduction to the functionality of organismBM(), organismAttributes(), and organismFilters() will allow users to perform BioMart queries in a very intuitive organism centric way. The main function to perform BioMart queries is biomart().

For the following examples we will assume that we are interested in the annotation of specific genes from the Homo sapiens proteome. We want to map the corresponding refseq gene id to a set of other gene ids used in other databases. For this purpose, first we need consult the organismAttributes() function.

# show all elements of the data.frame
options(tibble.print_max = Inf)

head(organismAttributes("Homo sapiens", topic = "id"))
# show all elements of the data.frame
options(tibble.print_max = Inf)
# retrieve the proteome of Homo sapiens from refseq
file_path <- getProteome( db       = "refseq",
                          organism = "Homo sapiens",
                          path     = file.path("_ncbi_downloads","proteomes") )

Hsapiens_proteome <- read_proteome(file_path, format = "fasta")

# remove splice variants from id
gene_set <- unlist(sapply(strsplit(Hsapiens_proteome@ranges@NAMES[1:5], ".",fixed = TRUE), function(x) x[1]))

result_BM <- biomart( genes      = gene_set,
                      mart       = "ENSEMBL_MART_ENSEMBL", 
                      dataset    = "hsapiens_gene_ensembl",
                      attributes = c("ensembl_gene_id","ensembl_peptide_id"),
                      filters    = "refseq_peptide")

result_BM 

The biomart() function takes as arguments a set of genes (gene ids specified in the filter argument), the corresponding mart and dataset, as well as the attributes which shall be returned.

Gene Ontology

The biomartr package also enables a fast and intuitive retrieval of GO terms and additional information via the getGO() function. Several databases can be selected to retrieve GO annotation information for a set of query genes. So far, the getGO() function allows GO information retrieval from the Ensembl Biomart database.

In this example we will retrieve GO information for a set of Homo sapiens genes stored as hgnc_symbol.

GO Annotation Retrieval via BioMart

The getGO() function takes several arguments as input to retrieve GO information from BioMart. First, the scientific name of the organism of interest needs to be specified. Furthermore, a set of gene ids as well as their corresponding filter notation (GUCA2A gene ids have filter notation hgnc_symbol; see organismFilters() for details) need to be specified. The database argument then defines the database from which GO information shall be retrieved.

# show all elements of the data.frame
options(tibble.print_max = Inf)
# search for GO terms of an example Homo sapiens gene
GO_tbl <- getGO(organism = "Homo sapiens", 
                genes    = "GUCA2A",
                filters  = "hgnc_symbol")

GO_tbl

Hence, for each gene id the resulting table stores all annotated GO terms found in Ensembl Biomart.