🦠 denseclass
Nanopore signal classification — label every raw read by species, barcode or taxon, straight from the current, with no basecalling step.
📖 Table of Contents
- Overview
- Installation
- Quick start
- Subcommands
- Training modes
- Examples
- Relationship to densecall
- Development
🧬 Overview
Reads are trimmed to their informative region (adapter/polyA detection for DNA, poly(A)-tail trimming for RNA), encoded, and passed through a small 1-D CNN that predicts one class per read. Training works either on real labelled reads or on signal simulated from reference genomes, so you can build a classifier without per-species reads for every class.
This package was split out of DenseCall and now stands alone — see Relationship to densecall.
📦 Installation
git clone <this-repo>
cd denseclass
pip install -e .
torch is deliberately unpinned so the resolver picks a build matching your local
CUDA toolkit. For GPU basecalling-adjacent work, install the CUDA toolkit first and
verify nvcc is on $PATH:
conda install -c nvidia cuda-toolkit=12.8
🚀 Quick start
denseclass --help
denseclass label --help
🎯 Subcommands
| Subcommand | Purpose |
|---|---|
label |
Build label_map.json / inverse_label_map.json from a FASTA whose headers are the class names |
split |
Split a read→label pairs file into train / test sets |
gendata |
Convert POD5/FAST5 + labels into train.hdf5 / valid.hdf5 |
train |
Train the classification CNN (real or simulated data) |
predict |
Classify reads with a trained model |
precision |
One-class precision / recall / F1 / ROC evaluation |
evaluation |
Full multiclass panel (confusion matrix, PR/ROC, ...) |
comparison |
Side-by-side comparison of two models |
🧪 Training modes
| Mode | Description |
|---|---|
| Real-data | gendata extracts signal chunks from reads already labelled by species, then train (no --simu) fits the CNN directly. |
| Simulation | train --simu <refs.fa> --preset <name> synthesises chunks on the fly from a FASTA of reference genomes. Presets: dna-r9-min, dna-r10-min, rna-r9-min, rna004-min, ... |
The CNN architecture is set by a small TOML (dna.toml with strides=[2,2,2,2,2] for
DNA, rna.toml with strides=[5,2,2,2,2] for RNA) passed via -config. The
label_map.json / inverse_label_map.json pair must be produced first with
denseclass label.
🧪 Examples
Barcode / species classification on real reads
# 1. build the label map
denseclass label species.fa
# 2. split read→label pairs
denseclass split readid_species.txt --train_file train_labels.txt --test_file test_labels.txt
# 3. extract training chunks
denseclass gendata train.pod5 \
--label_path train_labels.txt --save_path ./ --seqlen 6000 --do-trim
# 4. train
denseclass train model_real \
-config dna.toml --directory ./ --label-map label_map.json \
--chunksize 6000 -f --new -y
# 5. predict
denseclass predict model_real test.pod5 inverse_label_map.json \
--chunksize 6000 > result_real.txt
# 6. evaluate
denseclass evaluation result_real.txt test_labels.txt \
-m label_map.json -o ./real
Simulation-based training (no real per-species data)
denseclass label species.fa
denseclass train model_simu \
-config dna.toml --directory ./ --label-map label_map.json \
--chunksize 25000 -f --new --simu species.fa --preset dna-r10-min -y
denseclass predict model_simu reads_dir/ inverse_label_map.json \
--chunksize 25000 > result_simu.txt
denseclass precision result_simu.txt test_labels.txt -m label_map.json
RNA direct-read classification
RNA reads are reverse-complement mapped and sequenced after the poly(A) tail, so
gendata / predict take --rna --tail, and RNA models use rna.toml:
denseclass gendata train.pod5 \
--label_path train_labels.txt --save_path ./ --rna --seqlen 50000 --tail
denseclass train model \
-config rna.toml --directory ./ --label-map label_map.json \
-f --new -y --chunksize 50000 --rna
denseclass predict model test.pod5 inverse_label_map.json \
--rna --tail --chunksize 50000 > result_real.txt
🔗 Relationship to densecall
This package was previously densecall classify, wrapping densecall/microbiome/.
It is now standalone:
- No
densecallimport anywhere. The one helper that used to be shared (convert_base_name) is vendored indenseclass/base_util.py. - Separate dependency set and release cycle. Install and upgrade it on its own.
- The trained
model/directory is a normal model directory and can be used with the DenseCall basecallingtrain/predicttooling where applicable.
Migration is a command rename:
| Before | After |
|---|---|
densecall classify label |
denseclass label |
densecall classify gendata |
denseclass gendata |
densecall classify train |
denseclass train |
densecall classify predict |
denseclass predict |
All flags are unchanged.
🛠 Development
pytest tests/ # structural checks: imports, CLI tree, packaging
The test suite is purely structural — it verifies that every module imports, the command tree builds and formats, and the packaging metadata is consistent. It needs no signal data or checkpoints. End-to-end behaviour is exercised through the examples above.
Publishing
# 1. bump __version__ in denseclass/cli.py
python -m build
twine check dist/* && twine upload dist/*
📄 License
MIT — see LICENCE.txt.
Metadata
Release files for denseclass 0.1.0
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 |
|---|---|---|---|---|
| denseclass-0.1.0.tar.gz | 58.5 kB | Without provenance | Details for denseclass-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| denseclass-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for denseclass-0.1.0-py3-none-any.whl |
Total release size: 115.3 kB
Release files / denseclass-0.1.0.tar.gz
| Download URL | denseclass-0.1.0.tar.gz |
|---|---|
| Size | 58.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
81b7e1b48362e02559591792e9dc2cdc0dd04410b490e731b523472efd5dd645
|
|
BLAKE2b-256 checksum How to use checksums |
981f4ea0220a0665bb2a1c6c75bf7b6a7c0b6a212fb013e80ea35e3455389836
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.19
|
Release files / denseclass-0.1.0-py3-none-any.whl
| Download URL | denseclass-0.1.0-py3-none-any.whl |
|---|---|
| Size | 56.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d8697f9a23226dbaef1d08de527b1d7121a72018ffb3746f54d923ace3bededb
|
|
BLAKE2b-256 checksum How to use checksums |
4f86a160e3bb51494388baf4f43fb42c9c7324808b3c90651771b7bfd1ee3bb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.19
|
Security for denseclass 0.1.0
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.