| Title: | Interface to the RDP Classifier |
|---|---|
| Description: | This package installs and interfaces the naive Bayesian classifier for 16S rRNA sequences developed by the Ribosomal Database Project (RDP). With this package the classifier trained with the standard training set can be used or a custom classifier can be trained. |
| Authors: | Michael Hahsler [aut, cre] (ORCID: <https://orcid.org/0000-0003-2716-1405>), Nagar Anurag [aut] |
| Maintainer: | Michael Hahsler <[email protected]> |
| License: | GPL-2 |
| Version: | 2.0.0 |
| Built: | 2026-10-02 00:06:30 UTC |
| Source: | https://github.com/mhahsler/rRDP |
Calculate the classification accuracy at a given phylogenetic level.
accuracy(actual, predicted, rank) confusionTable(actual, predicted, rank)accuracy(actual, predicted, rank) confusionTable(actual, predicted, rank)
actual |
data.frame with the actual classification hierarchy. |
predicted |
data.frame with the predicted classification hierarchy. |
rank |
rank at which the accuracy should be evaluated. |
The accuracy or a confusion table.
## Not run: classifier <- rdp() seq <- readRNAStringSet(system.file("examples/RNA_example.fasta", package = "rRDP" )) ### decode the actual classification actual <- decode_Greengenes(names(seq)) ### use RDP to predict the classification pred <- predict(classifier, seq) ### calculate accuracy confusionTable(actual, pred, "genus") accuracy(actual, pred, "genus") ## End(Not run)## Not run: classifier <- rdp() seq <- readRNAStringSet(system.file("examples/RNA_example.fasta", package = "rRDP" )) ### decode the actual classification actual <- decode_Greengenes(names(seq)) ### use RDP to predict the classification pred <- predict(classifier, seq) ### calculate accuracy confusionTable(actual, pred, "genus") accuracy(actual, pred, "genus") ## End(Not run)
Functions to represent, decode and encode phylogenetic classification annotations used in FASTA files by RDP and the Greengenes project.
decode_Greengenes(annotation) GenClass16S( Kingdom = NA, Phylum = NA, Class = NA, Order = NA, Family = NA, Genus = NA, Species = NA, Otu = NA, Org_name = NA, Id = NA ) encode_Greengenes(classification) decode_RDP(annotation) encode_RDP(classification)decode_Greengenes(annotation) GenClass16S( Kingdom = NA, Phylum = NA, Class = NA, Order = NA, Family = NA, Genus = NA, Species = NA, Otu = NA, Org_name = NA, Id = NA ) encode_Greengenes(classification) decode_RDP(annotation) encode_RDP(classification)
annotation |
Annotation from a FASTA file containing the classification information. |
Kingdom |
Name of the kingdom to which the organism belongs. |
Phylum |
Name of the phylum to which the organism belongs. |
Class |
Name of the class to which the organism belongs. |
Order |
Name of the order to which the organism belongs. |
Family |
Name of the family to which the organism belongs. |
Genus |
Name of the genus to which the organism belongs. |
Species |
Name of the species to which the organism belongs. |
Otu |
Name of the otu to which the organism belongs. |
Org_name |
Name of the organism. |
Id |
ID of the sequence. |
classification |
A |
GenClass16S() and decodeX() return a
data.frame. encodeX() returns a string with the corresponding
annotation.
seq <- readRNAStringSet(system.file("examples/RNA_example.fasta", package = "rRDP" )) ### the FASTA annotation is read as names. This data has a Greengenes format ### annotation names(seq) classification <- decode_Greengenes(names(seq)) classification ### look at the Genus of all sequences classification[, "Genus"] ### to train the RDP classifier, the annotations need to be in RDP format annotation <- encode_RDP(classification) names(seq) <- annotation seq ### now we can train the classifier customRDP <- trainRDP(seq, dir = "sample_classifier") customRDP ## clean up removeRDP(customRDP)seq <- readRNAStringSet(system.file("examples/RNA_example.fasta", package = "rRDP" )) ### the FASTA annotation is read as names. This data has a Greengenes format ### annotation names(seq) classification <- decode_Greengenes(names(seq)) classification ### look at the Genus of all sequences classification[, "Genus"] ### to train the RDP classifier, the annotations need to be in RDP format annotation <- encode_RDP(classification) names(seq) <- annotation seq ### now we can train the classifier customRDP <- trainRDP(seq, dir = "sample_classifier") customRDP ## clean up removeRDP(customRDP)
RDP is a naive Bayes classifier for biological sequences using 8-mers as features. Use the RDP classifier (Wang et al, 2007) to classify 16S rRNA sequences. This package contains currently RDP version 2.14 released in August 2023.
rdp(dir = NULL) ## S3 method for class 'RDPClassifier' predict(object, newdata, confidence = 0.8, rdp_args = "", verbose = FALSE, ...) trainRDP(x, dir, rank = "genus", verbose = FALSE) removeRDP(object)rdp(dir = NULL) ## S3 method for class 'RDPClassifier' predict(object, newdata, confidence = 0.8, rdp_args = "", verbose = FALSE, ...) trainRDP(x, dir, rank = "genus", verbose = FALSE) removeRDP(object)
dir |
directory where the classifier information is stored. |
object |
a RDPClassifier object. |
newdata |
new data to be classified as a Biostrings::DNAStringSet. |
confidence |
numeric; minimum confidence level for classification. Results with lower confidence are replaced by NAs. Set to 0 to disable. |
rdp_args |
additional RDP arguments for classification (e.g.,
|
verbose |
logical; print additional information. |
... |
additional arguments (currently unused). |
x |
an object of class Biostrings::DNAStringSet with the 16S rRNA sequences for training. |
rank |
Taxonomic rank at which the classification is learned. |
trainRDP() creates a new classifier for the data in x and
stores the classifier information in dir. The data in x needs
to have annotations in the following format:
"<ID> <Kingdom>;<Phylum>;<Class>;<Order>;<Family>;<Genus>"
The trained classifier can be used as long as the directory is available.
A created classifier can be removed with removeRDP(). This will
remove the directory which stores the classifier information permanently.
Calling rdp() without a directory downloads the default 16S classifier
from the RDP project and caches it in the user data directory. The first
download may take a while, and you will be asked before it starts.
A custom classifier can be loaded by passing its
directory to rdp(dir).
rdp() loads a classifier model from a specified directory. predict() can then
be used to create a prediction.
rdp() and trainRDP() return a RDPClassifier object.
predict() returns a data.frame containing the classification results
for each sequence (rows). The data.frame has an attribute called
"confidence" with a matrix containing the confidence values.
Hahsler M, Nagar A (2020). "rRDP: Interface to the RDP Classifier." R Package, Bioconductor. doi:10.18129/B9.bioc.rRDP.
RDP classifier software: https://sourceforge.net/projects/rdp-classifier/
Qiong Wang, George M. Garrity, James M. Tiedje and James R. Cole. Naive Bayesian Classifier for Rapid Assignment of rRNA Sequences into the New Bacterial Taxonomy, Appl. Environ. Microbiol. August 2007 vol. 73 no. 16 5261-5267. doi:10.1128/AEM.00062-07
Qiong W. and Cole J.R. Updated RDP taxonomy and RDP Classifier for more accurate taxonomic classification, Microbial Ecology, Announcement, 4 March 2024. doi:10.1128/mra.01063-23
## Train a RDP classifier on new data trainingSequences <- readDNAStringSet( system.file("examples/trainingSequences.fasta", package = "rRDP") ) customRDP <- trainRDP(trainingSequences, dir = "test_classifier") customRDP testSequences <- readDNAStringSet( system.file("examples/testSequences.fasta", package = "rRDP") ) predict(customRDP, testSequences) ## clean up (don't do this if you want to use the classifier later on again) removeRDP(customRDP) ## Download a pretrained model manually ## Not run: # the download may take a while if (!file.exists("data")) { if (!file.exists("data.tgz")) download.file(paste0("https://downloads.sourceforge.net/", "project/rdp-classifier/rdp-classifier/data.tgz"), "data.tgz", mode = "wb") untar("data.tgz") } classifier <- rdp("data/classifier/16srrna") classifier seq <- readRNAStringSet(system.file("examples/RNA_example.fasta", package = "rRDP" )) # decode the actual classification actual <- decode_Greengenes(names(seq)) # use RDP to predict the classification pred <- predict(classifier, seq) # calculate accuracy confusionTable(actual, pred, "genus") accuracy(actual, pred, "genus") # Don't forget to delete the models if you do not need them anymore ## End(Not run)## Train a RDP classifier on new data trainingSequences <- readDNAStringSet( system.file("examples/trainingSequences.fasta", package = "rRDP") ) customRDP <- trainRDP(trainingSequences, dir = "test_classifier") customRDP testSequences <- readDNAStringSet( system.file("examples/testSequences.fasta", package = "rRDP") ) predict(customRDP, testSequences) ## clean up (don't do this if you want to use the classifier later on again) removeRDP(customRDP) ## Download a pretrained model manually ## Not run: # the download may take a while if (!file.exists("data")) { if (!file.exists("data.tgz")) download.file(paste0("https://downloads.sourceforge.net/", "project/rdp-classifier/rdp-classifier/data.tgz"), "data.tgz", mode = "wb") untar("data.tgz") } classifier <- rdp("data/classifier/16srrna") classifier seq <- readRNAStringSet(system.file("examples/RNA_example.fasta", package = "rRDP" )) # decode the actual classification actual <- decode_Greengenes(names(seq)) # use RDP to predict the classification pred <- predict(classifier, seq) # calculate accuracy confusionTable(actual, pred, "genus") accuracy(actual, pred, "genus") # Don't forget to delete the models if you do not need them anymore ## End(Not run)