Skip to main content

Naive Bayes Classifier for 16S rRNA sequence data

Project description

phylotypy

PyPI version Python 3.11+ License: MIT

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

Note: Intel Mac (x86_64) users are limited to numba 0.62.1, which is pinned in this package. Apple Silicon (M-series) users are not affected.


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


Download files

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

Source Distribution

phylotypy-0.2.6.tar.gz (271.4 kB view details)

Uploaded Source

Built Distributions

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

phylotypy-0.2.6-cp313-cp313-macosx_10_13_universal2.whl (474.7 kB view details)

Uploaded CPython 3.13macOS 10.13+ universal2 (ARM64, x86-64)

phylotypy-0.2.6-cp312-cp312-macosx_10_13_universal2.whl (477.6 kB view details)

Uploaded CPython 3.12macOS 10.13+ universal2 (ARM64, x86-64)

phylotypy-0.2.6-cp311-cp311-macosx_10_9_universal2.whl (477.2 kB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)

File details

Details for the file phylotypy-0.2.6.tar.gz.

File metadata

  • Download URL: phylotypy-0.2.6.tar.gz
  • Upload date:
  • Size: 271.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for phylotypy-0.2.6.tar.gz
Algorithm Hash digest
SHA256 594d26ca5ea3d2ce382f65e850926ea7ff2416c34cba9ebab4c4a828a92b5f6d
MD5 3682c6d0fd1ac5e2e4419272155932ab
BLAKE2b-256 2a4f239e52d6ce7b7cdea690b08db326ca835827867736389864f4f35f39c41d

See more details on using hashes here.

Provenance

The following attestation bundles were made for phylotypy-0.2.6.tar.gz:

Publisher: python-publish.yml on csaltikov/phylotypy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file phylotypy-0.2.6-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for phylotypy-0.2.6-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 21b7d10918993fa07e8c4c5111878ea0089fc358c49db2545d75912c677bf1f5
MD5 5ea38503a7e06e6b2735a1d53151ad84
BLAKE2b-256 ee4f0886256df5ee0783c0da2e0e81aa66261177d32c846190545d6d70b46205

See more details on using hashes here.

Provenance

The following attestation bundles were made for phylotypy-0.2.6-cp313-cp313-macosx_10_13_universal2.whl:

Publisher: python-publish.yml on csaltikov/phylotypy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file phylotypy-0.2.6-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for phylotypy-0.2.6-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 6357ff7ef7d90aee4ddb840268a2037c5076145ee4303be9ef088555f5d88871
MD5 369bf0c54a0de099c80fe97925ed5d91
BLAKE2b-256 49b0fad2079769e4c41524e09286c6eefcf35c6d2c1a7914ba6b9d80a4510067

See more details on using hashes here.

Provenance

The following attestation bundles were made for phylotypy-0.2.6-cp312-cp312-macosx_10_13_universal2.whl:

Publisher: python-publish.yml on csaltikov/phylotypy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file phylotypy-0.2.6-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for phylotypy-0.2.6-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 f1c6dd38feb11b7f41f690de97a694033ec8e3e7868119d0db01aa30b80eb0c2
MD5 370ee0e5725fd51160153051ac874b65
BLAKE2b-256 e41c799fa608b30d512cc27910076c0f3ecf7b172e9b3ed03894ec2df72c3502

See more details on using hashes here.

Provenance

The following attestation bundles were made for phylotypy-0.2.6-cp311-cp311-macosx_10_9_universal2.whl:

Publisher: python-publish.yml on csaltikov/phylotypy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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