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.3.tar.gz (281.8 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.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (955.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

phylotypy-0.3.3-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (918.9 kB view details)

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

phylotypy-0.3.3-cp313-cp313-macosx_10_13_universal2.whl (503.6 kB view details)

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

phylotypy-0.3.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (970.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

phylotypy-0.3.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (934.6 kB view details)

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

phylotypy-0.3.3-cp312-cp312-macosx_10_13_universal2.whl (505.8 kB view details)

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

phylotypy-0.3.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (953.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

phylotypy-0.3.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (920.5 kB view details)

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

phylotypy-0.3.3-cp311-cp311-macosx_10_9_universal2.whl (507.9 kB view details)

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

File details

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

File metadata

  • Download URL: phylotypy-0.3.3.tar.gz
  • Upload date:
  • Size: 281.8 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.3.tar.gz
Algorithm Hash digest
SHA256 eeca3d957944270505a7769d4dad05529a62f90fcc83f3f19bc022e1555c8900
MD5 47aef46c354275819fb3999bb534b10d
BLAKE2b-256 13aade4e2347730605d847bff53fad0fd9fa63620e728aefe69c52182c38ba17

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for phylotypy-0.3.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1a7e4f929e27736f45b37f17aee6243e84fd36d6274e0b0dfe338234fb113ae2
MD5 720d91421aea360920e68d582371a869
BLAKE2b-256 24e3558b3b89706e3197e44e1b18cc8afcdfe86e40eff6b736cfadb61c61d79a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for phylotypy-0.3.3-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 2b70a188135a10ddcd05fa2bf72d0f9abdef758e3e099f7f615e636d0f9af166
MD5 d1c6b14c00089059ba920e4648410219
BLAKE2b-256 a45412c66c6f5ade5d6beb953eeb40f8ff16d77a3c99982d2346d09f090b2eea

See more details on using hashes here.

Provenance

The following attestation bundles were made for phylotypy-0.3.3-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.3-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for phylotypy-0.3.3-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 092530fae4badbe06d6b06731c2c56925939293837a09bad82816c6d49ec2f4f
MD5 f29d6bb0db3a42527e7163fa75dad2eb
BLAKE2b-256 2dbab3b38143cb8ec40021700a43755e93eab92c7f6be60b78334912fe4093bf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for phylotypy-0.3.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1e621e9026043d578e8745e0779dbcd5742772d22cf9395d21b159b4276ad7e6
MD5 619b252774e70a29dfc5d02186d96167
BLAKE2b-256 0209f1e36eb8e73259387512081f51bb0dbec19060ac976ce4ab399a8fd80667

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for phylotypy-0.3.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 6d5abb55c52b8f56d09ccdcfce15c1170a8116a6aa0cc8c1197e2f63a285a276
MD5 16662ffb84c8e3e399872fea03de461c
BLAKE2b-256 d84e65c2195cc36fd09ed8d4cedc770ac469d56237323c19c07196984cf10e82

See more details on using hashes here.

Provenance

The following attestation bundles were made for phylotypy-0.3.3-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.3-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for phylotypy-0.3.3-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 5f2aa52bb1200470471bd9fc0b170da56dbd9003f01a93936de7f7184261676d
MD5 e0936a6b1b7955d53aaa41b8ff7e3f16
BLAKE2b-256 303a39097a920c8fefee91572c6dd12ced82308cef4895bc7b0fa88f82404d20

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for phylotypy-0.3.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 01d50f44e243ff9552a315074f96a025b8fdb77c50d07ba599dad9a2e7c26e28
MD5 40b877c0653bf3f6f35426ad5e612bff
BLAKE2b-256 5235b10a190f556efab743b839319ab5d681a4896344f8ad2a519a1df0a1ae9e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for phylotypy-0.3.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 9a4f3b89b8fc634380405adc6e193fc487751ebd311ecd609b5c004726659072
MD5 c9c5805749ffcabe8cf10ac212509f27
BLAKE2b-256 3230d43c320e80039994472bea643792343954ddd2d9ae05bf1236f471caa78d

See more details on using hashes here.

Provenance

The following attestation bundles were made for phylotypy-0.3.3-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.3-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for phylotypy-0.3.3-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 e742156bc5f7682ac0a448fa0093a1818426bd5d28769ab10a11d05b34897905
MD5 c42d33446ef5473b1fcb4709ac570a3b
BLAKE2b-256 0ee5c946851b368ba9feca5ed708b6bfff35b597ce8108dd5ded0435c16ef39f

See more details on using hashes here.

Provenance

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