Show the code
here::i_am("scripts/sample_inventory.qmd")
source(here::here("_common.R"))
source(here("scripts/sample_inventory.R"))Rich Lab for Molecular Health
here::i_am("scripts/sample_inventory.qmd")
source(here::here("_common.R"))
source(here("scripts/sample_inventory.R"))params$sample_type with one of isolates, fecals, or environmental to import and update the correct inventory files using the code below.statussampleIDsamplesetextractIDextract_runlibraryIDlibprep_runseq_runseq_run_idcollection_datecollection_stabilizercollection_bycollection_sourcecollection_siteextract_boxextract_runextraction_dateextraction_byextraction_targetextraction_kitextraction_protocolextraction_sample_input_ulextraction_elution_ulextraction_elution_tempextract_ng_ulextraction_notelibprep_datelibprep_runlibprep_protocollibprep_kitlibprep_extract_ullibprep_extract_h20lib_ng_ul_1lib_ng_ul_2lib_ul_addedlibprep_notelibprep_barcodeseq_run_idseq_dateseq_byseq_deviceseq_positionseq_flowcellseq_flowcell_idseq_flongleseq_depthseq_qscore_meanseq_length_meansubjectsubject_genussubject_speciessubject_confirmedsubject_sexsubject_age_categorysubject_repro_statuscollection_notesubject_masssubject_mass_confirmedsubject_forearmcollection_latitudecollection_longitudecollection_net_lengthcollection_pelletssubject_dietsubject_antibioticsubject_antidiarrhealsubject_fibersubject_probioticsubject_steroidsubject_bristolsubject_holdingcollection_pair_accesscollection_datetimecollection_antibioticcollection_mediumcollection_linecollection_LiCl_MSometimes excel sneaks in its own reformatting of dates in csv files, so you should make sure you switch all days back to yyyy-mm-dd format before trying to read the file with the code below.
sample_inventory <- read_csv(
here(paste0("inventories/", params$sample_type, "/sample_inventory.csv")),
col_types = inventory_csv_cols[[params$sample_type]]
) %>%
group_by(sampleID) %>%
arrange(extractID, libraryID, seq_run) %>%
mutate(status = case_when(
str_detect(sampleID, "NTC") ~ "control",
!is.na(first(seq_run)) ~ "sequenced",
is.na(first(seq_run)) & !is.na(first(libraryID)) ~ "libprepped",
is.na(first(seq_run)) & is.na(first(libraryID)) & !is.na(first(extractID)) ~ "extracted",
is.na(first(seq_run)) & is.na(first(libraryID)) & is.na(first(extractID)) ~ "collected"
)) %>%
ungroup() %>%
arrange(sampleset, sampleID, extractID, libraryID) %>%
select(any_of(inventory_cols$compilation)) %>%
distinct()inventory <- list(
compilation = select(filter(sample_inventory, status != "control"), any_of((inventory_cols$compilation))),
samples = select(filter(sample_inventory, status != "control"), any_of(inventory_cols$samples)),
extracts = select(filter(sample_inventory, status != "control"), any_of(inventory_cols$extracts)),
libraries = select(filter(sample_inventory, status != "control"), any_of(inventory_cols$libraries)),
controls = select(filter(sample_inventory, status == "control"), any_of(inventory_cols$controls))
)
inventory$compilation <- inventory$compilation %>%
distinct() %>%
arrange(sampleset, sampleID, extractID, libraryID, seq_run)
inventory$samples <- distinct(inventory$samples)
inventory$extracts <- distinct(filter(inventory$extracts, !is.na(extractID)))
inventory$libraries <- distinct(filter(inventory$libraries, !is.na(libraryID)))
inventory$controls <- distinct(inventory$controls)version_control_check(
paste0("inventories/", params$sample_type),
"inventory",
".RData"
)[1] "inventories/isolates directory exists."
[1] "version_archive directory already exists"
[1] "previous file version moved to archive"
save(
inventory,
file = here(paste0("inventories/", params$sample_type, "/inventory.RData"))
)
version_control_check(
paste0("inventories/", params$sample_type),
"sample_inventory",
".RData"
)[1] "inventories/isolates directory exists."
[1] "version_archive directory already exists"
[1] "previous file version moved to archive"
save(
sample_inventory,
file = here(paste0("inventories/", params$sample_type, "/sample_inventory.RData"))
)
version_control_check(
paste0("inventories/", params$sample_type),
"sample_inventory",
".csv"
)[1] "inventories/isolates directory exists."
[1] "version_archive directory already exists"
[1] "previous file version moved to archive"
write_csv(
sample_inventory,
here(paste0("inventories/", params$sample_type, "/sample_inventory.csv")),
na = ""
)
dashboard_transfer(
paste0("inventories/", params$sample_type),
paste0("inventories/", params$sample_type),
"inventory",
".RData"
)[1] "Dashboard subdirectory already exists"
[1] "File available for dashboard use now."
Use the links below to access the current github repo version of our inventories.