Skip to main content

anngtf

PyPI pyversions PyPI version Code style: black

Lift annotations from a gtf to your adata object.

Installation

To install via pip:

pip install anngtf

To install the development version:

git clone https://github.com/mvinyard/anngtf.git

cd anngtf; pip install -e .

Example usage

Parsing a .gtf file

import anngtf

gtf_filepath = "/path/to/ref/hg38/refdata-cellranger-arc-GRCh38-2020-A-2.0.0/genes/genes.gtf"

If this is your first time using anngtf, run:

gtf = anngtf.parse(path=gtf_filepath, genes=False, force=False, return_gtf=True)

Running this function will create two .csv files from the given .gtf files - one containing all feature types and one containing only genes. Both of these files are smaller than a .gtf and can be loaded into memory much faster using pandas.read_csv() (shortcut implemented in the next function). Additionally, this function leaves a paper trail for anngtf to find the newly-created .csv files again in the future such that one does not need to pass a path to the gtf.

In the scenario in which you've already run the above function, run:

gtf = anngtf.load() # no path necessary! 

Updating the adata.var table.

import anndata as a
import anngtf

adata = anndata.read_h5ad("/path/to/singlecell/data/adata.h5ad")
gtf = anngtf.load(genes=True)

anngtf.add(adata, gtf)

Since the anngtf distribution already knows where the .csv / .gtf files are, we could directly annotate adata without first specifcying gtf as a DataFrame, saving a step but I think it's more user-friendly to see what each one looks like, first.

Working advantage

Let's take a look at the time difference of loading a .gtf into memory as a pandas.DataFrame:

import anngtf
import gtfparse
import time

start = time.time()
gtf = gtfparse.read_gtf("/home/mvinyard/ref/hg38/refdata-cellranger-arc-GRCh38-2020-A-2.0.0/genes/genes.gtf")
stop = time.time()

print("baseline loading time: {:.2f}s".format(stop - start), end='\n\n')

start = time.time()
gtf = anngtf.load()
stop = time.time()

print("anngtf loading time: {:.2f}s".format(stop - start))
baseline loading time: 87.54s

anngtf loading time: 12.46s

~ 7x speed improvement.

  • Note: This is not meant to criticize or comment on anything related to gtfparse - in fact, this library relies solely on gtfparse for the actual parsing of a .gtf file into memory as pandas.DataFrame.

Metadata

Release files for anngtf 0.0.11

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

Source distribution (sdist)

Source distribution for anngtf 0.0.11
File Size Uploaded
anngtf-0.0.11.tar.gz 4.9 kB Details

Built distribution (wheel)

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

Total release size: 10.6 kB

Release files / anngtf-0.0.11.tar.gz

Download URL anngtf-0.0.11.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8519d34018305c1f026999846247f8e40c6c3785e14708f64a066c538682d81c
BLAKE2b-256 checksum
How to use checksums
022a6a18732e1589bda2c850975d4342179adadf879c58c9a452bc9c8417fec9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

Release files / anngtf-0.0.11-py3-none-any.whl

Download URL anngtf-0.0.11-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c8b891c124b2ed15398c0f7491d5ddc4c21ca2f4df8c9abb9604130a7f4505a4
BLAKE2b-256 checksum
How to use checksums
eb1a96393673d5ce9707b872d6625a8cd7ef4f0f515210d3eb17957cc49f7a7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

Release history Release notifications | RSS feed

This release

0.0.11 This release

2 release files

0.0.1

2 release files

0.0.0

2 release files

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