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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

anngtf-0.0.11.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

anngtf-0.0.11-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file anngtf-0.0.11.tar.gz.

File metadata

  • Download URL: anngtf-0.0.11.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for anngtf-0.0.11.tar.gz
Algorithm Hash digest
SHA256 8519d34018305c1f026999846247f8e40c6c3785e14708f64a066c538682d81c
MD5 8f4577705a8b740ed63f69102c2b7789
BLAKE2b-256 022a6a18732e1589bda2c850975d4342179adadf879c58c9a452bc9c8417fec9

See more details on using hashes here.

File details

Details for the file anngtf-0.0.11-py3-none-any.whl.

File metadata

  • Download URL: anngtf-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for anngtf-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 c8b891c124b2ed15398c0f7491d5ddc4c21ca2f4df8c9abb9604130a7f4505a4
MD5 a3c5cd074b93fc3cf030ffdf5f366091
BLAKE2b-256 eb1a96393673d5ce9707b872d6625a8cd7ef4f0f515210d3eb17957cc49f7a7a

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.11 This release

2 files

0.0.1

2 files

0.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page