true_pos_rate: true_pos_rate

View source: R/true_pos_rate.R

true_pos_rateR Documentation

true_pos_rate

Description

Calculate rate of true positives in positive control standards. Used in OCMS_zymobioimcs report.

Usage

true_pos_rate(relab, annotations, level = "species", cutoff = 0.01)

Arguments

relab

relative abundance data frame with samples in columns, features in rows

annotations

reference annotations for true positives

level

taxonomy level at which analysis is done. can be one of 'species','genus','family'. default 'species'

cutoff

threshold for read relative abundance in the sample. default is 0.01 (0.01 %)

Value

dataframe ranking features as true positive or false positive in each sample.

Examples

 # this would be better exemplified with actual std data rather than the example smaples
 data("dss_example")
data(zymobiomics)

# set count feature ids as rownames
count_df <- dss_example$merged_abundance_id %>%
  column_to_rownames('featureID')

# clean up some sample names
colnames(count_df) <- paste0('id', colnames(count_df))
tax_df <- dss_example$merged_taxonomy

# aggregate counts
agg_gen <- aggregateCount(count_df[tax_df$featureID,], tax_df, "Genus")
genus_relab <- relab(agg_gen$count_df)

true_pos_result <- true_pos_rate(relab=genus_relab,
                               annotations=zymobiomics$anno_ncbi_16s,
                               level='genus', cutoff=0.01)

# plot true pos rate
p <- ggplot(true_pos_result,
            aes(x=rank, y=true.pos.rate, colour=label, group=sample)) +
 geom_point() +
  theme_bw() +
  ylab("TP / (TP + FP)") +
 scale_colour_manual(values=c("grey", "purple")) +
 facet_wrap(~sample, scale="free")

p

OxfordCMS/OCMSutility documentation built on Feb. 27, 2025, 8:19 p.m.