gtfparse
Read GTF (gene transfer format) annotations into a pandas DataFrame, with one row per feature and attribute values such as gene and transcript IDs expanded into columns.
Install
python -m pip install gtfparse
Python 3.9 or later is required. For optional Polars output, install
gtfparse[polars].
Read an annotation and find genes
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.
Documentation
- Filter features, select chromosomes, write GTF and read numeric attributes
- Progress callbacks
- Version 3 migration and optional Polars output
- Complete API reference
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.
Metadata
Release files for gtfparse 3.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gtfparse-3.0.4.tar.gz | 142.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gtfparse-3.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 165.3 kB
Release files / gtfparse-3.0.4.tar.gz
| Download URL | gtfparse-3.0.4.tar.gz |
|---|---|
| Size | 142.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cb18b5180fa0e0bf0009722ed7595e27ac0a2809699d62dbc1f02f8cfe29dd42
|
|
BLAKE2b-256 checksum How to use checksums |
ebafa3fbf5ad14e0dac8e4de0b4faeadef42fa052d9e11c0dd03a95b37e5e12b
|
| 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.0.4-py3-none-any.whl
| Download URL | gtfparse-3.0.4-py3-none-any.whl |
|---|---|
| Size | 23.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c942c1a3a392006a623335e8da40013448aa121bd5744d6b0c0e1bd80852bd7b
|
|
BLAKE2b-256 checksum How to use checksums |
9d9563ac2ae21a212c4adc517542c78ee5c698bc8b795797c94d31201bdc76f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.6
|