knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(bactcountr) library(dplyr) library(tidyr) library(ggplot2) library(ggbeeswarm) library(readxl)
This package is used to provide an automated way to calculate CFUs based on the dilutions used and to plot the final results.
The package has three main functions:
tidy_cfu
: Cleans CFU data and selects all columns that start with dilutionpick_one_dilution
: Picks one dilution that is most likely to be the most accurate to perform CFU calculations oncalculate_cfu
: Calculates the whole and log cfus based on the dilution factor and resuspended volumeIn order to use the first function tidy_CFU
the data must have some columns:
dilution_x
where x is the dilution useddata("CFU_data") head(CFU_data)
When the tidy_CFU
function is used, it puts it into a tidy format. The naming/grouping columns are left alone, but the dilution and CFU columns are gathered so that each row of the dataframe represents a single observation. Any values in the original dataframe that are labeled as "TNTC" (Too Numerous To Count) are converted to NA columns as they cannot be used to calculate the CFUs.
CFU_raw_formatted <- tidy_CFU(CFU_data) head(CFU_raw_formatted)
The function pick_one_dilution
sifts through all of the data for the groups and finds the CFU observation for each group/replicate/organ that is closest to 25 CFUs (and therefore, most likely the most accurate observation). It picks one of the dilution-CFU observations per grouping.
CFU_one_dilution <- pick_one_dilution(CFU_raw_formatted, "CFUs", c("group", "organ", "replicate")) head(CFU_one_dilution)
The calculate_cfu
function calculates the whole CFUs and log CFUs for each observation in the data. It takes in experimental parameters such as the dilution factor used, the volume (in milliliters) used to resuspend the CFU solution, and the percent of the organ used (if organ is used, default is 1 so whole organ).
final_data <- calculate_cfu(CFU_one_dilution, dilution_factor = 5, resuspend_volume_ml = 0.5, volume_plated_uL = 100, percent = 0.5, "dilution", "CFUs") head(final_data)
This is an example reading in the data from an excel file. The functions are all run through so that the log CFUs are calculated for each group and replicate for the spleen. The results can subsequently be plotted.
# example file for the excel file example_file_address <- system.file("extdata", "PL_D-21_BCG_CFUs.xlsx", package = "bactcountr") # all of the functions are used to tidy the data, pick one dilution, and then calculate the log CFUs analyzed_CFUs <- read_xlsx(example_file_address) %>% tidy_CFU() %>% pick_one_dilution("CFUs", c("group", "organ", "replicate")) %>% filter(organ == "Spleen") %>% calculate_cfu(5, 0.5, 100,0.5, "dilution", "CFUs") # the CFUs can then be plotted ggplot(analyzed_CFUs, aes(group, log_CFUs, color = group)) + geom_beeswarm(groupOnX = TRUE) + ggtitle("PL BCG CFUs D-21 Spleen")
If you want to see the consistancy of the plating across the dilutions, you can skip the pick_one_dilution
function and plot the calculated log_CFUs for group/replicate against the dilutions.
analyzed_CFUs_wo_pick_one <- read_xlsx(example_file_address) %>% tidy_CFU() %>% filter(organ == "Spleen") %>% calculate_cfu(5, 0.5, 100, 0.5, "dilution", "CFUs") %>% unite(col = group_replicate, group, replicate, sep = "_") ggplot(analyzed_CFUs_wo_pick_one, aes(dilution, log_CFUs, color = group_replicate)) + geom_point() + geom_path() + ggtitle("PL BCG CFUs D-21 Spleen for all dilutions")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.