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.3.0

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.3.0
File Size Uploaded Provenance Actions
gtfparse-3.3.0.tar.gz 151.4 kB Without provenance Details for gtfparse-3.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 179.9 kB

Release files / gtfparse-3.3.0.tar.gz

Download URL gtfparse-3.3.0.tar.gz
Size 151.4 kB
Tags Source
SHA-256 checksum
How to use checksums
edd33315eea5a10634020aa8b5fe8dc3cf0189acb30b700f93c9c99727a1b451
BLAKE2b-256 checksum
How to use checksums
04c591b896e780058da6898f00e47251be8738b3ba66d2d6f5a62dc68a95db10
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.3.0-py3-none-any.whl

Download URL gtfparse-3.3.0-py3-none-any.whl
Size 28.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f34490ddc640fd494b5d110f085864e25a0fc2b327ffda655fbab474bad49f4f
BLAKE2b-256 checksum
How to use checksums
3ea8fb9654c54c01950f3acadafed6845478051d502b5cfda9be94ba4a966f6e
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.3.0

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.3.0 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