New Ensembl platform tables¶
Annotation after release 116 is published only on the new Ensembl platform, as files per assembly at https://ftp.ebi.ac.uk/pub/ensemblorganisms/ (genes.gff3.gz, xref.tsv.gz and homology.tsv.gz, among others) and through a GraphQL API. Four functions read the files, and annotations() lists what is published.
import ens_tables as et
human = {"assembly": "GCA_000001405.29", "annotation": "2026_04"}
genes = et.genes(**human)
primary = et.genes(**human, include_alt=False)
transcripts = et.transcripts(**human)
hgnc = et.xrefs(**human, db="HGNC Symbol")
mouse = et.homologies(**human, homology="2026_07_13", ref_species="mus_musculus")
et.annotations("GCA_000001405.29")
Genome |
|
|
|
|---|---|---|---|
Human GRCh38.p14 |
|
|
|
Mouse GRCm39 |
|
|
|
Versions¶
Table calls require the assembly accession and annotation date; homologies() also needs the homology date, and provider defaults to "ensembl". Record these values in the script and run the intended calls online once to fill the cache for offline use. annotations() reads the published directory listing and needs network access.
Files are checked against their directory’s md5sum.txt and cached as parquet. genes() and transcripts() share one GFF3 download (95 MB for human), xrefs() adds xref.tsv.gz (74 MB), and homologies() reads the homology file (7 MB). Each table records in attrs the source URL, its MD5, the assembly, provider and annotation date, and the gene scope or homology date. pandas does not carry attrs through every operation, and a merge drops them, so copy table.attrs first if you need the record.
Genes and transcripts¶
genes() has one row per gene and transcripts() one row per transcript with its gene. Column names follow BioMart’s attribute names where the meaning is the same, such as ensembl_gene_id, external_gene_name, start_position and transcript_biotype. Versions are in gene_version and transcript_version, and ensembl_gene_id_version and ensembl_transcript_id_version give versioned IDs. Coordinates are 1-based and inclusive, and strand is 1 or -1.
include_alt=True, the default, adds genes on alternative haplotypes and patches, which is the gene set of BioMart and query(); include_alt=False keeps the primary assembly. Some annotations, such as mouse 2026_04, publish no genes-including_alt file and have a single gene set, and attrs["source"] names the file used.
For human and mouse 2026_04 with include_alt=True, the tested shared gene and transcript field values match release 116, treating empty and missing gene descriptions alike. Table layouts and dtypes can differ.
Cross-references¶
xrefs() has one row per object and external record, as in the source file. level says whether the record is attached to the gene, a transcript or a protein. db takes full db_name values such as "HGNC Symbol", "NCBI gene (formerly Entrezgene)" or "GO"; a wrong name raises an error that lists the available ones. The first call downloads and converts the full xref file. Cached queries skip parquet row groups outside the requested databases.
Rows are limited to the genes of genes() with the same include_alt. Rows outside them, such as LRG records, are counted in attrs["excluded_rows"] after db is applied.
For 2026_04 with include_alt=True, human HGNC mappings and human and mouse Entrez mappings match release 116 after projection to unique gene and external ID pairs, excluding missing BioMart mappings.
Homologies¶
homologies() reads the homology file of the assembly’s own species. Each row links one of its genes (ensembl_gene_id) to a gene of ref_species, and query_perc_id and query_perc_cov refer to the gene of the assembly. The relation is directional: mouse homologs of human genes and human homologs of mouse genes are different sets. homology_type is homolog_rbbh or homolog_bbh as published; Compara’s one-to-one and one-to-many types are not part of these files.
Arguments and missing values¶
db and ref_species take a name or a list of names. Leave them out or pass None for no restriction; empty lists and blank names raise an error. Empty fields in the source files, such as genes without a name, are missing values in all four tables.
Common tasks¶
# Names and coordinates for adata.var indexed by Ensembl gene ID; the rows stay as they are
columns = ["external_gene_name", "chromosome_name", "start_position", "end_position"]
adata.var = adata.var.join(genes.set_index("ensembl_gene_id")[columns])
# tx2gene for quantification with versioned transcript IDs
tx2gene = transcripts[["ensembl_transcript_id_version", "ensembl_gene_id_version"]]
# Gene-GO pairs, one row per pair
go = et.xrefs(**human, db="GO")
gene_go = go[["ensembl_gene_id", "xref_id"]].drop_duplicates()
# Evidence codes, kept separately because one gene-GO pair can have several
go["evidence"] = go["xref_source"].str.rsplit(":", n=1).str[-1]
gene_go_evidence = go[["ensembl_gene_id", "xref_id", "evidence"]].drop_duplicates()
# One Entrez list per gene, so that a join keeps one row per gene
entrez = et.xrefs(**human, db="NCBI gene (formerly Entrezgene)")
entrez_ids = entrez.drop_duplicates(["ensembl_gene_id", "xref_id"]).groupby("ensembl_gene_id")["xref_id"].agg(";".join)