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.3.2.tar.gz (282.3 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.3.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (957.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

phylotypy-0.3.2-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (919.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ i686manylinux: glibc 2.5+ i686

phylotypy-0.3.2-cp313-cp313-macosx_10_13_universal2.whl (503.8 kB view details)

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

phylotypy-0.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (971.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

phylotypy-0.3.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (936.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ i686manylinux: glibc 2.5+ i686

phylotypy-0.3.2-cp312-cp312-macosx_10_13_universal2.whl (506.0 kB view details)

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

phylotypy-0.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (953.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

phylotypy-0.3.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (920.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ i686manylinux: glibc 2.5+ i686

phylotypy-0.3.2-cp311-cp311-macosx_10_9_universal2.whl (508.1 kB view details)

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

File details

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

File metadata

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

File hashes

Hashes for phylotypy-0.3.2.tar.gz
Algorithm Hash digest
SHA256 c523e1657b4d85ce9cc1557dd78ba4312f5ba1073fe431320938fe6edbb63ca5
MD5 994d98bbd3dc2ab0babacd87b4829b68
BLAKE2b-256 fba38a77557904e6881d16fffa1c289dbd51a74806a5c17a562ff42f228e388a

See more details on using hashes here.

Provenance

The following attestation bundles were made for phylotypy-0.3.2.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.3.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for phylotypy-0.3.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 29999218c80db389b3e841d63a60a69e8f08e50f57180e45023b8c8664bd9b6c
MD5 c131a029e2023068e627038330a9e466
BLAKE2b-256 645d09491585aee30b0ccbb9bcf79be99e0dcd43807d0b6e7248c611a812c989

See more details on using hashes here.

Provenance

The following attestation bundles were made for phylotypy-0.3.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.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.3.2-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for phylotypy-0.3.2-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 87cda1f2f7a16affcf10fecc6e2f36ce37a34cdce65fbf37f3b999edc1cea365
MD5 318303a49babf68db62dfd8a7dfeade6
BLAKE2b-256 408b1428514970c18d9d73c0800f52af5cc4a54245ee18d51ad4e4a2370e3883

See more details on using hashes here.

Provenance

The following attestation bundles were made for phylotypy-0.3.2-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.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.3.2-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for phylotypy-0.3.2-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 75aa95f167c81f84ca897027bc94eec29437f910633d9945eacbc52ff743576e
MD5 93ceb3ab43e807d2e186df0dafe7d9c7
BLAKE2b-256 80bafb2623237ddd0ca2ae7001da7008fbec2b1e2e2c9cd65aa7f8ea60cb69c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for phylotypy-0.3.2-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.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for phylotypy-0.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 704dc74d06415b1320759e1d46386cad73732003ce1ca85a6cbfd3666b29ff80
MD5 ba6d249bc5cd30032139b83edb2de2e1
BLAKE2b-256 f8bfd214183f84f865f5119ba5f3c6d0126b2930d3e53c0c5ebb09608639570c

See more details on using hashes here.

Provenance

The following attestation bundles were made for phylotypy-0.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.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.3.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for phylotypy-0.3.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b23ebfaf8e4fe45d761ded741c8fc528bd14f6c4941acedbe98947f21f69dc36
MD5 2e68f60db30524e57b370219ac7295cb
BLAKE2b-256 a5e922d45c44c483ba71cf64329ab27dded95097f20805adfdaaebf026d279c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for phylotypy-0.3.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.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.3.2-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for phylotypy-0.3.2-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 402784a5db2a03d4182916cf21d526553adbeec96deb6bfba091dd4ffd125d19
MD5 4b9ac6d53ae00e3e9ea05b253ab396ed
BLAKE2b-256 01b7b00331e724443b170026935a0ae944f8f2b8737d1670a7a93ec728587c79

See more details on using hashes here.

Provenance

The following attestation bundles were made for phylotypy-0.3.2-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.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for phylotypy-0.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 274f3be3783437636ab6fde06698f4a9db21e0209decbef635650b63eddbd7f8
MD5 d1eb8a3fa332ca50b529d523cde74c67
BLAKE2b-256 0c5099820659855be6f4d759b3855d6c7dee8c8ef3be40f28b2ecbe493a45c84

See more details on using hashes here.

Provenance

The following attestation bundles were made for phylotypy-0.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.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.3.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for phylotypy-0.3.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b4d15f8cad6a526e405c5d11696e177603acdb137bc100d53867f00999e70186
MD5 2bfab00555338629ba2cfee0562616ef
BLAKE2b-256 c614d58b7558ab56de851fec7fb4042d69dce3f93f710419b057f5e0a7245ab4

See more details on using hashes here.

Provenance

The following attestation bundles were made for phylotypy-0.3.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.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.3.2-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for phylotypy-0.3.2-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 92da960a6a3f10d5fe1d53d8c97dece72dcf19f82a4e89b70dba088076947e90
MD5 ef1f3bb86d7348ec0141824b37efa8b7
BLAKE2b-256 8ecd0f74e77b6b0c5e19defb42d8de2ac38e825d306a913fc9ce5786a4017686

See more details on using hashes here.

Provenance

The following attestation bundles were made for phylotypy-0.3.2-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