Skip to main content

annoyance - single-cell AnnData wrapper of Spotify's Annoy library.

Project description

logo

PyPI pyversions PyPI version Code style: black

annoy for the annotation of cell types.

Annoyance is a simple API for classifying cell types as annotated in an adata.obs table. An example notebook may be found here.

Overview

import annoyance
from anndata import read_h5ad

# load data
adata = read_h5ad("./data/pbmc3k.processed.h5ad")

Step 1. Instantiate the model and split the data on categorical labels

annoy = annoyance.SpotifyAnnoy()
annoy.split_data(
    adata, annot_col="Annotation", labels=["Monocyte", "Neutrophil"], on="X_pca"
)
label mask created:

CD4 T cells          1144
CD14+ Monocytes       480
B cells               342
CD8 T cells           316
NK cells              154
FCGR3A+ Monocytes     150
Dendritic cells        37
Megakaryocytes         15
Name: louvain, dtype: int64

Step 2. Build and evaluate the predictive model based on the data split

annoy.prebuild()
                   precision    recall  f1-score   support

          B cells       1.00      1.00      1.00        86
  CD14+ Monocytes       0.94      0.99      0.97       120
      CD4 T cells       0.98      0.98      0.98       286
      CD8 T cells       0.91      0.91      0.91        79
  Dendritic cells       1.00      0.67      0.80         9
FCGR3A+ Monocytes       0.95      0.95      0.95        37
   Megakaryocytes       1.00      0.75      0.86         4
         NK cells       0.97      0.95      0.96        39

         accuracy                           0.97       660
        macro avg       0.97      0.90      0.93       660
     weighted avg       0.97      0.97      0.96       660

Step 3. Build the classifier using all of the data then save the AnnoyIndex.

annoy.build()
annoy.save()
Annoyance annoy index saved to:

	annoyance_index/annoyance.annoy_idx.50_dims.20_neighbors.10_trees.ann
	annoyance_index/annoyance.annoy_idx.50_dims.20_neighbors.10_trees.txt

Installation

pip install annoyance

To install the development version

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

cd ./annoyance/
pip install -e .

Notes

This project uses open-source code from spotify/annoy. However, this repo is in no way affiliated with Spotify.

Interested? Questions and discussion may be directed to Michael Vinyard at: mvinyard@broadinstitute.org.

Project details


Download files

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

Source Distribution

annoyance-0.0.12.tar.gz (8.8 kB view hashes)

Uploaded Source

Built Distribution

annoyance-0.0.12-py3-none-any.whl (10.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page