Skip to main content

gtfparse

Tests Coverage Status PyPI

gtfparse reads GTF (Gene Transfer Format) annotation files, such as those from Ensembl and GENCODE, into pandas DataFrames: one row per feature, with attributes such as gene and transcript IDs expanded into columns. It can also write a table back to GTF. In the OpenVax tools, PyEnsembl uses it to read Ensembl and custom annotations before indexing them.

Install

python -m pip install gtfparse

Python 3.11 or later is required. gtfparse depends on pandas and PyArrow; for optional Polars output, install gtfparse[polars].

Quick start

This small artificial GTF runs without a download. Replace the stream with your annotation filename when working with a real dataset.

from io import StringIO
from gtfparse import read_gtf

annotation = StringIO(
    '1\texample\tgene\t101\t200\t.\t+\t.\tgene_id "g1"; gene_name "EXAMPLE";\n'
    '1\texample\texon\t101\t150\t.\t+\t.\tgene_id "g1"; transcript_id "t1";\n'
)
features = read_gtf(annotation)
genes = features.loc[features["feature"] == "gene"]
print(genes["gene_name"].tolist())
for row in features.itertuples():
    print(row.feature, row.seqname, row.start, row.end, row.gene_id)
['EXAMPLE']
gene 1 101 200 g1
exon 1 101 150 g1

feature identifies the row type. seqname is the chromosome or contig name; it is not the gene ID. The ninth GTF field supplies attributes such as gene_id, gene_name and transcript_id. Coordinates stay one-based and inclusive, as in the file.

Documentation

The guides are Markdown files in docs/. In reading order:

  1. Filter and write annotations: select chromosomes and features, write GTF and read numeric attributes.
  2. Report parsing progress with your own progress bar.
  3. Version 3 migration: pandas by default, and optional Polars output.
  4. API reference for every public function.

To build the documentation locally, run python -m pip install -r requirements-docs.txt and ./docs.sh. python scripts/check_docs_examples.py checks the printed example output.

Development

python -m pip install -e ".[dev]"
./lint.sh   # ruff check and ruff format --check
./test.sh   # pytest with coverage

./format.sh applies ruff formatting.

The development installer uses python from the active environment. Set PYTHON=/path/to/python ./develop.sh to select an interpreter explicitly; additional arguments are passed to pip.

License

Apache 2.0; see LICENSE.

Metadata

Release files for gtfparse 3.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gtfparse 3.1.2
File Size Uploaded Provenance Actions
gtfparse-3.1.2.tar.gz 144.7 kB Without provenance Details for gtfparse-3.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gtfparse 3.1.2
File Interpreter ABI Platform Actions
gtfparse-3.1.2-py3-none-any.whl Python 3 none any Details for gtfparse-3.1.2-py3-none-any.whl

Total release size: 169.6 kB

Release files / gtfparse-3.1.2.tar.gz

Download URL gtfparse-3.1.2.tar.gz
Size 144.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7260a68d71706a40eb343ae306a595a0778ebc6b726391ee876b4bac2cf7dbe8
BLAKE2b-256 checksum
How to use checksums
7a4285555ad10bb1eb6a0e6beae3728afe309e90ae30cbce41d9fc99214f9155
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.6

Release files / gtfparse-3.1.2-py3-none-any.whl

Download URL gtfparse-3.1.2-py3-none-any.whl
Size 24.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3e67245d60f86c0b5ff61da9c09f2497a2c4447a5c9973d060152efdbabaa33b
BLAKE2b-256 checksum
How to use checksums
a45b3c2788c72deb1ad03650763cf523dadb3c07e6bbbe062098e88be02cabdd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.6

Security for gtfparse 3.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

3.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page