Modified: 27 May, 2016
AnnotationHub server provides easy R / Bioconductor access to
large collections of publicly available whole genome resources,
e.g,. ENSEMBL genome fasta or gtf files, UCSC chain resources, ENCODE
data tracks at UCSC, etc.
r Biocpkg("AnnotationHub") package provides a client interface
to resources stored at the AnnotationHub web service.
r Biocpkg("AnnotationHub") package is straightforward to use.
ah = AnnotationHub()
Now at this point you have already done everything you need in order
to start retrieving annotations. For most operations, using the
AnnotationHub object should feel a lot like working with a familiar
Lets take a minute to look at the show method for the hub object ah
You can see that it gives you an idea about the different types of data that are present inside the hub. You can see where the data is coming from (dataprovider), as well as what species have samples present (species), what kinds of R data objects could be returned (rdataclass). We can take a closer look at all the kinds of data providers that are available by simply looking at the contents of dataprovider as if it were the column of a data.frame object like this:
In the same way, you can also see data from different species inside the hub by looking at the contents of species like this:
And this will also work for any of the other types of metadata present. You can learn which kinds of metadata are available by simply hitting the tab key after you type 'ah$'. In this way you can explore for yourself what kinds of data are present in the hub right from the command line. This interface also allows you to access the hub programatically to extract data that matches a particular set of criteria.
Another valuable types of metadata to pay attention to is the rdataclass.
The rdataclass allows you to see which kinds of R objects the hub will return to you. This kind of information is valuable both as a means to filter results and also as a means to explore and learn about some of the kinds of annotation objects that are widely available for the project. Right now this is a pretty short list, but over time it should grow as we support more of the different kinds of annotation objects via the hub.
Now lets try getting the Chain Files from UCSC using the query and subset methods to selectively pare down the hub based on specific criteria.
The query method lets you search rows for
specific strings, returning an
AnnotationHub instance with just the
rows matching the query.
From the show method, one can easily see that one of the dataprovider is UCSC and there is a rdataclass for ChainFile
One can get chain files for Drosophila melanogaster from UCSC with:
dm <- query(ah, c("ChainFile", "UCSC", "Drosophila melanogaster")) dm
Query has worked and you can now see that the only species present is Drosophila melanogaster.
The metadata underlying this hub object can be retrieved by you
df <- mcols(dm)
By default the show method will only display the first 5 and last 5 rows. There are already thousands of records present in the hub.
Lets look at another example, where we pull down only Inparanoid8 data from the hub and use subset to return a smaller base object (here we are finding cases where the genome column is set to panda).
ahs <- query(ah, c('inparanoid8', 'ailuropoda')) ahs
We can also look at the
AnnotationHub object in a browser using the
display() function. We can then filter the
for _chainFile__ by either using the Global search field on the top
right corner of the page or the in-column search field for `rdataclass'.
d <- display(ah)
Displaying and filtering the Annotation Hub object in a browser
By default 1000 entries are displayed per page, we can change this using the filter on the top of the page or navigate through different pages using the page scrolling feature at the bottom of the page.
We can also select the rows of interest to us and send them back to
the R session using 'Return rows to R session' button ; this sets a
filter internally which filters the
AnnotationHub object. The names
of the selected AnnotationHub elements displayed at the top of the
AnnotationHubto retrieve data
Looking back at our chain file example, if we are interested in the file dm1ToDm2.over.chain.gz, we can gets its metadata using
We can download the file using
Each file is retrieved from the AnnotationHub server and the file is also cache locally, so that the next time you need to retrieve it, it should download much more quickly.
When you create the
AnnotationHub object, it will set up the object
for you with some default settings. See
?AnnotationHub for ways to
customize the hub source, the local cache, and other instance-specific
?getAnnotationHubOption to get or set package-global
options for use across sessions.
If you look at the object you will see some helpful information about it such as where the data is cached and where online the hub server is set to.
By default the
AnnotationHub object is set to the latest
snapshotData and a snapshot version that matches the version of
Bioconductor that you are using. You can also learn about these data
with the appropriate methods.
If you are interested in using an older version of a snapshot, you can
list previous versions with the
possibleDates() like this:
pd <- possibleDates(ah) pd
Set the dates like this:
snapshotDate(ah) <- pd
Resources in AnnotationHub aren't loaded with the standard
R package approach
and therefore can't be loaded on cluster nodes with library(). There are a
couple of options to sharing AnnotationHub objects across a cluster when
researchers are using the same R install and want access to the same
As an example, we create a TxDb object from a GRanges stored in AnnotationHub contributed by contributed by Timothée Flutre. The GRanges was created from a GFF file and contains gene information for Vitis vinifera.
One option is that each user downloads the resource with hub[["AH50773"]] and the GRanges is saved in the cache. Each subsequent call to hub[["AH50773"]] retrieves the resource from the cache which is very fast.
The necessary code extracts the resource then calls makeTxDbFromGRanges().
library(AnnotationHub) hub <- AnnotationHub() gr <- hub[["AH50773"]] ## downloaded once txdb <- makeTxDbFromGRanges(gr) ## build on the fly
Another approach is that one user builds the TxDb and saves it as a .sqlite file. The cluster admin installs this in a common place on all cluster nodes and each user can load it with loadDb(). Loading the file is as quick and easy as calling library() on a TxDb package.
Once the .sqlite file is install each user's code would include:
library(AnnotationDbi) ## if not already loaded txdb <- loadDb("/locationToFile/mytxdb.sqlite")
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.