Create a dataframe which describes comparisons between a given condition and all other conditions described in a pool dataframe
Usage
sample_comparison_frame(
pool_df,
grouping_var = "batch",
condition_var = "cond",
base_comparison_condition = "inoculum",
var1_name = "lowBulk",
var2_name = "highBulk",
base_cond_in_each_group = TRUE
)
Arguments
- pool_df
a dataframe which describes the pool
- grouping_var
column by which to group and split the dataframe, Default: 'batch'
- condition_var
column which describes the various conditions of each sample, eg if tissue, then the levels of this column might be c(lung, brain, YPD, inoculum), Default: 'cond'
- base_comparison_condition
condition against which to compare all other conditions, Default: 'inoculum'
- var1_name
the output frame will have two columns, the first storing the samples which correspond to the
base_comparison_condition
, the other to the other sample conditions, Default: 'lowBulk'- var2_name
as in var1_name, this will rename the second column in the output frame, Default: 'highBulk'
- base_cond_in_each_group
whether to include the base condition in each group. Default TRUE
Value
A two column dataframe where the first column is the condition against which all other sample conditions in that group are compared. An example structure is:
highBulk | lowBulk | |
\(P1.1I\) | \(P1.1L\) | |
\(P1.1I\) | \(P1.1B\) |
Examples
if(interactive()){
library(dplyr)
# NOTE! "P2.1I" is a singleton
sample_example = c("P1.1I","P1.1L","P1.1Y",
"P1.2B","P1.2I","P1.2L","P1.2Y","P2.1I")
pool_construction = tibble(sample = sample_example) %>%
mutate(batch = str_remove(sample, "\\w$")) %>%
mutate(cond = ifelse(str_detect(sample, "P[[:alnum:]].{1,3}I"),'inoculum', NA)) %>%
mutate(cond = ifelse(str_detect(sample, "P[[:alnum:]].{1,3}Y"),'ypd', cond)) %>%
mutate(cond = ifelse(str_detect(sample, "P[[:alnum:]].{1,3}L"),'lung', cond)) %>%
mutate(cond = ifelse(str_detect(sample, "P[[:alnum:]].{1,3}B"),'brain', cond)) %>%
mutate(bulk = ifelse(cond == "inoculum", 'low', 'high'))
sample_comparison_frame(pool_construction)
}