Skip to content

ID version handling and GENCODE compatibility #335

Description

@ccwang002

Hi team, thanks again for maintaining this library.

We (together with @fkgruber) are trying to use pyensembl with a custom genome build based on GENCODE v48, but we’re running into issues where variant effects are not inferred correctly. For example,

from pyensembl import Genome
from varcode import Variant

g = Genome(
    reference_name="GRCh38",
    annotation_name="my_genome_features",
    gtf_path_or_url="gencode.v48.primary_assembly.annotation.gtf",
    protein_fasta_paths_or_urls="gencode.v48.pc_translations.fa.gz",
    transcript_fasta_paths_or_urls="gencode.v48.transcripts.fa.gz",
    cache_directory_path=".cache",
)

Variant("chr1", 12110124, "G", "A", ensembl=g).effects()
# <EffectCollection with 3 elements>
#  -- NoncodingTranscript(...)
#  -- NoncodingTranscript(...)
#  -- NoncodingTranscript(...)

# Expected output say using Ensembl release 114
# <EffectCollection with 3 elements>
#  -- Substitution(variant=..., transcript_name=TNFRSF8-201, transcript_id=ENST00000263932, effect_description=p.R199H)
#  -- Substitution(variant=..., transcript_name=TNFRSF8-203, transcript_id=ENST00000417814, effect_description=p.R88H)
#  -- NoncodingTranscript(variant=..., transcript_name=TNFRSF8-205, transcript_id=ENST00000514649)

So far we've identified some potential issues:

  1. Protein/transcript ID version handling.
    It looks like pyensembl trims version suffixes from FASTA IDs (e.g. .1 in ENSPxxx.1), which seems to break mapping between GTF and FASTA entries.

    • GENCODE GTF includes versioned IDs directly (e.g. ENSTxxx.7, ENSPxxx.1)
    • Ensembl GTF separates version into a different field (transcript_version, protein_version)

    The version trimming seems to occur at these places:

  2. Biotype field naming differences.
    GENCODE uses: gene_type transcript_type, while pyensembl expects: gene_biotype, transcript_biotype

Modifications to GENCODE GTF to make it work for pyensembl
zcat gencode.v48.primary_assembly.annotation.gtf.gz \
| sed -E '
  s/gene_type "/gene_biotype "/g;
  s/transcript_type "/transcript_biotype "/g;
  s/protein_id "ENSP([0-9]+)\.[0-9]+"/protein_id "ENSP\1"/g
' \
| gzip > gencode.v48.primary_assembly.annotation.biotype_protein_noversion.gtf.gz

Questions

  1. Is there a recommended way to preserve transcript/protein versioning within pyensembl?
  2. GENCODE compatibility (see also Compatability with Gencode GTF #168)
    • Are there official or recommended preprocessing steps for using GENCODE GTFs with pyensembl?
    • Beyond the fixes above, are there other known incompatibilities we should account for?

Happy to help test or contribute if useful. Thanks again for your work on this project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions