# nimble raccoon
A slim and fast reimplementation of [RACCOON](https://github.com/shlienlab/raccoon) (Resolution-Adaptive Coarse-to-fine Clusters OptimizatiON), iterative clustering library for python 3.
<!– <img src=”docs/figs/sps_logo.png” width=400, padding=100> [](https://zenodo.org/badge/latestdoi/91130860) [](https://badge.fury.io/py/simpsom) [](https://simpsom.readthedocs.io/en/latest/?badge=latest)  [](https://codecov.io/gh/fcomitani/simpsom) –>
It relies on [faiss](https://github.com/facebookresearch/faiss) for quick nearest neighbors searches and better memory management, but offers fewer functionalities, only allowing cosine and euclidean distances, Louvain as its clustering algorithm, and grid search.
## Installation
nimble-raccoon can be installed with pip with the following command
pip install nimble-raccoon
<!– For the GPU-enable version, clone this repo and install add the -gpu flag –>
## Usage
To identify clusters and build the hierarchy initialize a Raccoon object with set parameters and then call it on the input_data object, a pandas dataframe.
import numpy as np from functools import partial
from nimbloon import Raccoon
You can define custom functions to dynamically adapt the search range to the size of the dataset.
- def half_sqrt_range(x, num_elements=5):
sq = np.sqrt(x) return np.linspace(sq/2, sq, num_elements, dtype=int)
- rc_args = {‘metric’: ‘cosine’,
‘scale’: False, ‘cumulative_variance’: [.75, .8, .9, .95, .99], ‘clustering_parameter’: np.logspace(-2, 1.5, 10), ‘n_neighbors’: partial(half_sqrt_range, num_elements=3), ‘target_dimensions’: 12, ‘min_cluster_size’: 25, ‘max_neighbors’: 100, ‘silhouette_threshold’: 0., ‘max_depth’: 5}
Once everything is set up you can instantiate the Raccoon object.
rc = Raccoon(outh_path=’./rc_output’, **rc_args)
And then call it on the input dataset to build the clusters hierarchy.
rc_labels, rc_tree = rc(input_table)
Available parameters are:
metric: the distance metric, currently only cosine and euclidean can be set as metrics.
scale: scale features at every iteration.
- cumulative_variance: the limit of cumulative variance for low-information
features removal with tSVD. Can be a single float or a list of float
- clustering_parameter: the range of resolutions for the Louvain clustering
algorithm. Can be a single float or a list of float
- n_neighbors: the number of nearest neighbors to use across the search.
Can be a single int or a list of int. Can also be a function, in which case this will be applied to the input set size, adapting this parameter at each iteration.
- target_dimensions: the dimensionality of the target space after
applying UMAP.
- min_cluster_size: minimum size of clusters, if a cluster is identified
with size below this threshold, it will not be further split.
- max_neighbors: maximum number of neighbors, useful when n_neighbors is
dynamic and population dependent avoiding excessively costly operations for large datasets.
- silhouette_threshold: minimum silhouette score value to reach for a
partition to be accepted.
max_depth: maximum depth of the clusters hierarchy.
The output will be a one-hot-encoded dataframe with samples as rows and cluster labels as columns, and an anytree object with information on the hierarchical relationship among clusters. This information will also be automatically saved to disk in the out_path folder.
Both tSVD and UMAP steps can be skipped, by setting cumulative_variance to 1 and/or target_dimensions to None respectively.
## Citation
If you are using this library for your work, please cite the original RACCOON publication.
> Comitani, F., Nash, J.O., Cohen-Gogo, S. et al. Diagnostic classification of childhood cancer using multiscale transcriptomics. Nat Med 29, 656–666 (2023). https://doi.org/10.1038/s41591-023-02221-x
## Contributions
Contributions are always welcome. If you would like to help us improve this library please fork the main branch and make sure pytest pass after your changes.
Metadata
Release files for nimble-raccoon 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nimble-raccoon-0.1.1.tar.gz | 24.7 kB | Without provenance | Details for nimble-raccoon-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nimble_raccoon-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for nimble_raccoon-0.1.1-py3-none-any.whl |
Total release size: 49.2 kB
Release files / nimble-raccoon-0.1.1.tar.gz
| Download URL | nimble-raccoon-0.1.1.tar.gz |
|---|---|
| Size | 24.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fdfff58f33cb899c1402966224dc9b2f9c1887b93faa64bd395ea9c432884f25
|
|
BLAKE2b-256 checksum How to use checksums |
129315916710b02fdfbb6a41584c6360b677231676e8de8683dcdf7fcd3245d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / nimble_raccoon-0.1.1-py3-none-any.whl
| Download URL | nimble_raccoon-0.1.1-py3-none-any.whl |
|---|---|
| Size | 24.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
056604f5f872f832c7198e04ddbb235e35d190f29766e04ce7fa56db7c0b6d43
|
|
BLAKE2b-256 checksum How to use checksums |
682a34e2b897f7339d044b7f3a72e07492950a5ee76437180b0560125cda4427
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Security for nimble-raccoon 0.1.1
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.