Created
February 8, 2022 08:58
-
-
Save padpadpadpad/996fb298c648bac4ce06a7974c8b9808 to your computer and use it in GitHub Desktop.
Keep all the fits from growthcurver on a plate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load in packages | |
library(growthcurver) | |
library(tidyverse) | |
# load in example data | |
d <- growthdata # load some sample, simulated data | |
gc_fit <- SummarizeGrowthByPlate(d) # do the analysis | |
plot(gc_fit) # plot your data and the best fit | |
gc_fit$model %>% broom::augment() | |
gc_fit$vals | |
# want to grab the fit of all the wells in the plate so we can look at their output together | |
# setup output dataframe. This is the key step, want every individual curve in there | |
output <- tibble(well = colnames(d)[colnames(d) != 'time']) %>% | |
mutate(model = list(NA), | |
vals = list(NA), | |
data = list(NA)) | |
# run a for loop to do each fit | |
for(i in 1:nrow(output)){ | |
well <- output$well[i] | |
gc_fit <- SummarizeGrowth(d$time, d[, well]) | |
output$model[[i]] <- gc_fit$model | |
output$vals[[i]] <- gc_fit$vals %>% unlist() %>% bind_rows() %>% mutate(across(k:auc_e, as.numeric)) | |
output$data[[i]] <- gc_fit$data | |
} | |
# get predictions for each well | |
d_preds <- mutate(output, preds = map(model, broom::augment)) %>% | |
unnest(preds) %>% | |
select(-vals, - data, -model) | |
# plot these | |
ggplot(d_preds) + | |
geom_point(aes(t, n)) + | |
geom_line(aes(t, .fitted), col = 'red') + | |
facet_wrap(~well) | |
# get summary of fits for each well | |
d_check <- mutate(output, model_check = map(model, broom::glance)) %>% | |
unnest(model_check) %>% | |
select(-vals, - data, -model) | |
# get the values of all the desired traits | |
d_traits <- unnest(output, vals) %>% | |
select(- data, -model) | |
head(d_traits) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment