Quickly obtain gene and transcript annotations from Ensembl using AnnotationHub and ensembldb.

makeGRangesFromEnsembl(
  organism,
  level = c("genes", "transcripts"),
  genomeBuild = NULL,
  release = NULL,
  ignoreVersion = TRUE,
  synonyms = FALSE
)

makeGRangesFromEnsDb(
  object,
  level = c("genes", "transcripts"),
  ignoreVersion = TRUE,
  synonyms = FALSE
)

annotable(...)

Arguments

organism

character(1). Full Latin organism name (e.g. "Homo sapiens").

level

character(1). Return as genes or transcripts.

genomeBuild

character(1). Ensembl genome build assembly name (e.g. "GRCh38"). If set NULL, defaults to the most recent build available. Note: don't pass in UCSC build IDs (e.g. "hg38").

release

integer(1). Ensembl release version (e.g. 90). We recommend setting this value if possible, for improved reproducibility. When left unset, the latest release available via AnnotationHub/ensembldb is used. Note that the latest version available can vary, depending on the versions of AnnotationHub and ensembldb in use.

ignoreVersion

logical(1). Ignore identifier (e.g. transcript, gene) versions. When applicable, the identifier containing version numbers will be stored in txIdVersion and geneIdVersion, and the variants without versions will be stored in txId, txIdNoVersion, geneId, and geneIdNoVersion.

synonyms

logical(1). Include gene synonyms. Queries the Ensembl web server, and is CPU intensive.

object

EnsDb or character(1). EnsDb object or name of specific annotation package containing a versioned EnsDb object (e.g. "EnsDb.Hsapiens.v75").

...

Additional arguments.

Value

GRanges.

Details

Simply specify the desired organism, using the full Latin name. For example, we can obtain human annotations with Homo sapiens. Optionally, specific Ensembl genome builds (e.g. GRCh38) and release versions (e.g. 87) are supported.

Under the hood, this function fetches annotations from AnnotationHub using the ensembldb package. AnnotationHub supports versioned Ensembl releases, back to version 87.

Genome build: use "GRCh38" instead of "hg38" for the genome build, since we're querying Ensembl and not UCSC.

Functions

  • makeGRangesFromEnsembl: Obtain annotations from Ensembl by querying AnnotationHub.

  • makeGRangesFromEnsDb: Use a specific EnsDb object as the annotation source. Alternatively, can pass in an EnsDb package name as a character(1).

  • annotable: Legacy convenience function that calls makeGRangesFromEnsembl() and returns a tbl_df (tibble) instead of GRanges. Note that GRanges can also be coerced using as.data.frame().

Note

Updated 2021-03-10.

Broad class definitions

For gene and transcript annotations, a broadClass column is added, which generalizes the gene types into a smaller number of semantically-meaningful groups:

  • coding.

  • noncoding.

  • pseudo.

  • small.

  • decaying.

  • ig (immunoglobulin).

  • tcr (T cell receptor).

  • other.

GRCh37 (hg19) legacy annotations

makeGRangesFromEnsembl() supports the legacy Homo sapiens GRCh37 (release 75) build by internally querying the EnsDb.Hsapiens.v75 package. Alternatively, the corresponding GTF/GFF file can be loaded directly from GENCODE or Ensembl.

AnnotationHub queries

Here's how to perform manual, customized AnnotationHub queries.

library(AnnotationHub)
library(ensembldb)
ah <- AnnotationHub()

# Human ensembldb (EnsDb) records.
ahs <- query(
    x = ah,
    pattern = c(
        "Homo sapiens",
        "GRCh38",
        "Ensembl",
        "EnsDb"
    )
)
mcols(ahs)
print(ahs)
# EnsDb (Ensembl GRCh38 94; 2018-10-11)
ah[["AH64923"]]

# Human UCSC TxDb records.
ahs <- query(
    x = ah,
    pattern = c(
        "Homo sapiens",
        "UCSC",
        "TxDb",
        "knownGene"
    )
)
mcols(ahs)
print(ahs)
# TxDb (UCSC hg38 GENCODE 24; 2016-12-22)
ah[["AH52260"]]

See also

Examples

## Get annotations from Ensembl via AnnotationHub query. genes <- makeGRangesFromEnsembl( organism = "Homo sapiens", level = "genes" )
#> → Making `GRanges` from Ensembl.
#> → Getting `EnsDb` from AnnotationHub 2.22.0 (2020-10-27).
#> AH89426: Ensembl 103 EnsDb for Homo sapiens.
#> → Making `GRanges` from `EnsDb`.
#> Organism: Homo sapiens
#> Genome build: GRCh38
#> Release: 103
#> Level: genes
#> → Defining names by `geneId` column in `mcols`.
summary(genes)
#> [1] "EnsemblGenes object with 67992 ranges and 8 metadata columns"
transcripts <- makeGRangesFromEnsembl( organism = "Homo sapiens", level = "transcripts" )
#> → Making `GRanges` from Ensembl.
#> → Getting `EnsDb` from AnnotationHub 2.22.0 (2020-10-27).
#> AH89426: Ensembl 103 EnsDb for Homo sapiens.
#> → Making `GRanges` from `EnsDb`.
#> Organism: Homo sapiens
#> Genome build: GRCh38
#> Release: 103
#> Level: transcripts
#> → Defining names by `txId` column in `mcols`.
summary(transcripts)
#> [1] "EnsemblTranscripts object with 257222 ranges and 17 metadata columns"
## Get annotations from specific EnsDb object or package. if ("EnsDb.Hsapiens.v75" %in% rownames(installed.packages())) { genes <- makeGRangesFromEnsDb( object = "EnsDb.Hsapiens.v75", level = "genes" ) summary(genes) }
#> → Making `GRanges` from `EnsDb`.
#> Organism: Homo sapiens
#> Genome build: GRCh37
#> Release: 75
#> Level: genes
#> → Defining names by `geneId` column in `mcols`.
#> [1] "EnsemblGenes object with 64102 ranges and 6 metadata columns"