Naive Bayes Classifier for 16S rRNA sequence data
Project description
phylotypy
A Naive Bayesian Classifier for 16S rRNA gene sequences, inspired by the phylotypr R package by Riffomonas. Designed for classifying amplicon sequence variants (ASVs) from DADA2, QIIME2, or raw FASTA files against a reference database of 16S rRNA sequences. The RDP training data is provided here in the data directory located at the github repository. But Silva and others can be used.
Thanks to Riffomonas for the inspiration — check out the videos on his YouTube channel.
Performance
Training on the full RDP reference database takes ~30 seconds on a 2020 Apple Intel MacBook Pro. Newer systems should see a substantial increase in performance.
How to Install
Using pip:
pip install phylotypy
Using uv (recommended — how to install uv):
uv pip install phylotypy
Training Data
Download the RDP reference training set and an example dataset before classifying:
| File | Description |
|---|---|
| rdp_16S_v19.dada2.fasta | RDP trainset19072023, DADA2 format |
| dna_moving_pictures.fasta | Example dataset (Moving Pictures study) |
| The training data fasta descriptions should a taxonomy. By default the Species level is ignored. |
"Kingdom", "Phylum", "Class", "Order", "Family", "Genus", "Species"
The taxon string in the fasta description should follow the semicolon-separated format like this:
>Bacteria;Pseudomonadota;Gammaproteobacteria;Enterobacterales;Enterobacteriaceae;Citrobacter
TAGAGTTTGATCCATGGCTCAGATTGAACGCTGGCGGCAGGCCTAACAC.....
Quick Start
1. Load training data and sequences to classify
from phylotypy import classifier, results, read_fasta
rdp = read_fasta.read_taxa_fasta("rdp_16S_v19.dada2.fasta")
moving_pics = read_fasta.read_taxa_fasta("dna_moving_pictures.fasta")
2. Train the classifier
database = classifier.make_classifier(rdp)
3. Classify sequences
classified = classifier.classify_sequences(moving_pics, database)
4. Format and export results
classified = results.summarize_predictions(classified)
print(classified.columns)
Output:
Index(['id', 'sequence', 'classification', 'Kingdom', 'Phylum', 'Class',
'Order', 'Family', 'Genus', 'observed', 'lineage'],
dtype='object')
classified.to_csv("classified_results.csv")
Complete Code Block
from phylotypy import classifier, results, read_fasta
rdp = read_fasta.read_taxa_fasta("rdp_16S_v19.dada2.fasta")
moving_pics = read_fasta.read_taxa_fasta("dna_moving_pictures.fasta")
database = classifier.make_classifier(rdp)
classified = classifier.classify_sequences(moving_pics, database)
classified = results.summarize_predictions(classified)
print(classified.head())
classified.to_csv("classified_results.csv")
Example Classification Output
Taxonomic levels (Domain → Genus) are semicolon-separated. Numbers in parentheses represent bootstrap confidence scores. The default confidence threshold is 80%.
Bacteria(100);Pseudomonadota(99);Alphaproteobacteria(99);Rhodospirillales(99);Acetobacteraceae(99);Roseomonas(83)
Bacteria(99);Bacteroidota(97);Bacteroidia(93);Bacteroidales(93);Bacteroidales_unclassified(93);Bacteroidales_unclassified(93)
Bacteria(100);Bacteroidota(100);Bacteroidia(100);Bacteroidales(100);Bacteroidaceae(100);Bacteroides(100)
Working with Your Own Data
phylotypy works with FASTA files from DADA2, QIIME2, or any standard pipeline. See read_fasta.py for utilities to load and convert sequence data into the required format.
A complete walkthrough is available in vignette.py.
Requirements
Dependencies are installed automatically via pip. See pyproject.toml for the full list.
Citation
If you use phylotypy in your research, please cite:
- Wang, Q., Garrity, G.M., Tiedje, J.M., Cole, J.R. (2007) Naive Bayesian Classifier for Rapid Assignment of rRNA Sequences into the New Bacterial Taxonomy. Applied and Environmental Microbiology, 73(16), 5261–5267.
- Schloss PD.2025.phylotypr: an R package for classifying DNA sequences. Microbiol Resour Announc14:e01144-24.https://doi.org/10.1128/mra.01144-24
- Saltikov, C. (2024) phylotypy: Python implementation of a Naive Bayesian 16S rRNA classifier. https://github.com/csaltikov/phylotypy
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file phylotypy-0.2.3.tar.gz.
File metadata
- Download URL: phylotypy-0.2.3.tar.gz
- Upload date:
- Size: 270.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0a6843b8bc2ccf775e495975343d8cb6282ddd310fe2fcfddc31b332cc7048b
|
|
| MD5 |
49c853055c42c9ecbd2c286afcae0ed3
|
|
| BLAKE2b-256 |
9229c6ba40620e8ed5e271ab6ee6a0dee6c7cec29de1a13f31b1b99e8bd06e69
|
Provenance
The following attestation bundles were made for phylotypy-0.2.3.tar.gz:
Publisher:
python-publish.yml on csaltikov/phylotypy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
phylotypy-0.2.3.tar.gz -
Subject digest:
c0a6843b8bc2ccf775e495975343d8cb6282ddd310fe2fcfddc31b332cc7048b - Sigstore transparency entry: 1078507779
- Sigstore integration time:
-
Permalink:
csaltikov/phylotypy@8922ba6470b1fbd991adb1b2c524897ee8fcf310 -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/csaltikov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@8922ba6470b1fbd991adb1b2c524897ee8fcf310 -
Trigger Event:
release
-
Statement type:
File details
Details for the file phylotypy-0.2.3-cp312-cp312-macosx_10_13_universal2.whl.
File metadata
- Download URL: phylotypy-0.2.3-cp312-cp312-macosx_10_13_universal2.whl
- Upload date:
- Size: 477.4 kB
- Tags: CPython 3.12, macOS 10.13+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
811cd649bea7214d21eff1ae9835d3c89627717d20ba23c56b93fc6751157807
|
|
| MD5 |
78650e094dc0c534a4624c762e26338e
|
|
| BLAKE2b-256 |
f48243e9e50963fb29c4e5627359062d70b695e7bd63c816e215ab0274994459
|
Provenance
The following attestation bundles were made for phylotypy-0.2.3-cp312-cp312-macosx_10_13_universal2.whl:
Publisher:
python-publish.yml on csaltikov/phylotypy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
phylotypy-0.2.3-cp312-cp312-macosx_10_13_universal2.whl -
Subject digest:
811cd649bea7214d21eff1ae9835d3c89627717d20ba23c56b93fc6751157807 - Sigstore transparency entry: 1078507815
- Sigstore integration time:
-
Permalink:
csaltikov/phylotypy@8922ba6470b1fbd991adb1b2c524897ee8fcf310 -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/csaltikov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@8922ba6470b1fbd991adb1b2c524897ee8fcf310 -
Trigger Event:
release
-
Statement type:
File details
Details for the file phylotypy-0.2.3-cp311-cp311-macosx_10_9_universal2.whl.
File metadata
- Download URL: phylotypy-0.2.3-cp311-cp311-macosx_10_9_universal2.whl
- Upload date:
- Size: 477.0 kB
- Tags: CPython 3.11, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eadec1f38075b6d913b9b2994559632b30865693da11d58a29ef4badd447fbe3
|
|
| MD5 |
fe2a1eaf124b74fb4cb9f72e9ce2fae4
|
|
| BLAKE2b-256 |
574c080953757ba3943393303b752a7941bfacb772941428eb1c59895b38fd57
|
Provenance
The following attestation bundles were made for phylotypy-0.2.3-cp311-cp311-macosx_10_9_universal2.whl:
Publisher:
python-publish.yml on csaltikov/phylotypy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
phylotypy-0.2.3-cp311-cp311-macosx_10_9_universal2.whl -
Subject digest:
eadec1f38075b6d913b9b2994559632b30865693da11d58a29ef4badd447fbe3 - Sigstore transparency entry: 1078507799
- Sigstore integration time:
-
Permalink:
csaltikov/phylotypy@8922ba6470b1fbd991adb1b2c524897ee8fcf310 -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/csaltikov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@8922ba6470b1fbd991adb1b2c524897ee8fcf310 -
Trigger Event:
release
-
Statement type: