source("metadata/loris/factors.R")
source("metadata/loris/diet_schedule.R")
source("metadata/loris/nutrition.R")
source("metadata/loris/metadata_key.R")
source("metadata/loris/hdz_loris_log.R")

Intro

The purpose of a metadata file is to organize the potential independent or predictor variables for your analysis into a single table with one row per SampleID. Then, when you produce a set of potential dependent or outcome values, you organize those into a similar structure with the SampleIDs organized rowwise to streamline the process of matching predictor variables to outcome variables by SampleID. It’s good practice to keep as much of your information in one tidy table as possible so that you can keep pulling from that source to further filter, wrangle and analyze without losing track of different versions and datasets over time. That means you should brainstorm as many possible predictor variables you might use in downstream analysis as possible and organize them into one tidy table where each SampleID is matched to a value for every variable. You will end up ignoring most of these variables as you construct individual tests and visuals later, so consider this simply a rough draft of your information of interest. I am going to do this with the Pygmy Loris dataset for this tutorial. You may have a very different set of variables to organize for your own project.

Previous Scripts

Before this, you should use the SampleInventory script to create the file compilation.tsv.

Other Configuration Settings

Sampleset in Params

You can use the sampleset setting under params in the header of this script to select which sampleset you will be working with. So long as the same name is used consistently, this should automatically filter for that name (e.g., loris or marmoset).

File Paths

Next, you should make sure your config.yml file contains the path to locate each of the files you will be using. Below is an example excerpt from my config file.

default:
  setup: "setup/global/setup.R"
  conflicts: "setup/conflicted.R"
  functions: "setup/global/functions.R"
  packages: "setup/global/packages.R"
  inputs: "setup/default_inputs.R"
  fonts: "setup/global/fonts/FA6_Free-Solid-900.otf"
  test_prediction: "setup/microbiome/test_prediction/"
  visuals: "visuals/"
  tmp_tsv: "tmp/tmp_table.tsv"
  tmp_downloads: "tmp/downloads/"
  tmp_fetch: "tmp/fetch_references.txt"
  tmp_fasta3: "tmp/tmp3.fasta"
  tmp_fasta4: "tmp/tmp4.fasta"
  git_url: "https://rich-molecular-health-lab.github.io/"
  
isolates:
  samplesets: "salci" 
  minQC: 10
  
microbiome:
  micro_scripts: !expr list("setup/microbiome/functions.R", "setup/microbiome/inputs.R")
  setup_dir: "setup/microbiome"
  inputs: "setup/microbiome/inputs.R"
  packages: "setup/microbiome/packages.R"
  first_use_packages: "setup/microbiome/packages_first_use.R"
  functions: "setup/microbiome/functions.R"
  tax4fun: "setup/microbiome/Tax4Fun2_ReferenceData_v2/"
  Ref99NR: "setup/microbiome/Tax4Fun2_ReferenceData_v2/Ref99NR/"
  blast: "setup/microbiome/ncbi-blast-2.16.0+/bin"
  
swan:
  functions: "setup/read_processing/functions.R"
  loris_tax: "/work/richlab/aliciarich/bioinformatics_stats/data/loris/taxonomy/"
  uid_file: "/work/richlab/aliciarich/bioinformatics_stats/tmp/fetch_references.txt"
  logs: "/work/richlab/aliciarich/bioinformatics_stats/logs"
  ont_reads: "/work/richlab/aliciarich/ont_reads/"
  dorado_model: "/work/richlab/aliciarich/ont_reads/dna_r10.4.1_e8.2_400bps_sup@v5.0.0/"
  bioinformatics_stats: "/work/richlab/aliciarich/bioinformatics_stats"
  samplesheets: "/work/richlab/aliciarich/bioinformatics_stats/dataframes/sample_sheet/loris"
  scripts: "/work/richlab/aliciarich/bioinformatics_stats/batch_scripts/"
  accessions: "/work/richlab/aliciarich/bioinformatics_stats/tmp/accessions.txt"
  tmp_fasta1: "/work/richlab/aliciarich/bioinformatics_stats/tmp/tmp1.fasta"
  tmp_fasta2: "/work/richlab/aliciarich/bioinformatics_stats/tmp/tmp2.fasta"
  tmp_fasta3: "/work/richlab/aliciarich/bioinformatics_stats/tmp/tmp3.fasta"
  tmp_fasta4: "/work/richlab/aliciarich/bioinformatics_stats/tmp/tmp4.fasta"
  raw_loris_mb: "/work/richlab/aliciarich/ont_reads/loris_microbiome/hdz_raw"
  basecalled_loris_mb: "/work/richlab/aliciarich/ont_reads/loris_microbiome/basecalled"
  trimmed_loris_mb: "/work/richlab/aliciarich/ont_reads/loris_microbiome/trimmed"
  filtered_loris_mb: "/work/richlab/aliciarich/ont_reads/loris_microbiome/filtered"
  loris_mb_aligned: "/work/richlab/aliciarich/bioinformatics_stats/data/loris/taxonomy/refseqs_aligned.fasta"
  loris_mb_tree: "/work/richlab/aliciarich/bioinformatics_stats/data/loris/taxonomy/refseqs_tree.newick"

bats:
  sequencing:
    coverage: "visuals/bats_16s_depth_summary.html"
    depth_plot: "visuals/bats_16s_depth_hist.html"
  metadata:
    summary: "metadata/bats/samples_metadata.tsv"
    key: "metadata/bats/metadata_key.R"
    factors: "metadata/bats/factors.R"
    scripts: !expr list("metadata/bats/colors.R", "metadata/bats/metadata_key.R", "metadata/bats/factors.R")
  inventories:
    all_stages: "../read_processing/samples/inventories/bats/compilation_bats.tsv"
    collection: "../read_processing/samples/inventories/bats/samples_bats.csv"
    extraction: "../read_processing/samples/inventories/bats/extracts_bats.csv"
    libraries: "../read_processing/samples/inventories/bats/libraries_bats.csv"
    seqruns: "../read_processing/samples/inventories/bats/seqruns_bats.csv"
  barcodes_output: "../read_processing/samples/barcode_alignments/bats/"
  read_alignments: "data/bats/read_alignments"
  taxa_reps:
    aligned: "data/bats/taxonomy/refseqs_aligned.fasta"
    tree: "data/bats/taxonomy/refseqs_tree.newick"
    table: "data/bats/taxonomy/tax_table.tsv"

loris:
  day1: "2023-10-26"
  last: "2024-10-25"
  visuals:
    demographics: "visuals/loris/demography"
    coverage: "visuals/loris_depth_summary.html"
    depth_plot: "visuals/loris_depth_hist.html"
  AZAstudbooks:
    btp: "metadata/loris/Studbook/BTP25.R"
    btp_current: "metadata/loris/Studbook/BTP25.tsv"
    lifetable: "metadata/loris/Studbook/lifetable25.tsv"
    lifetabStatic: "metadata/loris/Studbook/lifetable25_static.tsv"
    load_data: "metadata/loris/Studbook/LoadStudbookData.R"
    functions: "metadata/loris/studbookFunctions.R"
    reactables: "metadata/loris/Studbook/reactables.R"
    living25: "metadata/loris/Studbook/LivingPop_2025.csv"
    living21: "metadata/loris/Studbook/LivingPop_2021.csv"
    historic21: "metadata/loris/Studbook/HistoricPop_2021.csv"
    institutions: 
      current25: "metadata/loris/Studbook/CurrentInstitutions_2025.csv"
      current21: "metadata/loris/Studbook/CurrentInstitutions_2021.csv"
      historic21: "metadata/loris/Studbook/HistoricInstitutions_2021.csv"
    working: "metadata/loris/Studbook/working_studbook_loris25.tsv"
    reactable_ready: "metadata/loris/Studbook/studbook_loris_reactableReady.tsv"
    timeline: "metadata/loris/Studbook/working_timeline_loris25.tsv"
  metadata: 
    scripts: !expr list("metadata/loris/colors.R", "metadata/loris/metadata_key.R", "metadata/loris/diet_schedule.R")
    bristol: "metadata/loris/bristols.tsv"
    studbook: "metadata/loris/subjects_loris.csv"
    summary: "metadata/loris/samples_metadata.tsv"
    key: "metadata/loris/metadata_key.R"
    factors: "metadata/loris/factors.R"
    foods: "metadata/loris/foods.tsv"
    proteins: "metadata/loris/proteins.tsv"
    fats: "metadata/loris/fats.tsv"
    CHOs: "metadata/loris/CHOs.tsv"
    Ash: "metadata/loris/Ash.tsv"
    vitamins: "metadata/loris/vitamins.tsv"
    reactable: "metadata/loris/loris_metadata_summary.html"
    sample_table: 
      identifiers: "metadata/loris/identifier_key.tsv"
      main: "metadata/loris/sample_table.tsv"
      merged: "metadata/loris/sample_table_merged.tsv"
  inventories:
    all_stages: "../read_processing/samples/inventories/loris/compilation_loris.tsv"
    collection: "../read_processing/samples/inventories/loris/samples_loris.csv"
    extraction: "../read_processing/samples/inventories/loris/extracts_loris.csv"
    libraries: "../read_processing/samples/inventories/loris/libraries_loris.csv"
    seqruns: "../read_processing/samples/inventories/loris/seqruns_loris.csv"
  outputs_wf16s: "data/loris/outputs_wf16s/"
  barcodes_output: "dataframes/barcodes/loris/"
  read_alignments: "data/loris/read_alignments"
  taxa_reps:
    aligned: "data/loris/taxonomy/refseqs_aligned.fasta"
    tree: "data/loris/taxonomy/refseqs_tree.newick"
    table: "data/loris/taxonomy/tax_table.tsv"
  abundance_wf16s: "data/loris/wf16s_abundance/"
  microeco: 
    dataset:
      main:
        keg: "microeco/loris/datasets/main/keg"
        njc: "microeco/loris/datasets/main/njc"
        fpt: "microeco/loris/datasets/main/fpt"
        tax: "microeco/loris/datasets/main"
      culi:
        keg: "microeco/loris/datasets/culi/keg"
        njc: "microeco/loris/datasets/culi/njc"
        fpt: "microeco/loris/datasets/culi/fpt"
        tax: "microeco/loris/datasets/culi"
      warb:
        keg: "microeco/loris/datasets/warble/keg"
        njc: "microeco/loris/datasets/warble/njc"
        fpt: "microeco/loris/datasets/warble/fpt"
        tax: "microeco/loris/datasets/warble"
    abund:
      main:
        keg: "microeco/loris/abundance/main/keg"
        fpt: "microeco/loris/abundance/main/fpt"
        njc: "microeco/loris/abundance/main/njc"
        tax: "microeco/loris/abundance/main"
      culi:
        keg: "microeco/loris/abundance/culi/keg"
        fpt: "microeco/loris/abundance/culi/fpt"
        njc: "microeco/loris/abundance/culi/njc"
        tax: "microeco/loris/abundance/culi"
      warb:
        keg: "microeco/loris/abundance/warble/keg"
        fpt: "microeco/loris/abundance/warble/fpt"
        njc: "microeco/loris/abundance/warble/njc"
        tax: "microeco/loris/abundance/warble"
    alpha:
      main: "microeco/loris/alphadiversity/main"
      culi: "microeco/loris/alphadiversity/culi"
      warb: "microeco/loris/alphadiversity/warble"
    beta:
      main:
        kegg: "microeco/loris/betadiversity/main/keg"
        fpt: "microeco/loris/betadiversity/main/fpt"
        njc: "microeco/loris/betadiversity/main/njc"
        tax: "microeco/loris/betadiversity/main"
      culi:
        kegg: "microeco/loris/betadiversity/culi/keg"
        fpt:  "microeco/loris/betadiversity/culi/fpt"
        njc:  "microeco/loris/betadiversity/culi/njc"
        tax: "microeco/loris/betadiversity/culi"
      warb:
        kegg: "microeco/loris/betadiversity/warble/keg"
        fpt:  "microeco/loris/betadiversity/warble/fpt"
        njc:  "microeco/loris/betadiversity/warble/njc"
        tax: "microeco/loris/betadiversity/warble"
    data:
      main:
        feature: "microeco/loris/datasets/main/feature_table.tsv"
        tree:    "microeco/loris/datasets/main/phylo_tree.tre"
        fasta:   "microeco/loris/datasets/main/rep_fasta.fasta"
        samples: "microeco/loris/datasets/main/sample_table.tsv"
        taxa:    "microeco/loris/datasets/main/tax_table.tsv"
      culi: 
        feature: "microeco/loris/datasets/culi/feature_table.tsv"
        tree:    "microeco/loris/datasets/culi/phylo_tree.tre"
        fasta:   "microeco/loris/datasets/culi/rep_fasta.fasta"
        samples: "microeco/loris/datasets/culi/sample_table.tsv"
        taxa:    "microeco/loris/datasets/culi/tax_table.tsv"
      warb:
        feature: "microeco/loris/datasets/warb/feature_table.tsv"
        tree:    "microeco/loris/datasets/warb/phylo_tree.tre"
        fasta:   "microeco/loris/datasets/warb/rep_fasta.fasta"
        samples: "microeco/loris/datasets/warb/sample_table.tsv"
        taxa:    "microeco/loris/datasets/warb/tax_table.tsv"

sample_sheets:
  compilations:
    bats:    "../read_processing/samples/sample_sheets/bats/nwr_combined_sample_sheet.csv"
    loris:    "../read_processing/samples/sample_sheets/loris/hdz_combined_sample_sheet.csv"
  nwr1: "../read_processing/samples/sample_sheets/bats/nwr1_sample_sheet.csv"
  hdz1:  "../read_processing/samples/sample_sheets/loris/hdz1_sample_sheet.csv"
  hdz2:  "../read_processing/samples/sample_sheets/loris/hdz2_sample_sheet.csv"
  hdz3:  "../read_processing/samples/sample_sheets/loris/hdz3_sample_sheet.csv"
  hdz4:  "../read_processing/samples/sample_sheets/loris/hdz4_sample_sheet.csv"
  hdz5:  "../read_processing/samples/sample_sheets/loris/hdz5_sample_sheet.csv"
  hdz6:  "../read_processing/samples/sample_sheets/loris/hdz6_sample_sheet.csv"
  hdz7:  "../read_processing/samples/sample_sheets/loris/hdz7_sample_sheet.csv"
  hdz8:  "../read_processing/samples/sample_sheets/loris/hdz8_sample_sheet.csv"
  hdz9:  "../read_processing/samples/sample_sheets/loris/hdz9_sample_sheet.csv"
  hdz10: "../read_processing/samples/sample_sheets/loris/hdz10_sample_sheet.csv"
  hdz11: "../read_processing/samples/sample_sheets/loris/hdz11_sample_sheet.csv"
  hdz12: "../read_processing/samples/sample_sheets/loris/hdz12_sample_sheet.csv"
  hdz13: "../read_processing/samples/sample_sheets/loris/hdz13_sample_sheet.csv"
  hdz14: "../read_processing/samples/sample_sheets/loris/hdz14_sample_sheet.csv"
  hdz15: "../read_processing/samples/sample_sheets/loris/hdz15_sample_sheet.csv"
  hdz16: "../read_processing/samples/sample_sheets/loris/hdz16_sample_sheet.csv"
  hdz17: "../read_processing/samples/sample_sheets/loris/hdz17_sample_sheet.csv"
  hdz18: "../read_processing/samples/sample_sheets/loris/hdz18_sample_sheet.csv"

barcode_alignments:
  compilations:
    loris:    "../read_processing/samples/barcode_alignments/loris/hdz_combined_barcode_alignment.tsv"
    bats:    "../read_processing/samples/barcode_alignments/bats/nwr_combined_barcode_alignment.tsv"
  nwr1: "../read_processing/samples/barcode_alignments/bats/nwr1_barcode_alignment.tsv"
  hdz1:  "../read_processing/samples/barcode_alignments/loris/hdz1_barcode_alignment.tsv"
  hdz2:  "../read_processing/samples/barcode_alignments/loris/hdz2_barcode_alignment.tsv"
  hdz3:  "../read_processing/samples/barcode_alignments/loris/hdz3_barcode_alignment.tsv"
  hdz4:  "../read_processing/samples/barcode_alignments/loris/hdz4_barcode_alignment.tsv"
  hdz5:  "../read_processing/samples/barcode_alignments/loris/hdz5_barcode_alignment.tsv"
  hdz6:  "../read_processing/samples/barcode_alignments/loris/hdz6_barcode_alignment.tsv"
  hdz7:  "../read_processing/samples/barcode_alignments/loris/hdz7_barcode_alignment.tsv"
  hdz8:  "../read_processing/samples/barcode_alignments/loris/hdz8_barcode_alignment.tsv"
  hdz9:  "../read_processing/samples/barcode_alignments/loris/hdz9_barcode_alignment.tsv"
  hdz10: "../read_processing/samples/barcode_alignments/loris/hdz10_barcode_alignment.tsv"
  hdz11: "../read_processing/samples/barcode_alignments/loris/hdz11_barcode_alignment.tsv"
  hdz12: "../read_processing/samples/barcode_alignments/loris/hdz12_barcode_alignment.tsv"
  hdz13: "../read_processing/samples/barcode_alignments/loris/hdz13_barcode_alignment.tsv"
  hdz14: "../read_processing/samples/barcode_alignments/loris/hdz14_barcode_alignment.tsv"
  hdz15: "../read_processing/samples/barcode_alignments/loris/hdz15_barcode_alignment.tsv"
  hdz16: "../read_processing/samples/barcode_alignments/loris/hdz16_barcode_alignment.tsv"
  hdz17: "../read_processing/samples/barcode_alignments/loris/hdz17_barcode_alignment.tsv"
  hdz18: "../read_processing/samples/barcode_alignments/loris/hdz18_barcode_alignment.tsv"

abund_wf16s_files:
  hdz1:  "data/loris/wf16s_abundance/hdz1_abundance_table_species.tsv"
  hdz2:  "data/loris/wf16s_abundance/hdz2_abundance_table_species.tsv"
  hdz3:  "data/loris/wf16s_abundance/hdz3_abundance_table_species.tsv"
  hdz4:  "data/loris/wf16s_abundance/hdz4_abundance_table_species.tsv"
  hdz5:  "data/loris/wf16s_abundance/hdz5_abundance_table_species.tsv"
  hdz6:  "data/loris/wf16s_abundance/hdz6_abundance_table_species.tsv"
  hdz7:  "data/loris/wf16s_abundance/hdz7_abundance_table_species.tsv"
  hdz8:  "data/loris/wf16s_abundance/hdz8_abundance_table_species.tsv"
  hdz9:  "data/loris/wf16s_abundance/hdz9_abundance_table_species.tsv"
  hdz10: "data/loris/wf16s_abundance/hdz10_abundance_table_species.tsv"
  hdz11: "data/loris/wf16s_abundance/hdz11_abundance_table_species.tsv"
  hdz12: "data/loris/wf16s_abundance/hdz12_abundance_table_species.tsv"
  hdz13: "data/loris/wf16s_abundance/hdz13_abundance_table_species.tsv"
  hdz14: "data/loris/wf16s_abundance/hdz14_abundance_table_species.tsv"
  hdz15: "data/loris/wf16s_abundance/hdz15_abundance_table_species.tsv"
  hdz16: "data/loris/wf16s_abundance/hdz16_abundance_table_species.tsv"
  hdz17: "data/loris/wf16s_abundance/hdz17_abundance_table_species.tsv"
  hdz18: "data/loris/wf16s_abundance/hdz18_abundance_table_species.tsv"

methods_16s:
  libprep_workflow: "'rapid16s'"
  dorado_model: "'dna_r10.4.1_e8.2_400bps_sup@v5.0.0'"
  min_length: 1000
  max_length: 2000
  min_qual: 7
  min_id: 85
  min_cov: 80
  kit_name: "'SQK-16S114-24'"
  tax_rank: "S"
  n_taxa_barplot: 12
  abund_threshold: 0
  loris:
    rarefy: 3500
    norm: "SRS"
    min_abund: 0.00001
    min_freq: 0.01
    include_lowest: TRUE
    unifrac: TRUE
    betadiv: "aitchison"
    alpha_pd: TRUE
    tax4fun_db: "Ref99NR"
    loris_rarefy: 3500
    keg_minID: 97
    

Note that I also include paths to files that this script will create. If the file is already there, then it will be overwritten, if not, it will be created there. Run the code below to set up your paths from the config file for the working sampleset you identified in the header:

global            <- config::get(config = "default")
swan              <- config::get(config = "swan")
micro             <- config::get(config = "microbiome")
loris             <- config::get(config = "loris")
marmoset          <- config::get(config = "marmoset")
isolates          <- config::get(config = "isolates")
bats              <- config::get(config = "bats")
methods_16s       <- config::get(config = "methods_16s")
sample_sheets     <- config::get(config = "sample_sheets")
abund_wf16s_files <- config::get(config = "abund_wf16s_files")
barcode_alignments<- config::get(config = "barcode_alignments")

seqruns      <- seqruns %>% keep_at(params$sampleset)       %>% list_flatten(name_spec = "")
subject_list <- keep_at(subjects, paste0(params$sampleset)) %>% list_flatten(name_spec = "{inner}")
path         <- config::get(config = paste0(params$sampleset))

Sequencing Run Lists

The code in the chunk above also generated a list of formatted codes for each available sequencing run to date, separated by taxa/samplesets (currently just for loris and marmoset). Make sure the end number matches the highest integer we have for that sampleset to date.

Other Setup Scripts

The script that I pasted above sources additional scripts that I run routinely at the start of any work to bring in functions and other inputs with shorter code chunks as well as the text of the yaml header for this R Markdown file. You can flip through the text from those below.

---
output:
  html_document:
    theme:
      bslib: true
    css: journal.css
    toc: true
    toc_float: true
    df_print: paged
params:
  sampleset: "loris"
  seqrun: "hdz18"
                     
---
conflicts_prefer(dplyr::filter)
conflicts_prefer(dplyr::select)
conflicts_prefer(dplyr::left_join)
conflicts_prefer(dplyr::inner_join)
conflicts_prefer(dplyr::full_join)
conflicts_prefer(dplyr::semi_join)
conflicts_prefer(dplyr::rename)
conflicts_prefer(dplyr::setdiff)
conflicts_prefer(dplyr::lag)
conflicts_prefer(rlang::set_names)
conflicts_prefer(purrr::flatten)
conflicts_prefer(purrr::discard_at)
conflicts_prefer(lubridate::month)
conflicts_prefer(lubridate::year)
conflicts_prefer(lubridate::day)
conflicts_prefer(htmltools::p)
conflicts_prefer(htmlwidgets::JS)
conflicts_prefer(dplyr::count)
conflicts_prefer(lubridate::mday)
conflicts_prefer(plotly::layout)
conflicts_prefer(plotly::export)
conflicts_prefer(purrr::discard)
conflicts_prefer(purrr::discard)
conflicts_prefer(ribd::kinship)
conflicts_prefer(dplyr::between)
conflicts_prefer(dplyr::first)
conflicts_prefer(lubridate::interval)
conflicts_prefer(purrr::map)
knitr::knit_engines$set(terminal = function(options) {
  code <- paste(options$code, collapse = "\n")
  
  params <- map(params, ~ if (is.atomic(.)) {list(.)} else {(.)}) %>%
    list_flatten()
  
  patterns <- list(
    params             = list(
      sampleset    = paste0(params$sampleset),
      seqrun       = paste0(params$seqrun),
      samplesheet  = as.character(sample_sheets[paste0(tolower(params$seqrun))])
    )            ,
    
    global            = global            ,
    path              = path              ,
    swan              = swan              ,
    micro             = micro             ,
    loris             = loris             ,
    isolates          = isolates          ,
    bats              = bats              ,
    methods_16s       = methods_16s       ,
    sample_sheets     = sample_sheets     ,
    abund_wf16s_files = abund_wf16s_files ,
    barcode_alignments= barcode_alignments
  )
  
  
  # Replace placeholders group by group
  for (group in names(patterns)) {
    placeholder_list <- patterns[[group]]
    for (name in names(placeholder_list)) {
      placeholder <- paste(group, name, sep = "\\$") # Match exact placeholder
      value <- placeholder_list[[name]]
      
      # Replace placeholders exactly and avoid breaking suffixes
      code <- gsub(placeholder, value, code, perl = TRUE)
    }
  }
  
  options$warning <- FALSE
  knitr::engine_output(options, code, out = code)
})


knitr::opts_chunk$set(message = FALSE,
               warning = FALSE,
               echo    = TRUE,
               include = TRUE,
               eval    = TRUE,
               comment = "")

External Scripts for Metadata

I also source external scripts to bring in different configurations of metadata to use in this workflow. Again, it just keeps my markdown file tidier while also making it easier for me to run code from those scripts in different files or stages of analysis while ensuring I only need to make changes to the code or data in one location to apply it everywhere. Toggle the panels below if you would like to see the code in those scripts. - Note: I am including the scripts that I use for loris metadata. These may vary for other datasets we use.

metadata_variables <- list(
  sample_context = list(
    basics = list(
      identifier        =  "unique ID representing deepest processing ID (SequenceID if available, then ExtractID, then SampleID if sample not extracted yet)",
      study_day         =  "day of sample collection relative to collection start",
      subject           =  "name of subject sample collected from",
      steps_remaining   = "Lab analysis stage for samples as one of (1) collected (poop icon), (2) dna extracted (tube icon), (3) microbiome sequenced (dna icon)."
      ),
   nutrition = list(
     diet_name         = "code name applied to categorize diet trials administered to Culi (Warble is always baseline)",
     total_mg          = "Total weight fed per day (expand cell for daily weight by food item/category)",
     total_kcal        = "total kcal in daily diet"   ,
     total_mg_dry      = "total dry weight of daily diet in mg",
     protein_fed       = "Total weight proteins fed per day (expand cell for daily weight of specific proteins)",  
     fat_fed           = "Total weight fats fed per day (expand cell for daily weight of specific fats)",  
     CHO_fed           = "Total weight carbohydrates fed per day (expand cell for daily weight of specific carbohydrates)",  
     mineral_fed       = "Total weight mineral content fed per day (expand cell for specific daily mineral content)",    
     vitamins          = "Expand cell to view table with estimated vitamin content per day" 
     ),
   supplements = list(
     probiotic         = "Probiotic given at 5 or 10 drops/day",       
     fiber             = "0.5 or 1 capsule Metamucil/day",
     steroid           = "Budesonide given 2x/day at 0.1 or 0.2 mg total",
     antibiotic        = "Metronidazole given 2x/day at 12.5 mg total",
     antidiarrheal     = "Loperamide given 2x/day at 0.08 mg total"
     ),
   other_by_date_subj = list(
     bristol_mean      = "Bristol fecal score recorded that day on scale of 1-6 (mean score for days with > 1 observation)",
     holding           = "Was individual in old or new enclosure?",
     pair_access       = "Did pair have shared enclosure access?", 
     warb_status       = "Was Warble in estrus, pregnant, or anestrus cycle?",
     keeper_note       = "Relevant observations or comments from care staff recorded on that day"
     ),
   subject_info = list(
     Subj_Certainty     =  "Certainty of subject ID recorded for fecal sample (confirmed, unknown, suspected)",  
     Sex                =  "Sex of subject",
     subject_age        =  "Age of subject (in years) on the date of sample collection, relative to birth year in AZA studbook record",
     StudbookID         =  "AZA studbook ID number of subject",
     MotherID           =  "AZA studbook ID number of subject's mother",  
     FatherID           =  "AZA studbook ID number of subject's father",  
     BirthLocation      =  "Institution where subject was born (uses AZA codes)"
     ),
   collection = list(
     SampleID           =  "Unique id for each sample collected",
     CollectionDate     =  "Date of sample collection (yyyy-mm-dd)",     
     SampleSet          =  "Lab code used to identify different samplesets (loris for this one)",
     SampleCollectedBy  =  "identifier for person or group collecting sample",
     SampleNotes        =  "Ad lib notes recorded for sample collection"
     )),
  labwork = list(
    DNAextraction = list(
      ExtractID          =  "Unique id for each (DNA) extract",
      ExtractDate        =  "Date of DNA extraction/purification",  
      ExtractConc        =  "DNA concentration (in ng/\u00b5L) estimated after extraction using Qubit assay and fluorometer",
      ExtractKit         =  "Kit used in DNA extraction/purification",  
      ExtractBox         =  "Identifier for freezer box where sample is located in the Rich Lab",
      ExtractedBy        =  "Person performing DNA extraction/purification", 
      ExtractNotes       =  "Lab notes recorded for DNA extraction/purification procedure"
      ),
    LibraryPrep = list(
      LibPrepDate        =  "date of library preparation",  
      LibPrepWorkflow    =  "lab workflow used for library preparation",      
      LibraryCode        =  "unique id for each pooled library",
      LibPrepKit         =  "ONT kit used for library prep",
      LibraryTube        =  "number applied to tube during Library Prep protocol",
      TemplateVolPrep    =  "volume of extract used in initial step of library prep",
      LibraryBarcode     =  "ONT barcode attached to library before pooling and multiplex sequencing",     
      fragment_type      =  "category applied for calculations during library prep protocol",
      strands            =  "double or single-stranded DNA prepared during library prep protocol",
      Length             =  "target DNA length during library prep protocol",
      InputMassStart     =  "target starting template mass (in ng) during library prep protocol",      
      Conc_QC2           =  "DNA concentration (in ng/\u00b5L) estimated at the end of library prep using Qubit assay and fluorometer",
      PoolSamples        =  "were samples barcoded and pooled for multiplexing during library prep?",  
      SampVolPool        =  "volume of sample added to library pool after barcoding during library prep",
      BeadVol            =  "volume of AMPure beads added to pooled library for final cleanup step",
      TotalPoolVol       =  "total volume of pooled library at the end of library prep",
      InputMassFinal     =  "target template mass (in ng) for flow cell loading after library prep"     
      
    ),
    Sequencing = list(
      SequenceID         =  "Unique id for each sequenced profile generated (some samples/extracts have technical replicates with unique IDs)",
      protocol_group_id  =  "unique id for each sequencing run logged by MinKNOW software",  
      SeqRunID           =  "unique id for each sequencing run",  
      SeqDate            =  "date of library sequencing run",
      SeqDateTime        =  "date and time (Central Time Zone) of library sequencing run",
      FlowCellType       = "type of Flow Cell library was sequenced with",   
      FlowCellSerial     = "serial number of flow cell used in sequencing run",      
      FlongleAdapter     =  "ID of adapter if Flongle Flow Cell was used for sequencing",     
      SeqDevice          =  "MinION device used for sequencing (Angel or Spike)"      ,
      reads_unclassified =  "Raw count of reads from sequencing run before filtering and alignment",
      raw_read_count     =  "Raw count of reads from sequencing run before filtering and alignment",
      depth              =  "Raw count of reads after filtering and alignment for each library",
      mean_coverage      =  "Mean proportion of reads that successfully aligned to a reference"
      )
    )
  )

relative_nutrients <- list(
  id_cols = list(
    "identifier"   =  "unique ID representing deepest processing ID (SequenceID if available, then ExtractID, then SampleID if sample not extracted yet)",
    "SampleID"     =  "unique id for each sample collected",
    "ExtractID"    =  "unique id for each (DNA) extract",
    "SequenceID"   =  "unique id for each sequencing run per sample",         
    "subject"      =  "name of subject sample collected from"
  ), 
  raw_vals      = list(
    proteins    = list(
      "methionine"                 = "total amount fed per day in mg",
      "taurine"                    = "total amount fed per day in mg",
      "proteins_total"             = "total amount fed per day in mg"
    ),
    fats        = list(
      "omega3"                     = "total amount fed per day in mg",
      "omega6"                     = "total amount fed per day in mg",
      "fats_total"                 = "total amount fed per day in mg"
    ),
    CHOs        = list(
      "ADF"                        = "total amount fed per day in mg",
      "NDF"                        = "total amount fed per day in mg",
      "TDF"                        = "total amount fed per day in mg",
      "crude_fiber"                = "total amount fed per day in mg",
      "starch"                     = "total amount fed per day in mg",
      "CHOs_total"                 = "total amount fed per day in mg"
      ),     
    Ash         = list(
      "calcium"                    = "total amount fed per day in mg",
      "magnesium"                  = "total amount fed per day in mg",
      "phosphorus"                 = "total amount fed per day in mg",
      "potassium"                  = "total amount fed per day in mg",
      "copper"                     = "total amount fed per day in mg",
      "iodine"                     = "total amount fed per day in mg",
      "iron"                       = "total amount fed per day in mg",
      "manganese"                  = "total amount fed per day in mg",
      "zinc"                       = "total amount fed per day in mg",
      "Ash_total"                  = "total amount fed per day in mg"
      ),     
    vitamins    = list(
      "beta_carotene"              = "total amount fed per day in mg",
      "lycopene"                   = "total amount fed per day in mg",
      "choline"                    = "total amount fed per day in mg",
      "folic_acid"                 = "total amount fed per day in mg",
      "vit_B1_thiamin"             = "total amount fed per day in mg",
      "vit_B2_riboflavin"          = "total amount fed per day in mg",
      "vit_B3_niacin"              = "total amount fed per day in mg",
      "vit_B5_pantothenic_acid"    = "total amount fed per day in mg",
      "vit_B6_pyridoxine"          = "total amount fed per day in mg",
      "vit_B7_biotin"              = "total amount fed per day in mg",
      "vit_B12"                    = "total amount fed per day in mg",
      "vit_C"                      = "total amount fed per day in mg",
      "vit_A"                      = "total amount fed per day in mg",
      "vit_D3"                     = "total amount fed per day in mg",
      "vit_E"                      = "total amount fed per day in mg",
      "vit_K"                      = "total amount fed per day in mg"
      ),
    foods       = list(
      "biscuit"                    = "total amount fed per day in mg",
      "gum_arabic"                 = "total amount fed per day in mg",
      "invertebrates"              = "total amount fed per day in mg",
      "protein_rotate"             = "total amount fed per day in mg",
      "seasonal_veggies"           = "total amount fed per day in mg",
      "HDZ_oatgel"                 = "total amount fed per day in mg"
      )
  )
)

nested_metadata <- list(
  foods    = list(
    columns = list(
      food   = "name of food category", 
      mg_fed = "daily mass in diet (mg)"
      ),
    rows = list(
      )
    ),
  proteins = list(
    columns = list(
      nutrient      = "name of protein (total is overall protein value)",
      fed           = "amount in daily diet as raw mass",
      fed_unit      = "unit used to report raw mass",
      relative_fed  = "amount in daily diet relative to overall diet or body mass",
      relative_unit = "transformation or unit applied to report relative amount"
      ),
    rows = list(
      total      = "overall protein values",
      methionine = "Methionine",
      taurine    = "Taurine"
      )
    ),
  fats     = list(
    columns = list(
      nutrient      = "name of protein (total is overall protein value)",
      fed           = "amount in daily diet as raw mass",
      fed_unit      = "unit used to report raw mass",
      relative_fed  = "amount in daily diet relative to overall diet or body mass",
      relative_unit = "transformation or unit applied to report relative amount"
    ),
    rows    = list(
      total      = "overall fat values",
      omega3     = "Omega3",
      omega6     = "Omega6"
    )
  ),
  CHOs     = list(
    columns = list(
      nutrient      = "name of protein (total is overall protein value)",
      fed           = "amount in daily diet as raw mass",
      fed_unit      = "unit used to report raw mass",
      relative_fed  = "amount in daily diet relative to overall diet or body mass",
      relative_unit = "transformation or unit applied to report relative amount"
    ),
    rows    = list(
      total       = "overall carbohydrate values",
      ADF         = "Acid Detergent Fiber",
      NDF         = "Neutral Detergent Fiber",
      TDF         = "Total Dietary Fiber",
      WSC         = "Water-Soluble Carbohydrates",
      crude_fiber = "Crude Fiber",
      starch      = "Starch"
    )
  ),
  Ash      = list(
    columns = list(
      nutrient      = "name of protein (total is overall protein value)",
      fed           = "amount in daily diet as raw mass",
      fed_unit      = "unit used to report raw mass",
      relative_fed  = "amount in daily diet relative to overall diet or body mass",
      relative_unit = "transformation or unit applied to report relative amount"
    ),
    rows    = list(
      total       = "overall mineral values",
      calcium     = "Calcium",
      copper      = "Copper",
      iodine      = "Iodine",
      iron        = "Iron",
      magnesium   = "Magnesium",
      manganese   = "Manganese",
      phosphorus  = "Phosphorus",
      potassium   = "Potassium",
      zinc        = "Zinc"
    )
  ),
  vitamins = list(
    columns = list(
      nutrient      = "name of protein (total is overall protein value)",
      fed           = "amount in daily diet as raw mass",
      fed_unit      = "unit used to report raw mass",
      relative_fed  = "amount in daily diet relative to overall diet or body mass",
      relative_unit = "transformation or unit applied to report relative amount"
    ),
    rows    = list(
      total                   = "overall vitamin values",
      beta_carotene           = "Beta-Carotene",
      choline                 = "Choline",
      folic_acid              = "Folic Acid (Vitamin B9)",
      lycopene                = "Lycopene",
      vit_A                   = "Vitamin A (Retinol, Retinal, Retinoic Acid)",
      vit_B12                 = "Vitamin B12 (Cobalamin)",
      vit_B1_thiamin          = "Vitamin B1 (Thiamin)",
      vit_B2_riboflavin       = "Vitamin B2 (Riboflavin)",
      vit_B3_niacin           = "Vitamin B3 (Niacin)",
      vit_B5_pantothenic_acid = "Vitamin B5 (Pantothenic Acid)",
      vit_B6_pyridoxine       = "Vitamin B6 (Pyridoxine)",
      vit_B7_biotin           = "Vitamin B7 (Biotin)",
      vit_C                   = "Vitamin C (Ascorbic Acid)",
      vit_D3                  = "Vitamin D3 (Cholecalciferol)",
      vit_E                   = "Vitamin E (Tocopherols & Tocotrienols)",
      vit_K                   = "Vitamin K (Phylloquinone & Menaquinone)"
      )
  )
)

nutrition_details <- list(
  proteins = list(
    methionine = list(name = "Methionine"   , context = list("An essential amino acid (must be obtained from diet).", "Important for protein synthesis, liver function, and antioxidant pathways","Found in eggs, fish, meat, and some legumes.")),
    taurine    = list(name = "Taurine"      , context = list("A conditionally essential amino acid for some species", "Critical for eye, heart, and nervous system function", "Naturally found in animal tissues (meat, fish, and insects)—not in plants", "Some species (like strict carnivores) cannot synthesize it efficiently and require dietary supplementation."))
  ),
  fats     = list(
    omega3     = list(name = "Omega-3 Fatty Acids"   , context = list("A class of polyunsaturated fats including ALA (alpha-linolenic acid), EPA (eicosapentaenoic acid), and DHA (docosahexaenoic acid)", "Important for brain function, anti-inflammatory processes, and cardiovascular health", "Found in fish, algae, flaxseeds, and some nuts", "Essential in many mammalian diets for neurological and immune functions")),
    omega6     = list(name = "Omega-6 Fatty Acids"   , context = list("Another class of polyunsaturated fats, including LA (linoleic acid) and AA (arachidonic acid).", "Important for skin health, immune response, and cell membrane function.", "Found in plant oils (soybean, corn, sunflower) and animal fats.", "Omega-6 and omega-3 should be balanced, as excess omega-6 can promote inflammation."))
  ),
  CHOs     = list(
    ADF         = list(name = "Acid Detergent Fiber"       , context = list("Measures cellulose and lignin (the least digestible plant components)", "Important for evaluating forage quality—higher ADF means lower digestibility.")),
    NDF         = list(name = "Neutral Detergent Fiber"    , context = list("Includes hemicellulose, cellulose, and lignin (total plant fiber)", "Indicates bulkiness and gut fill—higher NDF means lower voluntary intake.")),
    TDF         = list(name = "Total Dietary Fiber"        , context = list("The sum of soluble and insoluble fiber in food", "Includes cellulose, hemicellulose, pectins, gums, and resistant starch.")),
    WSC         = list(name = "Water-Soluble Carbohydrates", context = list("Includes simple sugars (glucose, fructose, sucrose) and fructans", "Important for fermentation, energy metabolism, and insulin response.")),
    crude_fiber = list(name = "Crude Fiber"                , context = list("An older method of fiber analysis measuring cellulose and lignin, but underestimates total fiber.")),
    starch      = list(name = "Starch"                     , context = list("A digestible polysaccharide providing a rapid energy source", "Important for balancing energy intake in different species (e.g., ruminants vs. omnivores)."))
  ),
  Ash      = list(
    "Macrominerals"  = list(
      calcium     = list(name = "Calcium (Ca)"   , context = list("Essential for bone health, muscle function, and nerve signaling.", "Found in dairy, leafy greens, bones (in whole prey), and eggshells.", "Calcium-to-phosphorus (Ca:P) ratio is critical—imbalances can cause metabolic bone disease (MBD).")),
      magnesium   = list(name = "Magnesium (Mg)" , context = list("Supports muscle and nerve function, enzyme activation, and bone structure.", "Found in nuts, seeds, whole grains, and dark leafy greens.", "Deficiency can cause muscle cramps, weakness, and metabolic issues.")),
      phosphorus  = list(name = "Phosphorus (P)" , context = list("Works with calcium in bone health and energy metabolism (ATP production).", "Found in meat, fish, nuts, and dairy.", "Excess phosphorus with low calcium can lead to bone disorders (common in meat-heavy diets).")),
      potassium   = list(name = "Potassium (K)"  , context = list("Regulates fluid balance, muscle contractions, and nerve signals.", "Found in bananas, potatoes, beans, and leafy greens.", "Deficiency can cause muscle weakness and heart issues."))
    ),
    "Trace Minerals" = list(
      copper      = list(name = "Copper (Cu)"    , context = list("Essential for iron metabolism, connective tissue formation, and immune function.", "Found in organ meats, shellfish, nuts, and seeds.", "Excess copper can be toxic, especially in species prone to copper accumulation (e.g., some primates and dogs).")),
      iodine      = list(name = "Iodine (I)"     , context = list("Crucial for thyroid hormone production (supports metabolism and growth).", "Found in seafood, seaweed, dairy, and iodized salt.", "Deficiency leads to goiter and thyroid dysfunction.")),
      iron        = list(name = "Iron (Fe)"      , context = list("Essential for oxygen transport (hemoglobin), energy metabolism, and immune function.", "Found in red meat, liver, legumes, and dark leafy greens.", "Heme iron (from animal sources) is more bioavailable than non-heme iron (from plants).", "Excess iron can cause oxidative stress, especially in species adapted to low-iron diets (e.g., some bats and primates).")),
      manganese   = list(name = "Manganese (Mn)" , context = list("Needed for bone development, antioxidant function, and metabolism.", "Found in nuts, whole grains, tea, and leafy greens.", "Deficiency is rare but can affect bone health and enzyme function.")),
      zinc        = list(name = "Zinc (Zn)"      , context = list("Supports immune function, wound healing, and enzyme activity.", "Found in meat, shellfish, legumes, and seeds.", "Deficiency can cause skin lesions, slow healing, and immune suppression."))
    )
  ),
  vitamins = list(
    "Carotenoids & Vitamin Precursors"       = list(
      beta_carotene           = list(name = "Beta-Carotene", context = list("A provitamin A carotenoid, meaning it can be converted into vitamin A in some species.", "Found in carrots, sweet potatoes, and leafy greens.", "Not all species efficiently convert it—carnivores like cats require preformed vitamin A.")),
      lycopene                = list(name = "Lycopene"     , context = list("A carotenoid antioxidant with no vitamin A activity but protective against oxidative stress.", "Found in tomatoes, red peppers, and watermelon.", "Important for skin health and cellular protection."))
    ),
    "Water-Soluble Vitamins (B-Complex & C)" = list(
      choline                 = list(name = "Choline"                      , context = list("Not technically a vitamin, but often grouped with B vitamins.", "Essential for nerve signaling, brain development, and liver function.", "Found in eggs, liver, and soybeans.")),
      folic_acid              = list(name = "Folic Acid (Vitamin B9)"      , context = list("Essential for DNA synthesis, cell division, and fetal development.", "Found in leafy greens, legumes, and liver.")),
      vit_B1_thiamin          = list(name = "Vitamin B1 (Thiamin)"         , context = list("Required for carbohydrate metabolism and nerve function.", "Found in whole grains, pork, and legumes.", "Deficiency can cause neurological issues, particularly in high-fish diets (thiaminase risk).")),
      vit_B2_riboflavin       = list(name = "Vitamin B2 (Riboflavin)"      , context = list("Important for energy production and antioxidant defense.", "Found in dairy, eggs, and lean meats.")),
      vit_B3_niacin           = list(name = "Vitamin B3 (Niacin)"          , context = list("Supports metabolism and DNA repair.", "Found in meat, fish, and whole grains.", "Some species (e.g., cats) require preformed niacin, as they cannot synthesize it efficiently.")),
      vit_B5_pantothenic_acid = list(name = "Vitamin B5 (Pantothenic Acid)", context = list("Essential for coenzyme A (CoA) synthesis, involved in fat and carbohydrate metabolism.", "Found in meat, eggs, and whole grains.")),
      vit_B6_pyridoxine       = list(name = "Vitamin B6 (Pyridoxine)"      , context = list("Important for protein metabolism and neurotransmitter function.", "Found in bananas, poultry, and fish.")),
      vit_B7_biotin           = list(name = "Vitamin B7 (Biotin)"          , context = list("Supports fat metabolism, skin, and coat health.", "Found in eggs, nuts, and liver.", "Raw egg whites contain avidin, which inhibits biotin absorption.")),
      vit_B12                 = list(name = "Vitamin B12 (Cobalamin)"      , context = list("Essential for nerve function and red blood cell production.", "Found only in animal products (meat, eggs, dairy).", "Strict herbivores may need supplementation.")),
      vit_C                   = list(name = "Vitamin C (Ascorbic Acid)"    , context = list("Antioxidant and collagen synthesis vitamin.", "Found in fruits and vegetables (citrus, bell peppers).", "Most mammals synthesize vitamin C, but primates, guinea pigs, and some bats require dietary sources."))
      
    ),
    "Fat-Soluble Vitamins (A, D, E, K)"      = list(
      vit_A                   = list(name = "Vitamin A (Retinol, Retinal, Retinoic Acid)", context = list("Crucial for vision, immune function, and reproduction.", "Found in liver, fish oil, and dairy.", "Toxic in excess, especially in species that accumulate vitamin A (e.g., cats).")),
      vit_D3                  = list(name = "Vitamin D3 (Cholecalciferol)"               , context = list("Regulates calcium and phosphorus metabolism.", "Synthesized in skin via UVB exposure or obtained from fatty fish, liver, and egg yolks.", "Some nocturnal species may require dietary vitamin D3 supplementation.")),
      vit_E                   = list(name = "Vitamin E (Tocopherols & Tocotrienols)"     , context = list("A powerful antioxidant that protects cell membranes.", "Found in nuts, seeds, and plant oils.", "Deficiency can lead to muscle degeneration and immune dysfunction.")),
      vit_K                   = list(name = "Vitamin K (Phylloquinone & Menaquinone)"    , context = list("Essential for blood clotting and bone metabolism.", "Found in leafy greens (K1) and fermented foods (K2).", "Some gut bacteria produce K2, so deficiencies are rare but can occur with certain medications."))
    )
  )
)
foods_mg <- list(
  baseline = list(
    "biscuit"          = 13200,
    "invertebrates"    = 10000,
    "gum_arabic"       = 12000,
    "protein_rotate"   = 2100,
    "seasonal_veggies" = 15000
  ),
  biscuit_elimination = list(
      "biscuit"          = 0,
      "invertebrates"    = 18000,
      "gum_arabic"       = 17000,
      "protein_rotate"   = 5000,
      "seasonal_veggies" = 30000
    ),
  less_Bugs_more_Egg = list(
      "biscuit"            = 13200,
      "invertebrates"      = 8000,
      "gum_arabic"         = 10000,
      "egg_whole_cooked"   = 5000,
      "sweet_potato_raw"   = 5000,
      "green_bean_fresh"   = 10000,
      "carrot"             = 5000,
      "canned_pumpkin"     = 5000
    ),
  sweet_potato_green_beans_carrots_pumpkin = list(
      "biscuit"            = 13200,
      "invertebrates"      = 8000,
      "gum_arabic"         = 10000,
      "egg_whole_cooked"   = 5000,
      "sweet_potato_raw"   = 5000,
      "green_bean_fresh"   = 10000,
      "carrot"             = 5000,
      "canned_pumpkin"     = 5000
    ),
  oatmeal_gel = list(
      "biscuit"            = 13200,
      "invertebrates"      = 8000,
      "gum_arabic"         = 12000,
      "HDZ_oatmeal_gel"         = 5000,
      "protein_rotate"     = 2100,
      "seasonal_veggies"   = 20000
    ),
  low_lectin = list(
      "biscuit"            = 0,
      "invertebrates"      = 18000,
      "gum_arabic"         = 17000,
      "egg_white_cooked"   = 5000,
      "sweet_potato_cooked"= 5000,
      "carrot"             = 10000,
      "celery"             = 5000,
      "lettuce_romaine"    = 5000
    ),
  gum36_veg37_invert27 = list(
      "biscuit"            = 0,
      "invertebrates"      = 18000,
      "gum_arabic"         = 24000,
      "seasonal_veggies"   = 25000
    ),
  water31_root31_protein19_gum19 = list(
      "egg_whole_raw"           = 9000,
      "invertebrates"           = 9000,
      "gum_arabic"              = 18000,
      "seasonal_veggies_root"   = 30000,
      "seasonal_veggies_watery" = 30000
    )
)

nutrient_totals <- list(
  baseline                       = list(mg_fed = 52000      , mg_dry = 29000      , kcal = 90),
  biscuit_elimination                   = list(mg_fed = 70000      , mg_dry = 28243      , kcal = 90),
  less_Bugs_more_Egg                = list(mg_fed = 53200      , mg_dry = 27982.29167, kcal = 92),
  sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 61200      , mg_dry = 28454.5    , kcal = 90),
  oatmeal_gel                         = list(mg_fed = 60342.85714, mg_dry = 29904.58333, kcal = 90),
  low_lectin                     = list(mg_fed = 65000      , mg_dry = 29799.75   , kcal = 93),
  gum36_veg37_invert27           = list(mg_fed = 67000      , mg_dry = 32127.41667, kcal = 87),
  water31_root31_protein19_gum19 = list(mg_fed = 96000      , mg_dry = 30136.91071, kcal = 88)
)
  

proteins <- list(
  totals = list(
    baseline                       = list(mg_fed = 5100      , proportion = 0.172) ,
    biscuit_elimination                   = list(mg_fed = 4444      , proportion = 0.2    ),
    less_Bugs_more_Egg                = list(mg_fed = 5692.84375, proportion = 0.20344),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 5132.76667, proportion = 0.18039),
    oatmeal_gel                         = list(mg_fed = 4826.53571, proportion = 0.1614 ),
    low_lectin                     = list(mg_fed = 7375.20417, proportion = 0.24749),
    gum36_veg37_invert27           = list(mg_fed = 3747.0375 , proportion = 0.11663),
    water31_root31_protein19_gum19 = list(mg_fed = 3765.82986, proportion = 0.12496)
    ),
  taurine = list(
    baseline                       = list(mg_fed = 20    , proportion = 0.0006 ),
    biscuit_elimination                   = list(mg_fed = 0     , proportion = 0      ),
    less_Bugs_more_Egg                = list(mg_fed = 17.952, proportion = 0.00064),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 17.952, proportion = 0.00063),
    oatmeal_gel                         = list(mg_fed = 17.952, proportion = 0.0006 ),
    low_lectin                     = list(mg_fed = 0     , proportion = 0      ),
    gum36_veg37_invert27           = list(mg_fed = 0     , proportion = 0      ),
    water31_root31_protein19_gum19 = list(mg_fed = 0     , proportion = 0      )
  ),
  methionine = list(
    baseline                       = list(mg_fed = 90       , proportion = 0.0031     ),
    biscuit_elimination                   = list(mg_fed = 63.79    , proportion = 0.002258657),
    less_Bugs_more_Egg                = list(mg_fed = 130.34071, proportion = 0.00466    ),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 101.63   , proportion = 0.00357    ),
    oatmeal_gel                         = list(mg_fed = 86.58715 , proportion = 0.0029     ),
    low_lectin                     = list(mg_fed = 198.55   , proportion = 0.00666    ),
    gum36_veg37_invert27           = list(mg_fed = 50.01429 , proportion = 0.00156    ),
    water31_root31_protein19_gum19 = list(mg_fed = 70.49786 , proportion = 0.00234    )
  )
)


fats <- list(
  totals = list(
    baseline                       = list(mg_fed = 2000      , proportion = 0.054      ),
    biscuit_elimination                   = list(mg_fed = 1861      , proportion = 0.065905076),
    less_Bugs_more_Egg                = list(mg_fed = 2655.69415, proportion = 0.09491    ),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 1806.97933, proportion = 0.0635     ),
    oatmeal_gel                         = list(mg_fed = 1618.96429, proportion = 0.05414    ),
    low_lectin                     = list(mg_fed = 1018.84933, proportion = 0.03419    ),
    gum36_veg37_invert27           = list(mg_fed = 1016.60137, proportion = 0.03164    ),
    water31_root31_protein19_gum19 = list(mg_fed = 1655.85244, proportion = 0.05494    )
  ),
  omega3 = list(
    baseline                       = list(mg_fed = 635   , mg_g = 2.2    ),
    biscuit_elimination                   = list(mg_fed = 1513  , mg_g = 0.0054 ),
    less_Bugs_more_Egg                = list(mg_fed = 634.49, mg_g = 2.2675 ),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 634.49, mg_g = 2.22984),
    oatmeal_gel                         = list(mg_fed = 634.49, mg_g = 2.12231),
    low_lectin                     = list(mg_fed = 634.49, mg_g = 0.00508),
    gum36_veg37_invert27           = list(mg_fed = 634.49, mg_g = 0.00665),
    water31_root31_protein19_gum19 = list(mg_fed = 634.49, mg_g = 0.00532)
  ),
  omega6 = list(
    baseline                       = list(mg_fed = 3370  , mg_g = 11.5    ),
    biscuit_elimination                   = list(mg_fed = 5440  , mg_g = 0.0193  ),
    less_Bugs_more_Egg                = list(mg_fed = 3369.2, mg_g = 12.0405 ),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 3369.2, mg_g = 11.84066),
    oatmeal_gel                         = list(mg_fed = 3369.2, mg_g = 11.26864),
    low_lectin                     = list(mg_fed = 3369.2, mg_g = 0.01826 ),
    gum36_veg37_invert27           = list(mg_fed = 3369.2, mg_g = 0.02390 ),
    water31_root31_protein19_gum19 = list(mg_fed = 3369.2, mg_g = 0.01911 )
  )
)


CHOs <- list(
  totals = list(
    baseline                       = list(mg_fed = 2000      , proportion = 0.054),
    biscuit_elimination                   = list(mg_fed = 3306      , proportion = 0.117051162),
    less_Bugs_more_Egg                = list(mg_fed = 991.69565 , proportion = 0.03544),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 2642.5    , proportion = 0.09287),
    oatmeal_gel                         = list(mg_fed = 2005.1413 , proportion = 0.06705),
    low_lectin                     = list(mg_fed = 2485.5    , proportion = 0.08341),
    gum36_veg37_invert27           = list(mg_fed = 2059.23913, proportion = 0.06410),
    water31_root31_protein19_gum19 = list(mg_fed = 5548.42500, proportion = 0.18411)
  ),
  WSC = list(
    baseline                       = list(mg_fed = 0, proportion = 0),
    biscuit_elimination                   = list(mg_fed = 0, proportion = 0),
    less_Bugs_more_Egg                = list(mg_fed = 0, proportion = 0),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 0, proportion = 0),
    oatmeal_gel                         = list(mg_fed = 0, proportion = 0),
    low_lectin                     = list(mg_fed = 0, proportion = 0),
    gum36_veg37_invert27           = list(mg_fed = 0, proportion = 0),
    water31_root31_protein19_gum19 = list(mg_fed = 0, proportion = 0)
  ),
  starch = list(
    baseline                       = list(mg_fed = 3000      , proportion = 0.093),
    biscuit_elimination                   = list(mg_fed = 1175.7    , proportion = 0.041628505),
    less_Bugs_more_Egg                = list(mg_fed = 2488.56667, proportion = 0.08893),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 2931.66667, proportion = 0.10303),
    oatmeal_gel                         = list(mg_fed = 3102.91905, proportion = 0.10376),
    low_lectin                     = list(mg_fed = 863.16667 , proportion = 0.02897),
    gum36_veg37_invert27           = list(mg_fed = 831.41667 , proportion = 0.02588),
    water31_root31_protein19_gum19 = list(mg_fed = 2619.25263, proportion = 0.08691)
  ),
  NDF = list(
    baseline                       = list(mg_fed = 9000       , proportion = 0.321),
    biscuit_elimination                   = list(mg_fed = 9243.2     , proportion = 0.32727783),
    less_Bugs_more_Egg                = list(mg_fed = 8137.84222 , proportion = 0.29082),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 8539.042   , proportion = 0.30009),
    oatmeal_gel                         = list(mg_fed = 9629.23644 , proportion = 0.322),
    low_lectin                     = list(mg_fed = 9141.782   , proportion = 0.30677),
    gum36_veg37_invert27           = list(mg_fed = 12311.33756, proportion = 0.3832),
    water31_root31_protein19_gum19 = list(mg_fed = 9657.06145 , proportion = 0.32044)
  ),
  ADF = list(
    baseline                       = list(mg_fed = 2000      , proportion = 0.081),
    biscuit_elimination                   = list(mg_fed = 763.86    , proportion = 0.027046144),
    less_Bugs_more_Egg                = list(mg_fed = 2196.54127, proportion = 0.0785),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 2387.31714, proportion = 0.0839),
    oatmeal_gel                         = list(mg_fed = 2435.20325, proportion = 0.08143),
    low_lectin                     = list(mg_fed = 681.28857 , proportion = 0.02286),
    gum36_veg37_invert27           = list(mg_fed = 711.17746 , proportion = 0.02214),
    water31_root31_protein19_gum19 = list(mg_fed = 798.50338 , proportion = 0.0265)
  ),
  crude_fiber = list(
    baseline                       = list(mg_fed = 12000, proportion = 0.422),
    biscuit_elimination                   = list(mg_fed = 15300, proportion = 0.541733548),
    less_Bugs_more_Egg                = list(mg_fed = 10595, proportion = 0.37863),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 10595, proportion = 0.37235),
    oatmeal_gel                         = list(mg_fed = 12395, proportion = 0.41448),
    low_lectin                     = list(mg_fed = 15300, proportion = 0.51343),
    gum36_veg37_invert27           = list(mg_fed = 21600, proportion = 0.51343),
    water31_root31_protein19_gum19 = list(mg_fed = 16200, proportion = 0.53755)
  ),
  TDF = list(
    baseline                       = list(mg_fed = 1000     , proportion = 0.018),
    biscuit_elimination                   = list(mg_fed = 1073.62  , proportion = 0.038014127),
    less_Bugs_more_Egg                = list(mg_fed = 270.69565, proportion = 0.00967),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 820.2    , proportion = 0.02882),
    oatmeal_gel                         = list(mg_fed = 606.16274, proportion = 0.02027),
    low_lectin                     = list(mg_fed = 874.2    , proportion = 0.02934),
    gum36_veg37_invert27           = list(mg_fed = 755.93913, proportion = 0.02353),
    water31_root31_protein19_gum19 = list(mg_fed = 1408.35  , proportion = 0.04673)
  )
)  

Ash <- list(
  totals = list(
    baseline                       = list(mg_fed = 2000      , proportion = 0.062      , ca_p_ratio  = 1.93),
    biscuit_elimination                   = list(mg_fed = 1431      , proportion = 0.050675903, ca_p_ratio  = 1.93),
    less_Bugs_more_Egg                = list(mg_fed = 1721.86155, proportion = 0.06153    , ca_p_ratio  = 1.95096),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 1764.36233, proportion = 0.06201    , ca_p_ratio  = 1.86483),
    oatmeal_gel                         = list(mg_fed = 1816.25337, proportion = 0.06073    , ca_p_ratio  = 2.03403),
    low_lectin                     = list(mg_fed = 1531.76108, proportion = 0.05140    , ca_p_ratio  = 1.74059),
    gum36_veg37_invert27           = list(mg_fed = 1647.6457 , proportion = 0.05128    , ca_p_ratio  = 2.30977),
    water31_root31_protein19_gum19 = list(mg_fed = 1560.31388, proportion = 0.05177    , ca_p_ratio  = 2.37506)
  ),
  calcium = list(
    baseline                       = list(mg_fed = 321.7701592, proportion = 0.01096414),
    biscuit_elimination                   = list(mg_fed = 257.32     , proportion = 0.009110887),
    less_Bugs_more_Egg                = list(mg_fed = 290.22518  , proportion = 0.01037),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 297.2016   , proportion = 0.01044),
    oatmeal_gel                         = list(mg_fed = 319.66248  , proportion = 0.01069),
    low_lectin                     = list(mg_fed = 254.7411   , proportion = 0.00855),
    gum36_veg37_invert27           = list(mg_fed = 332.46719  , proportion = 0.01035),
    water31_root31_protein19_gum19 = list(mg_fed = 254.52055  , proportion = 0.00845)
  ),
  phosphorus = list(
    baseline                       = list(mg_fed = 167.1484216, proportion = 0.00569549),
    biscuit_elimination                   = list(mg_fed = 157.91     , proportion = 0.005591296),
    less_Bugs_more_Egg                = list(mg_fed = 148.76029  , proportion = 0.00532),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 159.3716   , proportion = 0.0056),
    oatmeal_gel                         = list(mg_fed = 157.15731  , proportion = 0.00526),
    low_lectin                     = list(mg_fed = 146.3536   , proportion = 0.00491),
    gum36_veg37_invert27           = list(mg_fed = 143.93931  , proportion = 0.00448),
    water31_root31_protein19_gum19 = list(mg_fed = 107.16394  , proportion = 0.00356)
  ),
  potassium = list(
    baseline                       = list(mg_fed = 322.688967, proportion = 0.00569549),
    biscuit_elimination                   = list(mg_fed = 334.71    , proportion = 0.011851272),
    less_Bugs_more_Egg                = list(mg_fed = 264.31908 , proportion = 0.00945),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 320.23034 , proportion = 0.01125),
    oatmeal_gel                         = list(mg_fed = 322.43378 , proportion = 0.01078),
    low_lectin                     = list(mg_fed = 366.38577 , proportion = 0.01229),
    gum36_veg37_invert27           = list(mg_fed = 329.17668 , proportion = 0.01025),
    water31_root31_protein19_gum19 = list(mg_fed = 330.54289 , proportion = 0.01097)
  ),
  magnesium = list(
    baseline                       = list(mg_fed = 157.3827213, proportion = 0.005362729),
    biscuit_elimination                   = list(mg_fed = 257.78     , proportion = 0.009127275),
    less_Bugs_more_Egg                = list(mg_fed = 113.78598  , proportion = 0.00407),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 51.3928    , proportion = 0.00181),
    oatmeal_gel                         = list(mg_fed = 190.93112  , proportion = 0.00638),
    low_lectin                     = list(mg_fed = 50.2238    , proportion = 0.00169),
    gum36_veg37_invert27           = list(mg_fed = 228.28999  , proportion = 0.00711),
    water31_root31_protein19_gum19 = list(mg_fed = 356.98761  , proportion = 0.01185)
  ),
  copper = list(
    baseline                       = list(mg_fed = 0.5    , mg_kg = 16),
    biscuit_elimination                   = list(mg_fed = 0.1    , mg_kg = 5.0155),
    less_Bugs_more_Egg                = list(mg_fed = 0.42528, mg_kg = 15.1983),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 0.45428, mg_kg = 15.96503),
    oatmeal_gel                         = list(mg_fed = 0.45601, mg_kg = 15.24881),
    low_lectin                     = list(mg_fed = 0.1363 , mg_kg = 4.57389),
    gum36_veg37_invert27           = list(mg_fed = 0.13316, mg_kg = 4.14484),
    water31_root31_protein19_gum19 = list(mg_fed = 0.11077, mg_kg = 3.67543)
  ),
  iron = list(
    baseline                       = list(mg_fed = 5.5    , mg_kg = 188),
    biscuit_elimination                   = list(mg_fed = 4.3    , mg_kg = 153.4236),
    less_Bugs_more_Egg                = list(mg_fed = 4.50299, mg_kg = 160.9229),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 4.92512, mg_kg = 173.08756),
    oatmeal_gel                         = list(mg_fed = 5.31891, mg_kg = 177.86267),
    low_lectin                     = list(mg_fed = 3.39732, mg_kg = 114.00498),
    gum36_veg37_invert27           = list(mg_fed = 3.6698 , mg_kg = 114.22634),
    water31_root31_protein19_gum19 = list(mg_fed = 2.53316, mg_kg = 84.05507)
  ),
  zinc = list(
    baseline                       = list(mg_fed = 2.5    , mg_kg = 86),
    biscuit_elimination                   = list(mg_fed = 1.2    , mg_kg = 41.8857),
    less_Bugs_more_Egg                = list(mg_fed = 2.35165, mg_kg = 84.0407),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 2.44255, mg_kg = 85.84055),
    oatmeal_gel                         = list(mg_fed = 2.43729, mg_kg = 81.50225),
    low_lectin                     = list(mg_fed = 1.07555, mg_kg = 36.09249),
    gum36_veg37_invert27           = list(mg_fed = 1.09124, mg_kg = 33.96603),
    water31_root31_protein19_gum19 = list(mg_fed = 0.78669, mg_kg = 26.10390)
  ),
  manganese = list(
    baseline                       = list(mg_fed = 1.5    , mg_kg = 50),
    biscuit_elimination                   = list(mg_fed = 0.4    , mg_kg = 12.4065),
    less_Bugs_more_Egg                = list(mg_fed = 1.38766, mg_kg = 49.5905),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 1.45356, mg_kg = 51.08364),
    oatmeal_gel                         = list(mg_fed = 1.46863, mg_kg = 49.11047),
    low_lectin                     = list(mg_fed = 0.30859, mg_kg = 10.3554),
    gum36_veg37_invert27           = list(mg_fed = 0.32665, mg_kg = 10.16727),
    water31_root31_protein19_gum19 = list(mg_fed = 0.26483, mg_kg = 8.78754)
  ),
  iodine = list(
    baseline                       = list(mg_fed = 0      , mg_kg = 0.7),
    biscuit_elimination                   = list(mg_fed = 0      , mg_kg = 0),
    less_Bugs_more_Egg                = list(mg_fed = 0.02172, mg_kg = 0.7763),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 0.02172, mg_kg = 0.76344),
    oatmeal_gel                         = list(mg_fed = 0.02172, mg_kg = 0.72642),
    low_lectin                     = list(mg_fed = 0.00014, mg_kg = 0.0047),
    gum36_veg37_invert27           = list(mg_fed = 0      , mg_kg = 0),
    water31_root31_protein19_gum19 = list(mg_fed = 0      , mg_kg = 0)
  )
) 

vitamins <- list(
  totals = list(
    baseline                       = list(mg_fed = 0, mg_kg = 0),
    biscuit_elimination                   = list(mg_fed = 0, mg_kg = 0),
    less_Bugs_more_Egg                = list(mg_fed = 0, mg_kg = 0),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 0, mg_kg = 0),
    oatmeal_gel                         = list(mg_fed = 0, mg_kg = 0),
    low_lectin                     = list(mg_fed = 0, mg_kg = 0),
    gum36_veg37_invert27           = list(mg_fed = 0, mg_kg = 0),
    water31_root31_protein19_gum19 = list(mg_fed = 0, mg_kg = 0)
  ),
  vit_A = list(
    baseline                       = list(mg_fed = 641       , IU_g = 22),
    biscuit_elimination                   = list(mg_fed = 732       , IU_g = 25.9006),
    less_Bugs_more_Egg                = list(mg_fed = 593.10984 , IU_g = 21.1959),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 2694.5646 , IU_g = 94.69731),
    oatmeal_gel                         = list(mg_fed = 760.41222 , IU_g = 25.42795),
    low_lectin                     = list(mg_fed = 2837.95   , IU_g = 95.23402),
    gum36_veg37_invert27           = list(mg_fed = 596.7381  , IU_g = 18.57411),
    water31_root31_protein19_gum19 = list(mg_fed = 2002.58571, IU_g = 66.44960)
  ),
  vit_D3 = list(
    baseline                       = list(mg_fed = 131    , IU_g = 4),
    biscuit_elimination                   = list(mg_fed = 97.3   , IU_g = 3.4434),
    less_Bugs_more_Egg                = list(mg_fed = 131.596, IU_g = 4.7028),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 122.896, IU_g = 4.31904),
    oatmeal_gel                         = list(mg_fed = 130.858, IU_g = 4.37585),
    low_lectin                     = list(mg_fed = 94.452 , IU_g = 3.16956),
    gum36_veg37_invert27           = list(mg_fed = 133.344, IU_g = 4.15047),
    water31_root31_protein19_gum19 = list(mg_fed = 107.838, IU_g = 3.57827)
  ),
  vit_E = list(
    baseline                       = list(mg_fed = 6      , mg_kg = 190),
    biscuit_elimination                   = list(mg_fed = 4.5    , mg_kg = 158.0895),
    less_Bugs_more_Egg                = list(mg_fed = 5.00225, mg_kg = 178.765),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 5.1554 , mg_kg = 181.18034),
    oatmeal_gel                         = list(mg_fed = 6.97048, mg_kg = 233.09054),
    low_lectin                     = list(mg_fed = 4.39583, mg_kg = 147.51238),
    gum36_veg37_invert27           = list(mg_fed = 5.68865, mg_kg = 177.06542),
    water31_root31_protein19_gum19 = list(mg_fed = 4.17978, mg_kg = 138.69307)
  ),
  vit_K = list(
    baseline                       = list(mg_fed = 0.048859, mg_kg = 1.7),
    biscuit_elimination                   = list(mg_fed = 0       , mg_kg = 0.7201),
    less_Bugs_more_Egg                = list(mg_fed = 0.04627 , mg_kg = 1.6535),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 0.05074 , mg_kg = 1.78323),
    oatmeal_gel                         = list(mg_fed = 0.04953 , mg_kg = 1.65643),
    low_lectin                     = list(mg_fed = 0.02413 , mg_kg = 0.80957),
    gum36_veg37_invert27           = list(mg_fed = 0.02617 , mg_kg = 0.81465),
    water31_root31_protein19_gum19 = list(mg_fed = 0.02382 , mg_kg = 0.79047)
  ),
  vit_B1_thiamin = list(
    baseline                       = list(mg_fed = 0.196003, mg_kg = 7),
    biscuit_elimination                   = list(mg_fed = 0.055   , mg_kg = 1.94),
    less_Bugs_more_Egg                = list(mg_fed = 0.19234 , mg_kg = 6.8737),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 0.19914 , mg_kg = 6.99854),
    oatmeal_gel                         = list(mg_fed = 0.19693 , mg_kg = 6.58529),
    low_lectin                     = list(mg_fed = 0.043   , mg_kg = 1.44297),
    gum36_veg37_invert27           = list(mg_fed = 0.04498 , mg_kg = 1.40008),
    water31_root31_protein19_gum19 = list(mg_fed = 0.0607  , mg_kg = 2.01405)
  ),
  vit_B2_riboflavin = list(
    baseline                       = list(mg_fed = 0.29455, mg_kg = 10),
    biscuit_elimination                   = list(mg_fed = 0.213  , mg_kg = 7.5462),
    less_Bugs_more_Egg                = list(mg_fed = 0.31262, mg_kg = 11.1721),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 0.30534, mg_kg = 10.73082),
    oatmeal_gel                         = list(mg_fed = 0.27704, mg_kg = 9.26405),
    low_lectin                     = list(mg_fed = 0.30765, mg_kg = 10.32391),
    gum36_veg37_invert27           = list(mg_fed = 0.19895, mg_kg = 6.19260),
    water31_root31_protein19_gum19 = list(mg_fed = 0.17153, mg_kg = 5.69183)
  ),
  vit_B3_niacin = list(
    baseline                       = list(mg_fed = 1.957192, mg_kg = 67),
    biscuit_elimination                   = list(mg_fed = 0.962   , mg_kg = 34.0582),
    less_Bugs_more_Egg                = list(mg_fed = 1.70526 , mg_kg = 60.9407),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 1.89955 , mg_kg = 66.75745),
    oatmeal_gel                         = list(mg_fed = 1.92509 , mg_kg = 64.37443),
    low_lectin                     = list(mg_fed = 0.81165 , mg_kg = 27.23681),
    gum36_veg37_invert27           = list(mg_fed = 0.79862 , mg_kg = 24.85802),
    water31_root31_protein19_gum19 = list(mg_fed = 0.7196  , mg_kg = 23.87755)
  ),
  choline = list(
    baseline                       = list(mg_fed = 37.545567, mg_kg = 1168.97601747296),
    biscuit_elimination                   = list(mg_fed = 33.015   , mg_kg = 1168.976),
    less_Bugs_more_Egg                = list(mg_fed = 72.28271 , mg_kg = 2583.1591),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 48.8966  , mg_kg = 1718.41361),
    oatmeal_gel                         = list(mg_fed = 35.42382 , mg_kg = 1184.56164),
    low_lectin                     = list(mg_fed = 27.825   , mg_kg = 933.73267),
    gum36_veg37_invert27           = list(mg_fed = 28.27528 , mg_kg = 880.09808),
    water31_root31_protein19_gum19 = list(mg_fed = 46.25473 , mg_kg = 1534.8198)
  ),
  vit_B5_pantothenic_acid = list(
    baseline                       = list(mg_fed = 1.195088, mg_kg = 41),
    biscuit_elimination                   = list(mg_fed = 0.499   , mg_kg = 17.6565),
    less_Bugs_more_Egg                = list(mg_fed = 1.27381 , mg_kg = 45.5222),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 1.25365 , mg_kg = 44.05806),
    oatmeal_gel                         = list(mg_fed = 1.17367 , mg_kg = 39.24709),
    low_lectin                     = list(mg_fed = 0.53635 , mg_kg = 17.99847),
    gum36_veg37_invert27           = list(mg_fed = 0.44874 , mg_kg = 13.96738),
    water31_root31_protein19_gum19 = list(mg_fed = 0.51371 , mg_kg = 17.04597)
  ),
  vit_B6_pyridoxine = list(
    baseline                       = list(mg_fed = 0.26034, mg_kg = 9),
    biscuit_elimination                   = list(mg_fed = 0.096  , mg_kg = 3.403),
    less_Bugs_more_Egg                = list(mg_fed = 0.25503, mg_kg = 9.1139),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 0.27178, mg_kg = 9.55139),
    oatmeal_gel                         = list(mg_fed = 0.26179, mg_kg = 8.75416),
    low_lectin                     = list(mg_fed = 0.08041, mg_kg = 2.69834),
    gum36_veg37_invert27           = list(mg_fed = 0.08094, mg_kg = 2.51945),
    water31_root31_protein19_gum19 = list(mg_fed = 0.11476, mg_kg = 3.80793)
  ),
  vit_B7_biotin = list(
    baseline                       = list(mg_fed = 0.008388, mg_kg = 0.29),
    biscuit_elimination                   = list(mg_fed = 0.006   , mg_kg = 0.2135),
    less_Bugs_more_Egg                = list(mg_fed = 0.00671 , mg_kg = 0.2399),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 0.00772 , mg_kg = 0.27124),
    oatmeal_gel                         = list(mg_fed = 0.00822 , mg_kg = 0.27481),
    low_lectin                     = list(mg_fed = 0.00613 , mg_kg = 0.20571),
    gum36_veg37_invert27           = list(mg_fed = 0.00603 , mg_kg = 0.18769),
    water31_root31_protein19_gum19 = list(mg_fed = 0.00302 , mg_kg = 0.10004)
  ),
  folic_acid = list(
    baseline                       = list(mg_fed = 0.24385, mg_kg = 8),
    biscuit_elimination                   = list(mg_fed = 0.011  , mg_kg = 0.3983),
    less_Bugs_more_Egg                = list(mg_fed = 0.24073, mg_kg = 8.6028),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 0.2426 , mg_kg = 8.52589),
    oatmeal_gel                         = list(mg_fed = 0.2426 , mg_kg = 8.11247),
    low_lectin                     = list(mg_fed = 0.01125, mg_kg = 0.37752),
    gum36_veg37_invert27           = list(mg_fed = 0.01125, mg_kg = 0.35017),
    water31_root31_protein19_gum19 = list(mg_fed = 0.00563, mg_kg = 0.18665)
  ),
  vit_B12 = list(
    baseline                       = list(mg_fed = 0.0563012, ug_kg = 1.92),
    biscuit_elimination                   = list(mg_fed = 0.1      , ug_kg = 3.5378),
    less_Bugs_more_Egg                = list(mg_fed = 0.02871  , ug_kg = 1.026),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 0.04525  , ug_kg = 1.59025),
    oatmeal_gel                         = list(mg_fed = 0.0452   , ug_kg = 1.51152),
    low_lectin                     = list(mg_fed = 0.09992  , ug_kg = 3.3532),
    gum36_veg37_invert27           = list(mg_fed = 0.09990  , ug_kg = 3.10949),
    water31_root31_protein19_gum19 = list(mg_fed = 0.05005  , ug_kg = 1.66075)
  ),
  vit_C = list(
    baseline                       = list(mg_fed = 11.7    , mg_kg = 400),
    biscuit_elimination                   = list(mg_fed = 8.199   , mg_kg = 290.2894),
    less_Bugs_more_Egg                = list(mg_fed = 10.14728, mg_kg = 362.6323),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 10.1506 , mg_kg = 356.73092),
    oatmeal_gel                         = list(mg_fed = 12.60268, mg_kg = 421.42964),
    low_lectin                     = list(mg_fed = 2.784   , mg_kg = 93.4236),
    gum36_veg37_invert27           = list(mg_fed = 7.03945 , mg_kg = 219.11051),
    water31_root31_protein19_gum19 = list(mg_fed = 11.9245 , mg_kg = 395.67758)
  ),
  beta_carotene = list(
    baseline                       = list(mg_fed = 0.3    , mg_kg = 10),
    biscuit_elimination                   = list(mg_fed = 0.365  , mg_kg = 12.9073),
    less_Bugs_more_Egg                = list(mg_fed = 0.21937, mg_kg = 7.8394),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 1.32197, mg_kg = 46.45908),
    oatmeal_gel                         = list(mg_fed = 0.33946, mg_kg = 11.35145),
    low_lectin                     = list(mg_fed = 1.5285 , mg_kg = 51.29238),
    gum36_veg37_invert27           = list(mg_fed = 0.30174, mg_kg = 9.39192),
    water31_root31_protein19_gum19 = list(mg_fed = 1.02329, mg_kg = 33.95471)
  ),
  lycopene = list(
    baseline                       = list(mg_fed = 0.0192825, ug_kg = 1),
    biscuit_elimination                   = list(mg_fed = 0.039    , ug_kg = 1.3655),
    less_Bugs_more_Egg                = list(mg_fed = 0.01286  , ug_kg = 0.4594),
    sweet_potato_green_beans_carrots_pumpkin                      = list(mg_fed = 0.00005  , ug_kg = 0.00176),
    oatmeal_gel                         = list(mg_fed = 0.02571  , ug_kg = 0.85973),
    low_lectin                     = list(mg_fed = 0.0001   , ug_kg = 0.00336),
    gum36_veg37_invert27           = list(mg_fed = 0.03214  , ug_kg = 1.00031),
    water31_root31_protein19_gum19 = list(mg_fed = 0.05936  , ug_kg = 1.9696)
  )
) 

diet_footnotes <- list(
  "Gum supplement is Mazuri Enrich Gum Arabic (5B35)"
)

nameby_diet <- function(list) {
  set_names(list, map_chr(list, ~ as.character(.x$diet$phase_name)))
}

nameby_begin <- function(list) {
  set_names(list, map_chr(list, ~ as.character(.x$begin)))
}

diet_trials <- list(
  list(begin = ymd(path$day1   ), diet = "baseline"),
  list(begin = ymd("2023-11-23"), diet = "oatmeal_gel"), 
  list(begin = ymd("2023-12-14"), diet = "baseline"),
  list(begin = ymd("2024-01-25"), diet = "oatmeal_gel"),
  list(begin = ymd("2024-05-29"), diet = "baseline"), 
  list(begin = ymd("2024-06-15"), diet = "biscuit_elimination"),
  list(begin = ymd("2024-06-29"), diet = "less_bugs_more_egg"),
  list(begin = ymd("2024-07-13"), diet = "sweet_potato_green_beans_carrots_pumpkin"), 
  list(begin = ymd("2024-07-27"), diet = "baseline"),  
  list(begin = ymd("2024-08-10"), diet = "oatmeal_gel"), 
  list(begin = ymd("2024-08-24"), diet = "baseline"), 
  list(begin = ymd("2024-09-21"), diet = "low_lectin"), 
  list(begin = ymd("2024-10-19"), diet = "baseline")
) %>% .[order(map_dbl(., ~ .x$begin))] 

warble_trials <- list(
  list(begin = ymd(path$day1   ), diet = "baseline")
) %>% enframe(name = NULL) %>% 
  unnest_wider(value) %>%
  mutate(diet_name = str_to_lower(diet), .keep = "unused") %>%
  mutate(end = today(), subject = "warble")

supplement_details <- list(
    fiber         = list(rx = "Metamucil"    , units = "capsules per day", route = "in gum or on biscuits", dose = list(low = 0.5, high = 1.0)),
    probiotic     = list(rx = "OTC"          , units = "drops per day"   , route = "in gum or on biscuits", dose = list(low = 5.0, high = 10.0)),
    steroid       = list(rx = "Budesonide"   , units = "mg per day"      , route = "in gum or on biscuits", dose = list(low = 0.1, high = 0.2)),
    antibiotic    = list(rx = "Metronidazole", units = "mg per day"      , route = "in gum or on biscuits", dose = 12.5 ),
    antidiarrheal = list(rx = "Loperamide"   , units = "mg per day"      , route = "in gum or on biscuits", dose = 0.08)
)

supplements <- list(
list(begin = ymd(path$day1   ),  probiotic = 00.0, steroid = 00.0, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
list(begin = ymd("2023-11-02"),  probiotic = 05.0, steroid = 00.0, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
list(begin = ymd("2023-11-07"),  probiotic = 10.0, steroid = 00.0, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
list(begin = ymd("2023-12-14"),  probiotic = 00.0, steroid = 00.1, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
list(begin = ymd("2024-01-04"),  probiotic = 00.0, steroid = 00.2, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
list(begin = ymd("2024-01-25"),  probiotic = 10.0, steroid = 00.2, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
list(begin = ymd("2024-02-20"),  probiotic = 00.0, steroid = 00.2, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
list(begin = ymd("2024-02-23"),  probiotic = 10.0, steroid = 00.2, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
list(begin = ymd("2024-04-29"),  probiotic = 10.0, steroid = 00.2, fiber = 00.0, antibiotic = 12.5, antidiarrheal = 00.00),
list(begin = ymd("2024-05-06"),  probiotic = 10.0, steroid = 00.2, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
list(begin = ymd("2024-05-29"),  probiotic = 00.0, steroid = 00.0, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
list(begin = ymd("2024-07-27"),  probiotic = 00.0, steroid = 00.0, fiber = 00.5, antibiotic = 00.0, antidiarrheal = 00.00),
list(begin = ymd("2024-08-01"),  probiotic = 00.0, steroid = 00.0, fiber = 01.0, antibiotic = 00.0, antidiarrheal = 00.00),
list(begin = ymd("2024-08-10"),  probiotic = 00.0, steroid = 00.0, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
list(begin = ymd("2024-08-24"),  probiotic = 05.0, steroid = 00.0, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
list(begin = ymd("2024-08-29"),  probiotic = 10.0, steroid = 00.0, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
list(begin = ymd("2024-09-07"),  probiotic = 00.0, steroid = 00.2, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.08),
list(begin = ymd("2024-09-21"),  probiotic = 00.0, steroid = 00.0, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
list(begin = ymd("2024-10-19"),  probiotic = 00.0, steroid = 00.2, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
list(begin = ymd("2024-11-16"),  probiotic = 00.0, steroid = 00.1, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
list(begin = ymd("2024-12-28"),  probiotic = 00.0, steroid = 00.0, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00)
)

warble_supplements <- list(
  list(begin = ymd(path$day1   ),  probiotic = 00.0, steroid = 00.0, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00)
) %>% enframe(name = NULL) %>% 
  unnest_wider(value) %>%
  mutate(end = today(), subject = "warble")

new_holding_start <- list(
    culi   = ymd("2024-02-28"),
    warble = ymd("2024-02-29")
)

pair_access <- list(
  list(begin = ymd(path$day1)   , end = ymd("2023-10-29")),
  list(begin = ymd("2024-04-02"), end = ymd("2024-04-15"))
)

access_dates <- enframe(pair_access, name = NULL) %>%
  unnest_wider(value) %>%
  mutate(pair_access = "y") %>%
  mutate(date = map2(begin, end, seq, by = "day")) %>%  
  unnest(date) %>%
  select(-c(begin, end))

cycles <- list(
  estrus = list(
    list(begin = ymd(path$day1)   , end = ymd("2023-10-29")),
    list(begin = ymd("2024-03-21"), end = ymd("2024-04-06"))
  ),
  pregnant = list(
    list(begin = ymd("2024-04-07"), end = ymd("2024-10-09"))
  )
) 

cycle_dates <- enframe(cycles, name = "warb_status") %>%
  unnest_longer(value) %>%
  unnest_wider(value) %>%
  mutate(date = map2(begin, end, seq, by = "day")) %>%  
  unnest(date) %>%
  select(-c(begin, end))

log <- list(
  
  list(date = ymd("2024-01-22"), tag = "food" , subject = list("culi") , note = "removing cauliflower and broccoli from diet rotation"),
  list(date = ymd("2024-02-20"), tag = "food" , subject = list("culi") , note = "removing tomato from diet rotation"),
  list(date = ymd("2024-03-21"), tag = "repro" , subject = list("culi")             , note = "Culi whistling and actively attempting to get to Warble"),
  list(date = ymd("2024-04-04"), tag = "repro" , subject = list("culi", "warble"), note = "Observed several breeding events"),
  list(date = ymd("2023-11-16"), tag = "health", subject = list("culi")             , note = "had what appeared to be dried blood around his anus and tail"),
  list(date = ymd("2023-12-17"), tag = "health", subject = list("culi")             , note = "coprophagy observed"),
  list(date = ymd("2024-01-21"), tag = "health", subject = list("culi")             , note = "coprophagy observed"),
  list(date = ymd("2024-02-10"), tag = "health", subject = list("culi")             , note = "left biscuit and some gum"),
  list(date = ymd("2024-04-01"), tag = "repro" , subject = list("warble")           , note = "swollen vulva"),
  list(date = ymd("2024-04-02"), tag = "repro" , subject = list("culi")             , note = "swollen testicles"),
  list(date = ymd("2024-04-03"), tag = "repro" , subject = list("culi", "warble"), note = "Keeper Zach entered the facility in the morning to clean and found Warble and Culi sleeping together in a hammock in room 3"),
  list(date = ymd("2024-04-03"), tag = "repro" , subject = list("culi", "warble"), note = "Observed breeding event"),
  list(date = ymd("2024-04-04"), tag = "repro" , subject = list("warble")           , note = "Observed whistling"),
  list(date = ymd("2024-04-04"), tag = "repro" , subject = list("culi", "warble"), note = "JM and AMR found Warble and Culi sleeping together in a hammock in room 3"),
  list(date = ymd("2024-04-04"), tag = "repro" , subject = list("warble")         , note = "swollen vulva"),
  list(date = ymd("2024-04-06"), tag = "repro" , subject = list("warble")         , note = "pregnancy suspected"),
  list(date = ymd("2024-04-14"), tag = "health", subject = list("culi")             , note = "weight = 451 g"),
  list(date = ymd("2024-05-13"), tag = "health", subject = list("warble")           , note = "weight = 467 g"),
  list(date = ymd("2024-06-17"), tag = "health", subject = list("culi")             , note = "left pieces of food in room 5"),
  list(date = ymd("2024-08-08"), tag = "health", subject = list("culi")             , note = "extremely liquid feces"),
  list(date = ymd("2024-09-08"), tag = "health", subject = list("culi")             , note = "extremely liquid feces"),
  list(date = ymd("2025-01-23"), tag = "repro" , subject = list("culi", "warble"), note = "Social grooming observed between the barriers. Culi initiated grooming by licking Warble’s head; she licked his arm, and he was observed licking her genitals. No whistling was observed."),
  list(date = ymd("2024-10-09"), tag = "repro" , subject = list("warble")           , note = "gave birth to twins"),
  list(date = ymd("2024-10-10"), tag = "repro" , subject = list("warble")           , note = "double infanticide")
)   %>% .[order(map_dbl(., ~ .x$date))]

keeper_notes <- enframe(log, name = NULL) %>%
  unnest_wider(value) %>%
  unnest_longer(subject) %>%
  mutate(keeper_note = str_glue("{tag}", ": ", "{note}"), .keep = "unused") %>%
  ungroup() %>%
  reframe(keeper_note = str_flatten(keeper_note, collapse = "; "), .by = c(date, subject))
diet_trials <- list(
  list(begin = ymd(path$day1   ), diet = "Baseline"),
  list(begin = ymd("2023-11-23"), diet = "Oatmeal Gel"), 
  list(begin = ymd("2023-12-14"), diet = "Baseline"),
  list(begin = ymd("2024-01-25"), diet = "Oatmeal Gel"),
  list(begin = ymd("2024-05-29"), diet = "Baseline"), 
  list(begin = ymd("2024-06-15"), diet = "Biscuit elimination"),
  list(begin = ymd("2024-06-29"), diet = "Less bugs, more egg"),
  list(begin = ymd("2024-07-13"), diet = "Sweet potato, green beans, carrots, pumpkin"), 
  list(begin = ymd("2024-07-27"), diet = "Baseline"),  
  list(begin = ymd("2024-08-10"), diet = "Oatmeal Gel"), 
  list(begin = ymd("2024-08-24"), diet = "Baseline"), 
  list(begin = ymd("2024-09-21"), diet = "Low lectin"), 
  list(begin = ymd("2024-10-19"), diet = "Baseline")
) %>% .[order(map_dbl(., ~ .x$begin))] 

warble_trials <- list(
  list(begin = ymd(path$day1   ), diet = "Baseline")
) %>% enframe(name = NULL) %>% 
  unnest_wider(value) %>%
  mutate(diet_name = diet, .keep = "unused") %>%
  mutate(end = today(), subject = "warble")

supplement_details <- list(
  fiber         = list(rx = "Metamucil"    , units = "capsules per day", route = "in gum or on biscuits", dose = list(low = 0.5, high = 1.0)),
  probiotic     = list(rx = "OTC"          , units = "drops per day"   , route = "in gum or on biscuits", dose = list(low = 5.0, high = 10.0)),
  steroid       = list(rx = "Budesonide"   , units = "mg per day"      , route = "in gum or on biscuits", dose = list(low = 0.1, high = 0.2)),
  antibiotic    = list(rx = "Metronidazole", units = "mg per day"      , route = "in gum or on biscuits", dose = 12.5 ),
  antidiarrheal = list(rx = "Loperamide"   , units = "mg per day"      , route = "in gum or on biscuits", dose = 0.08)
)

supplements <- list(
  list(begin = ymd(path$day1   ),  probiotic = 00.0, steroid = 00.0, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
  list(begin = ymd("2023-11-02"),  probiotic = 05.0, steroid = 00.0, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
  list(begin = ymd("2023-11-07"),  probiotic = 10.0, steroid = 00.0, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
  list(begin = ymd("2023-12-14"),  probiotic = 00.0, steroid = 00.1, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
  list(begin = ymd("2024-01-04"),  probiotic = 00.0, steroid = 00.2, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
  list(begin = ymd("2024-01-25"),  probiotic = 10.0, steroid = 00.2, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
  list(begin = ymd("2024-02-20"),  probiotic = 00.0, steroid = 00.2, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
  list(begin = ymd("2024-02-23"),  probiotic = 10.0, steroid = 00.2, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
  list(begin = ymd("2024-04-29"),  probiotic = 10.0, steroid = 00.2, fiber = 00.0, antibiotic = 12.5, antidiarrheal = 00.00),
  list(begin = ymd("2024-05-06"),  probiotic = 10.0, steroid = 00.2, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
  list(begin = ymd("2024-05-29"),  probiotic = 00.0, steroid = 00.0, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
  list(begin = ymd("2024-07-27"),  probiotic = 00.0, steroid = 00.0, fiber = 00.5, antibiotic = 00.0, antidiarrheal = 00.00),
  list(begin = ymd("2024-08-01"),  probiotic = 00.0, steroid = 00.0, fiber = 01.0, antibiotic = 00.0, antidiarrheal = 00.00),
  list(begin = ymd("2024-08-10"),  probiotic = 00.0, steroid = 00.0, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
  list(begin = ymd("2024-08-24"),  probiotic = 05.0, steroid = 00.0, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
  list(begin = ymd("2024-08-29"),  probiotic = 10.0, steroid = 00.0, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
  list(begin = ymd("2024-09-07"),  probiotic = 00.0, steroid = 00.2, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.08),
  list(begin = ymd("2024-09-21"),  probiotic = 00.0, steroid = 00.0, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
  list(begin = ymd("2024-10-19"),  probiotic = 00.0, steroid = 00.2, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
  list(begin = ymd("2024-11-16"),  probiotic = 00.0, steroid = 00.1, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00),
  list(begin = ymd("2024-12-28"),  probiotic = 00.0, steroid = 00.0, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00)
)

warble_supplements <- list(
  list(begin = ymd(path$day1   ),  probiotic = 00.0, steroid = 00.0, fiber = 00.0, antibiotic = 00.0, antidiarrheal = 00.00)
) %>% enframe(name = NULL) %>% 
  unnest_wider(value) %>%
  mutate(end = today(), subject = "warble")


new_holding_start <- list(
  culi   = ymd("2024-02-28"),
  warble = ymd("2024-02-29")
)

pair_access <- list(
  list(begin = ymd(path$day1)   , end = ymd("2023-10-29")),
  list(begin = ymd("2024-04-02"), end = ymd("2024-04-15"))
)

access_dates <- enframe(pair_access, name = NULL) %>%
  unnest_wider(value) %>%
  mutate(pair_access = "y") %>%
  mutate(date = map2(begin, end, seq, by = "day")) %>%  
  unnest(date) %>%
  select(-c(begin, end))

cycles <- list(
  estrus = list(
    list(begin = ymd(path$day1)   , end = ymd("2023-10-29")),
    list(begin = ymd("2024-03-21"), end = ymd("2024-04-06"))
  ),
  pregnant = list(
    list(begin = ymd("2024-04-07"), end = ymd("2024-10-09"))
  )
) 

cycle_dates <- enframe(cycles, name = "warb_status") %>%
  unnest_longer(value) %>%
  unnest_wider(value) %>%
  mutate(date = map2(begin, end, seq, by = "day")) %>%  
  unnest(date) %>%
  select(-c(begin, end))

log <- list(
  
  list(date = ymd("2024-01-22"), tag = "food" , subject = list("culi") , note = "removing cauliflower and broccoli from diet rotation"),
  list(date = ymd("2024-02-20"), tag = "food" , subject = list("culi") , note = "removing tomato from diet rotation"),
  list(date = ymd("2024-03-21"), tag = "repro" , subject = list("culi")             , note = "Culi whistling and actively attempting to get to Warble"),
  list(date = ymd("2024-04-04"), tag = "repro" , subject = list("culi", "warble"), note = "Observed several breeding events"),
  list(date = ymd("2023-11-16"), tag = "health", subject = list("culi")             , note = "had what appeared to be dried blood around his anus and tail"),
  list(date = ymd("2023-12-17"), tag = "health", subject = list("culi")             , note = "coprophagy observed"),
  list(date = ymd("2024-01-21"), tag = "health", subject = list("culi")             , note = "coprophagy observed"),
  list(date = ymd("2024-02-10"), tag = "health", subject = list("culi")             , note = "left biscuit and some gum"),
  list(date = ymd("2024-04-01"), tag = "repro" , subject = list("warble")           , note = "swollen vulva"),
  list(date = ymd("2024-04-02"), tag = "repro" , subject = list("culi")             , note = "swollen testicles"),
  list(date = ymd("2024-04-03"), tag = "repro" , subject = list("culi", "warble"), note = "Keeper Zach entered the facility in the morning to clean and found Warble and Culi sleeping together in a hammock in room 3"),
  list(date = ymd("2024-04-03"), tag = "repro" , subject = list("culi", "warble"), note = "Observed breeding event"),
  list(date = ymd("2024-04-04"), tag = "repro" , subject = list("warble")           , note = "Observed whistling"),
  list(date = ymd("2024-04-04"), tag = "repro" , subject = list("culi", "warble"), note = "JM and AMR found Warble and Culi sleeping together in a hammock in room 3"),
  list(date = ymd("2024-04-04"), tag = "repro" , subject = list("warble")         , note = "swollen vulva"),
  list(date = ymd("2024-04-06"), tag = "repro" , subject = list("warble")         , note = "pregnancy suspected"),
  list(date = ymd("2024-04-14"), tag = "health", subject = list("culi")             , note = "weight = 451 g"),
  list(date = ymd("2024-05-13"), tag = "health", subject = list("warble")           , note = "weight = 467 g"),
  list(date = ymd("2024-06-17"), tag = "health", subject = list("culi")             , note = "left pieces of food in room 5"),
  list(date = ymd("2024-08-08"), tag = "health", subject = list("culi")             , note = "extremely liquid feces"),
  list(date = ymd("2024-09-08"), tag = "health", subject = list("culi")             , note = "extremely liquid feces"),
  list(date = ymd("2025-01-23"), tag = "repro" , subject = list("culi", "warble"), note = "Social grooming observed between the barriers. Culi initiated grooming by licking Warble’s head; she licked his arm, and he was observed licking her genitals. No whistling was observed."),
  list(date = ymd("2024-10-09"), tag = "repro" , subject = list("warble")           , note = "gave birth to twins"),
  list(date = ymd("2024-10-10"), tag = "repro" , subject = list("warble")           , note = "double infanticide")
)   %>% .[order(map_dbl(., ~ .x$date))]

keeper_notes <- enframe(log, name = NULL) %>%
  unnest_wider(value) %>%
  unnest_longer(subject) %>%
  mutate(keeper_note = str_glue("{tag}", ": ", "{note}"), .keep = "unused") %>%
  ungroup() %>%
  reframe(keeper_note = str_flatten(keeper_note, collapse = "; "), .by = c(date, subject))
nutrition_factors <- list(
  foods    = c("biscuit", "HDZ_oatmeal_gel", "invertebrates",  "protein_rotate", "gum_arabic", "seasonal_veggies"),
  classes  = c("proteins", "fats", "CHOs", "Ash", "vitamins", "total"),
  proteins = c("methionine", "taurine", "total", "proteins_total"),
  fats     = c("omega3", "omega6", "total", "fats_total"),
  CHOs     = c("ADF", "NDF", "TDF", "WSC", "crude_fiber", "starch", "total", "CHOs_total"),
  Ash      = c("calcium", "magnesium", "phosphorus", "potassium", "copper", "iodine", "iron", "manganese", "zinc", "total", "Ash_total"),
  vitamins = c("beta_carotene", "lycopene", "choline", "folic_acid", "vit_B1_thiamin", "vit_B2_riboflavin", "vit_B3_niacin", "vit_B5_pantothenic_acid", "vit_B6_pyridoxine","vit_B7_biotin", "vit_B12", "vit_C", "vit_A", "vit_D3", "vit_E", "vit_K", "total", "vitamins_total"),
  all      = c("methionine", "taurine", "omega3", "omega6", "ADF", "NDF", "TDF", "WSC", "crude_fiber", "starch", "calcium", "magnesium", "phosphorus", "potassium", "copper", "iodine", "iron", "manganese", "zinc","beta_carotene", "lycopene", "choline", "folic_acid", "vit_B1_thiamin", "vit_B2_riboflavin", "vit_B3_niacin", "vit_B5_pantothenic_acid", "vit_B6_pyridoxine","vit_B7_biotin", "vit_B12", "vit_C", "vit_A", "vit_D3", "vit_E", "vit_K", "total")
)

holding_factors <- c(
  "old",
  "new"
)

diet_factors <- c(
  "baseline",
  "oatmeal_gel",
  "biscuit_elimination",
  "less_Bugs_more_Egg",
  "sweet_potato_green_beans_carrots_pumpkin",
  "low_lectin",
  "gum36_veg37_invert27",
  "water31_root31_protein19_gum19"
)

rename_classes <- c(
 "Proteins"         = "proteins", 
 "Fats"             = "fats", 
 "Carbohydrates"    = "CHOs", 
 "Mineral Content"  = "Ash", 
 "Vitamins"         = "vitamins", 
 "Total Diet"       = "total"
)

dose_cols <- c(
  "probiotic",
  "fiber",
  "steroid",
  "antibiotic",
  "antidiarrheal"
)


warb_cycle_factors <- c(
  "anestrus",
  "estrus",
  "pregnant"
)

default_factors <- c(
  "day",
  "subject",
  "ExtractKit",
  "ExtractedBy",
  "LibPrepKit",
  "FlowCellType",
  "SeqDevice"
)

steps_remaining_colors <- c(
  "#D2981AFF" = "sample not extracted"          ,
  "#A53E1FFF" = "extract not sequenced"         ,
  "#457277FF" = "sample extracted and sequenced"
)

steps_remaining_icons <- c(
 "poop" = "sample not extracted"           ,
 "vial" = "extract not sequenced"          ,
 "dna"  = "sample extracted and sequenced" 
)

steps_remaining_factors <- c(
  "sample not extracted"           ,
  "extract not sequenced"          ,
  "sample extracted and sequenced" 
)


diet_colors <- c(
   "#8C8C8CFF" =  "Baseline"                                              ,
   "#88BDE6FF" =  "Biscuit elimination"                                   ,
   "#FBB258FF" =  "Less bugs, more egg"                                   ,
   "#90CD97FF" =  "Sweet potato, green beans, carrots, pumpkin"           ,
   "#BFA554FF" =  "36% gum, 37% veg, 27% insects"                         ,
   "#BC99C7FF" =  "31% watery veg, 31% root veg, 19% insects/egg, 19% gum",
   "#EDDD46FF" =  "Low lectin"                                            ,
   "#F07E6EFF" =  "Oatmeal Gel"  
)

warb_status_colors <- c(
  "#A8A6A7FF" = "anestrus",
  "#B1283AFF" = "estrus",
  "#006A8EFF" = "pregnant"
)

holding_colors <- c(
  "#5773CCFF" = "old",
  "#FFB900FF" = "new"
)

certainty_colors <- c(
  "#CA562CFF" = "no",
  "#B5B991FF" = "yes"
)
certainty_icons <- c(
  "x"     = "no",
  "check" = "yes"
)

pair_access_colors <- c(
  "#E1C473FF" = "n",
  "#2C5724FF" = "y"
)
pair_access_icons <- c(
  "square-minus"     = "no",
  "square-check"     = "yes"
)

subj_colors <- c(
  "#803777FF" = "warble",
  "#216F63FF" = "culi"
)
subj_icons <- c(
  "female"     = "warble",
  "male"       = "culi"
)


alarm_colors        <- c("#CEFF1AFF", "#D8E01BFF", "#DFC11BFF", "#E2A11BFF", "#E37F1BFF", "#E1581AFF", "#DE1A1AFF")
concentration_scale <- c("#FF3200FF", "#E9A17CFF", "#E9E4A6FF", "#1BB6AFFF", "#0076BBFF", "#172869FF")
intake_scale        <- c("#1D457FFF", "#61599DFF", "#C36377FF", "#EB7F54FF", "#F2AF4AFF")

supplement_color <- c("#985A71FF")

rename_diets <- c(
  "Baseline"                         = "baseline",
  "Oatmeal Gel"                          = "oatmeal_gel",
  "Biscuit Elimination"              = "biscuit_elimination",
  "Less Bugg/More Egg"               = "less_Bugs_more_Egg",
  "Seasonal Veggies"                 = "sweet_potato_green_beans_carrots_pumpkin",
  "Low Lectin"                       = "low_lectin",
  "Gum:Veggies:Invertebrates Ratio"  = "gum36_veg37_invert27",
  "Watery:Root:Protein:Gum Ratio"    = "water31_root31_protein19_gum19"
)

rename_foods <- c(
 "Biscuit"                      = "biscuit", 
 "Oatmeal Gel"                      = "HDZ_oatmeal_gel", 
 "Invertebrates"                = "invertebrates",  
 "Protein Rotation"             = "protein_rotate", 
 "Egg (whole, cooked)"          = "egg_whole_cooked"       ,
 "Egg (whole, raw)"             = "egg_whole_raw"          ,
 "Egg Whites (cooked)"          = "egg_white_cooked"       ,
 "Gum Arabic"                   = "gum_arabic", 
 "Canned Pumpkin"               = "canned_pumpkin"         ,
 "Carrot"                       = "carrot"                 ,
 "Green Beans (fresh)"          = "green_bean_fresh"       ,
 "Seasonal Veggies (Standard)"  = "seasonal_veggies",
 "Seasonal Veggies (Root)"      = "seasonal_veggies_root"  ,
 "Sweet Potato (raw)"           = "sweet_potato_raw"       ,
 "Sweet Potato (cooked)"        = "sweet_potato_cooked"    ,
 "Seasonal Veggies (Watery)"    = "seasonal_veggies_watery",
 "Lettuce (romaine)"            = "lettuce_romaine"        ,
 "Celery"                       = "celery"                 
)

   


rename_nutrients <- c(
 "Methionine"                   = "methionine", 
 "Taurine"                      = "taurine", 
 "Omega-3"                      = "omega3", 
 "Omega-6"                      = "omega6", 
 "Acid Detergent Fiber"         = "ADF", 
 "Neutral Detergent Fiber"      = "NDF", 
 "Total Dietary Fiber"          = "TDF", 
 "Water-Soluble Carbohydrates"  = "WSC", 
 "Crude Fiber"                  = "crude_fiber", 
 "Starch"                       = "starch", 
 "Calcium (Ca)"                 = "calcium", 
 "Magnesium (Mg)"               = "magnesium", 
 "Phosphorus (P)"               = "phosphorus", 
 "Potassium (K)"                = "potassium",
 "Copper (Cu)"                  = "copper", 
 "Iodine (I)"                   = "iodine", 
 "Iron (Fe)"                    = "iron", 
 "Manganese (Mn)"               = "manganese", 
 "Zinc (Zn)"                    = "zinc",
 "Beta-Carotene"                = "beta_carotene", 
 "Lycopene"                     = "lycopene", 
 "Choline"                      = "choline", 
 "Folic Acid (Vitamin B9)"      = "folic_acid",
 "Vitamin B1 (Thiamin)"         = "vit_B1_thiamin", 
 "Vitamin B2 (Riboflavin)"      = "vit_B2_riboflavin", 
 "Vitamin B3 (Niacin)"          = "vit_B3_niacin", 
 "Vitamin B5 (Pantothenic Acid)"= "vit_B5_pantothenic_acid", 
 "Vitamin B6 (Pyridoxine)"      = "vit_B6_pyridoxine",
 "Vitamin B7 (Biotin)"          = "vit_B7_biotin", 
 "Vitamin B12 (Cobalamin)"      = "vit_B12", 
 "Vitamin C (Ascorbic Acid)"    = "vit_C", 
 "Vitamin A"                    = "vit_A", 
 "Vitamin D3 (Cholecalciferol)" = "vit_D3", 
 "Vitamin E"                    = "vit_E", 
 "Vitamin K"                    = "vit_K", 
  "Total"                       = "total"
)

ordered_variables = c(
  "study_day",
  "subject",
  "identifier",
  "steps_remaining",
  "diet_name",
  "total_mg",
  "total_kcal",
  "total_mg_dry",
  "foods",
  "proteins",
  "fats",
  "CHOs",
  "Ash",
  "vitamins",
  "probiotic",
  "fiber",
  "steroid",
  "antibiotic",
  "antidiarrheal",
  "bristol_min",
  "bristol_max",
  "bristol_mean",
  "holding",
  "pair_access",
  "warb_status",
  "keeper_note",
  "Subj_Certainty",
  "Sex",
  "subject_age",
  "StudbookID",
  "MotherID",
  "FatherID",
  "BirthLocation",
  "SampleID",
  "CollectionDate",
  "SampleSet",
  "SampleCollectedBy",
  "SampleNotes",
  "ExtractID",
  "ExtractDate",
  "ExtractConc",
  "ExtractKit",
  "ExtractBox",
  "ExtractedBy",
  "ExtractNotes",
  "SequenceID",
  "LibPrepDate",
  "LibPrepWorkflow",
  "LibraryCode",
  "protocol_group_id",
  "LibPrepKit",
  "LibraryTube",
  "TemplateVolPrep",
  "LibraryBarcode",
  "fragment_type",
  "strands",
  "Length",
  "InputMassStart",
  "Conc_QC2",
  "PoolSamples",
  "SampVolPool",
  "BeadVol",
  "TotalPoolVol",
  "InputMassFinal",
  "SeqRunID",
  "SeqDate",
  "SeqDateTime",
  "FlowCellType",
  "FlowCellSerial",
  "FlongleAdapter",
  "SeqDevice",
  "reads_unclassified"
)


microeco_cols <- c(
  "study_day",
  "subject",
  "identifier",
  "diet_name",
  "total_mg",
  "total_kcal",
  "total_mg_dry",
  "probiotic",
  "fiber",
  "steroid",
  "antibiotic",
  "antidiarrheal",
  "bristol_mean",
  "holding",
  "pair_access",
  "warb_status",
  "keeper_note",
  "Subj_Certainty",
  "Sex",
  "subject_age",
  "SampleID",
  "CollectionDate",
  "SampleNotes",
  "ExtractID",
  "ExtractDate",
  "ExtractConc",
  "ExtractKit",
  "ExtractedBy",
  "ExtractNotes",
  "SequenceID",
  "LibPrepDate",
  "LibraryCode",
  "LibPrepKit",
  "LibraryBarcode",
  "Conc_QC2",
  "SeqDate",
  "FlowCellType",
  "FlowCellSerial",
  "FlongleAdapter",
  "SeqDevice",
  "reads_unclassified",
  "protein_fed",
  "fat_fed",
  "CHO_fed", 
  "mineral_fed"     
)

date.vars <- c(
  "CollectionDate",
  "ExtractDate",
  "LibPrepDate",
  "SeqDate"
)

yn.vars <- c(
  "pair_access",
  "Subj_Certainty"
)

ids <- c(
  "identifier",
  "SampleID",
  "ExtractID",
  "SequenceID",
  "LibraryCode"
)

coverage_table_cols <- c(
  "study_day",
  "Subject",
  "identifier",
  "raw_read_count" = "reads_unclassified",
  "depth",
  "mean_coverage",
  "diet_name",
  "total_mg",
  "total_kcal",
  "total_mg_dry",
  "bristol_mean",
  "protein_fed",
  "fat_fed",
  "CHO_fed", 
  "mineral_fed",
  "probiotic",
  "fiber",
  "steroid",
  "antibiotic",
  "antidiarrheal",
  "holding",
  "pair_access",
  "warb_status",
  "keeper_note",
  "Subj_Certainty",
  "Sex",
  "subject_age",
  "CollectionDate",
  "SampleID",
  "SampleNotes",
  "ExtractID",
  "ExtractDate",
  "ExtractConc",
  "ExtractKit",
  "ExtractedBy",
  "ExtractNotes",
  "SequenceID",
  "LibPrepDate",
  "LibraryCode",
  "LibPrepKit",
  "LibraryBarcode",
  "Conc_QC2",
  "SeqDate",
  "FlowCellType",
  "FlowCellSerial",
  "FlongleAdapter",
  "SeqDevice"
)

depth_table_cols <- c(
  "study_day",
  "subject",
  "identifier",
  "diet_name",
  "bristol_mean",
  "depth",
  "mean_coverage",
  "ExtractConc",
  "ExtractDate",
  "ExtractedBy",
  "ExtractNotes",
  "LibPrepDate",
  "LibraryCode",
  "Conc_QC2",
  "FlowCellType",
  "SeqDevice",
  "ExtractID",
  "ExtractKit",
  "SequenceID",
  "LibPrepKit",
  "LibraryBarcode",
  "SeqDate",
  "FlowCellSerial",
  "FlongleAdapter",
  "CollectionDate",
  "SampleID",
  "SampleNotes",
  "total_mg",
  "protein_fed",
  "fat_fed",
  "CHO_fed", 
  "mineral_fed",
  "vitamins",
  "probiotic",
  "fiber",
  "steroid",
  "antibiotic",
  "antidiarrheal",
  "holding",
  "pair_access",
  "warb_status",
  "keeper_note",
  "Subj_Certainty",
  "Sex",
  "subject_age",
  "diet_color",
  "holding_color",
  "warb_status_color",
  "color_Subj_Certainty",
  "icon_Subj_Certainty",
  "color_pair_access",
  "icon_pair_access",
  "color_subject",
  "icon_subject"
  )

sample_table_cols <- c(
  "study_day",
  "subject",
  "identifier",
  "diet_name",
  "total_mg",
  "total_kcal",
  "total_mg_dry",
  "probiotic",
  "fiber",
  "steroid",
  "antibiotic",
  "antidiarrheal",
  "bristol_mean",
  "holding",
  "pair_access",
  "warb_status",
  "keeper_note",
  "Subj_Certainty",
  "Sex",
  "subject_age",
  "SampleID",
  "CollectionDate",
  "SampleNotes",
  "ExtractID",
  "ExtractDate",
  "ExtractKit",
  "ExtractedBy",
  "ExtractNotes",
  "SequenceID",
  "LibraryCode",
  "LibPrepKit",
  "FlowCellType",
  "FlowCellSerial",
  "FlongleAdapter",
  "SeqDevice",
  "protein_fed",
  "fat_fed",
  "CHO_fed", 
  "mineral_fed"   
)

sample_merge_cols <- c(
  "study_day",
  "subject",
  "subject_day",
  "diet_name",
  "total_mg",
  "total_kcal",
  "total_mg_dry",
  "probiotic",
  "fiber",
  "steroid",
  "antibiotic",
  "antidiarrheal",
  "bristol_mean",
  "holding",
  "pair_access",
  "warb_status",
  "keeper_note",
  "Subj_Certainty",
  "Sex",
  "subject_age",
  "CollectionDate",              
  "protein_fed"                ,
  "fat_fed"                    ,
  "CHO_fed"                    ,
  "mineral_fed"                ,
  "Omega_3"                    ,
  "Omega_6"                    ,
  "Methionine"                 ,
  "Taurine"                    ,
  "Calcium_Ca"                 ,
  "Magnesium_Mg"               ,
  "Phosphorus_P"               ,
  "Potassium_K"                ,
  "Copper_Cu"                  ,
  "Iodine_I"                   ,
  "Iron_Fe"                    ,
  "Manganese_Mn"               ,
  "Zinc_Zn"                    ,
  "Acid_Detergent_Fiber"       ,
  "Neutral_Detergent_Fiber"    ,
  "Total_Dietary_Fiber"        ,
  "Water_Soluble_Carbohydrates",
  "Crude_Fiber"                ,
  "Starch"                     ,
  "Beta_Carotene"              ,
  "Lycopene"                   ,
  "Choline"                    ,
  "Folic_Acid_Vitamin_B9"      ,
  "Vitamin_B1_Thiamin"         ,
  "Vitamin_B2_Riboflavin"      ,
  "Vitamin_B3_Niacin"          ,
  "Vitamin_B5_Pantothenic_Acid",
  "Vitamin_B6_Pyridoxine"      ,
  "Vitamin_B7_Biotin"          ,
  "Vitamin_B12_Cobalamin"      ,
  "Vitamin_C_Ascorbic_Acid"    ,
  "Vitamin_A"                  ,
  "Vitamin_D3_Cholecalciferol" ,
  "Vitamin_E"                  ,
  "Vitamin_K"                  ,
  "Biscuit"                    ,
  "Gum_Arabic"                 ,
  "Invertebrates"              ,
  "Protein_Rotation"           ,
  "Seasonal_Veggie_Rotation"   ,
  "Oat_Gel" 
)

ranked_cols_env <- c(
  "ID"                         ,
  "total_mg"                   ,
  "total_kcal"                 ,
  "total_mg_dry"               ,
  "bristol_mean"               ,
  "probiotic"                  ,
  "steroid"                    ,
  "fiber"                      ,
  "antibiotic"                 ,
  "antidiarrheal"              ,
  "protein_fed"                ,
  "fat_fed"                    ,
  "CHO_fed"                    ,
  "mineral_fed"                ,
  "Omega_3"                    ,
  "Omega_6"                    ,
  "Methionine"                 ,
  "Taurine"                    ,
  "Calcium_Ca"                 ,
  "Magnesium_Mg"               ,
  "Phosphorus_P"               ,
  "Potassium_K"                ,
  "Copper_Cu"                  ,
  "Iodine_I"                   ,
  "Iron_Fe"                    ,
  "Manganese_Mn"               ,
  "Zinc_Zn"                    ,
  "Acid_Detergent_Fiber"       ,
  "Neutral_Detergent_Fiber"    ,
  "Total_Dietary_Fiber"        ,
  "Water_Soluble_Carbohydrates",
  "Crude_Fiber"                ,
  "Starch"                     ,
  "Beta_Carotene"              ,
  "Lycopene"                   ,
  "Choline"                    ,
  "Folic_Acid_Vitamin_B9"      ,
  "Vitamin_B1_Thiamin"         ,
  "Vitamin_B2_Riboflavin"      ,
  "Vitamin_B3_Niacin"          ,
  "Vitamin_B5_Pantothenic_Acid",
  "Vitamin_B6_Pyridoxine"      ,
  "Vitamin_B7_Biotin"          ,
  "Vitamin_B12_Cobalamin"      ,
  "Vitamin_C_Ascorbic_Acid"    ,
  "Vitamin_A"                  ,
  "Vitamin_D3_Cholecalciferol" ,
  "Vitamin_E"                  ,
  "Vitamin_K"                  ,
  "Biscuit"                    ,
  "Gum_Arabic"                 ,
  "Invertebrates"              ,
  "Protein_Rotation"           ,
  "Seasonal_Veggie_Rotation"   ,
  "Oat_Gel" 
)

sample_table_numeric <- c(
  "study_day",
  "total_mg",
  "total_kcal",
  "total_mg_dry",
  "bristol_mean",
  "protein_fed"                ,
  "fat_fed"                    ,
  "CHO_fed"                    ,
  "mineral_fed"                ,
  "Omega_3"                    ,
  "Omega_6"                    ,
  "Methionine"                 ,
  "Taurine"                    ,
  "Calcium_Ca"                 ,
  "Magnesium_Mg"               ,
  "Phosphorus_P"               ,
  "Potassium_K"                ,
  "Copper_Cu"                  ,
  "Iodine_I"                   ,
  "Iron_Fe"                    ,
  "Manganese_Mn"               ,
  "Zinc_Zn"                    ,
  "Acid_Detergent_Fiber"       ,
  "Neutral_Detergent_Fiber"    ,
  "Total_Dietary_Fiber"        ,
  "Water_Soluble_Carbohydrates",
  "Crude_Fiber"                ,
  "Starch"                     ,
  "Beta_Carotene"              ,
  "Lycopene"                   ,
  "Choline"                    ,
  "Folic_Acid_Vitamin_B9"      ,
  "Vitamin_B1_Thiamin"         ,
  "Vitamin_B2_Riboflavin"      ,
  "Vitamin_B3_Niacin"          ,
  "Vitamin_B5_Pantothenic_Acid",
  "Vitamin_B6_Pyridoxine"      ,
  "Vitamin_B7_Biotin"          ,
  "Vitamin_B12_Cobalamin"      ,
  "Vitamin_C_Ascorbic_Acid"    ,
  "Vitamin_A"                  ,
  "Vitamin_D3_Cholecalciferol" ,
  "Vitamin_E"                  ,
  "Vitamin_K"                  ,
  "Biscuit"                    ,
  "Gum_Arabic"                 ,
  "Invertebrates"              ,
  "Protein_Rotation"           ,
  "Seasonal_Veggie_Rotation"   ,
  "Oat_Gel" 
)

dataset_types <- c("tax", "function")
tax_levels    <- c("species", "genus", "family", "order", "class", "phylum")
func_levels   <- c("kegg", "fpt", "njc")
all_levels    <- c("species", "genus", "family", "order", "class", "phylum", "kegg", "fpt", "njc")
datasets      <- c("main", "culi", "warb")

env_vars <- list(
  "Categorical Variables" = c(
    "Sample"     = "ID"         ,         
    "Diet Name"  = "diet_name"  ,         
    "Study Day"  = "study_day"
  ),
  
  "Health Outcomes" = c(
    "Bristol Fecal Score" = "bristol_mean"  
  ),
  
  "Supplements and Medications" = c(
    "Probiotic"        = "probiotic"         ,         
    "Steroid"          = "steroid"           ,         
    "Fiber Supplement" = "fiber"             ,         
    "Antibiotic"       = "antibiotic"        ,         
    "Antidiarrheal"    = "antidiarrheal"              
  ),
  
  "Daily Diet Totals" = c(
    "Total Weight"     = "total_mg"    ,               
    "Total kcal"       = "total_kcal"  ,               
    "Total Dry Weight" = "total_mg_dry"               
  ),
  
  "Diet Composition" = c(
    "Biscuit"                   = "Biscuit", 
    "Oatmeal Gel"                   = "Oat_Gel", 
    "Invertebrates"             = "Invertebrates",  
    "Protein Rotation"          = "Protein_Rotation", 
    "Gum Arabic"                =  "Gum_Arabic", 
    "Seasonal Veggie Rotation"  = "Seasonal_Veggie_Rotation"
  ),
  
  "Nutritional Composition" = c(
    "Total Proteins"          = "protein_fed"     ,           
    "Total Fats"              = "fat_fed"         ,           
    "Total Carbohydrates"     = "CHO_fed"         ,           
    "Total Mineral Content"   = "mineral_fed"                
  ),
  
  "Carbohydrates" = c(
    "Acid Detergent Fiber"         = "Acid_Detergent_Fiber", 
    "Neutral Detergent Fiber"      = "Neutral_Detergent_Fiber", 
    "Total Dietary Fiber"          = "Total_Dietary_Fiber", 
    "Water-Soluble Carbohydrates"  = "Water_Soluble_Carbohydrates", 
    "Crude Fiber"                  = "Crude_Fiber", 
    "Starch"                       = "Starch"
  ),
  
  "Fats" = c(
    "Omega-3"                      = "Omega_3", 
    "Omega-6"                      = "Omega_6"
  ),
  
  "Proteins" = c(
    "Methionine"                   = "Methionine", 
    "Taurine"                      = "Taurine"
  ),
  
  "Mineral Content" = c(
    "Calcium (Ca)"                 = "Calcium_Ca", 
    "Magnesium (Mg)"               = "Magnesium_Mg", 
    "Phosphorus (P)"               = "Phosphorus_P", 
    "Potassium (K)"                = "Potassium_K",
    "Copper (Cu)"                  = "Copper_Cu", 
    "Iodine (I)"                   = "Iodine_I", 
    "Iron (Fe)"                    = "Iron_Fe", 
    "Manganese (Mn)"               = "Manganese_Mn", 
    "Zinc (Zn)"                    = "Zinc_Zn"     
  ),
  
  "Vitamins" = c(
    "Beta-Carotene"                  =  "Beta_Carotene"              ,
    "Lycopene"                       =  "Lycopene"                   ,
    "Choline"                        =  "Choline"                    ,
    "Folic Acid (Vitamin B9)"        =  "Folic_Acid_Vitamin_B9"      ,
    "Vitamin B1 (Thiamin)"           =  "Vitamin_B1_Thiamin"         ,
    "Vitamin B2 (Riboflavin)"        =  "Vitamin_B2_Riboflavin"      ,
    "Vitamin B3 (Niacin)"            =  "Vitamin_B3_Niacin"          ,
    "Vitamin B5 (Pantothenic Acid)"  =  "Vitamin_B5_Pantothenic_Acid",
    "Vitamin B6 (Pyridoxine)"        =  "Vitamin_B6_Pyridoxine"      ,
    "Vitamin B7 (Biotin)"            =  "Vitamin_B7_Biotin"          ,
    "Vitamin B12 (Cobalamin)"        =  "Vitamin_B12_Cobalamin"      ,
    "Vitamin C (Ascorbic Acid)"      =  "Vitamin_C_Ascorbic_Acid"    ,
    "Vitamin A"                      =  "Vitamin_A"                  ,
    "Vitamin D3 (Cholecalciferol)"   =  "Vitamin_D3_Cholecalciferol" ,
    "Vitamin E"                      =  "Vitamin_E"                  ,
    "Vitamin K"                      =  "Vitamin_K"                  
  )
)


meta.vars.ordered <- c(
  "study_day",
  "subject",
  "identifier",
  "steps_remaining",
  "diet_name",                 
  "Total_rel_max"                ,
  "Total_Protein"                ,
  "Total_Fat"                    ,
  "Total_CHO_by_diff"            ,
  "Total_Ash"                    ,
  "probiotic",
  "fiber",
  "steroid",
  "antibiotic",
  "antidiarrheal",
  "bristol",
  "Biscuit_rotation"             ,
  "Invertebrate_misc"            ,
  "Mazuri_enrich_gum_arabic_5b35",
  "Protein_rotation"             ,
  "Seasonal_vegetables"          ,
  "Egg_whole_cooked_meat_prep"   ,
  "Potato_sweet"                 ,
  "Bean_green_fresh"             ,
  "Carrot"                       ,
  "Pumpkin_canned"               ,
  "Egg_whole_raw_meat_prep"      ,
  "Seasonal_vegetables_root"     ,
  "Seasonal_vegetables_non-root" ,
  "Egg_white_only_cooked"        ,
  "Potato_sweet_cooked"          ,
  "Celery"                       ,
  "Lettuce_romaine"              ,
  "Ohdz_oatmeal_gel"             ,
  "Dry_Matter"                   ,
  "KCal"                         ,
  "Taurine"                      ,
  "Methionine"                   ,
  "Omega_3_ALA__EPA__DHA"        ,
  "Omega_6_LA__GLA__AA"          ,
  "Starch"                       ,
  "NDF"                          ,
  "ADF"                          ,
  "Crude_Fiber"                  ,
  "TDF"                          ,
  "Calcium"                      ,
  "Phosphorus"                   ,
  "Potassium"                    ,
  "Magnesium"                    ,
  "Copper"                       ,
  "Iron"                         ,
  "Zinc"                         ,
  "Manganese"                    ,
  "Iodine"                       ,
  "Ca_P"                         ,
  "Vit_A_IU"                     ,
  "Vit_D3"                       ,
  "Vit_E"                        ,
  "Vit_K"                        ,
  "Vit_B1_Thiamin"               ,
  "Vit_B2_Riboflavin"            ,
  "Vit_B3_Niacin"                ,
  "Choline"                      ,
  "Vit_B5_Pantothenic_Acid"      ,
  "Vit_B6_Pyridoxine"            ,
  "Vit_B7_Biotin"                ,
  "Folic_Acid"                   ,
  "Vit_B12"                      ,
  "Vit_C"                        ,
  "Beta_carotene"                ,
  "Lycopene"                     ,
  "holding",
  "pair_access",
  "warb_status",
  "keeper_note",
  "Subj_Certainty",
  "Sex",
  "subject_age",
  "StudbookID",
  "MotherID",
  "FatherID",
  "BirthLocation",
  "SampleID",
  "CollectionDate",
  "SampleSet",
  "SampleCollectedBy",
  "SampleNotes",
  "ExtractID",
  "ExtractDate",
  "ExtractConc",
  "ExtractKit",
  "ExtractBox",
  "ExtractedBy",
  "ExtractNotes",
  "SequenceID",
  "LibPrepDate",
  "LibPrepWorkflow",
  "LibraryCode",
  "protocol_group_id",
  "LibPrepKit",
  "LibraryTube",
  "TemplateVolPrep",
  "LibraryBarcode",
  "fragment_type",
  "strands",
  "Length",
  "InputMassStart",
  "Conc_QC2",
  "PoolSamples",
  "SampVolPool",
  "BeadVol",
  "TotalPoolVol",
  "InputMassFinal",
  "SeqRunID",
  "SeqDate",
  "SeqDateTime",
  "FlowCellType",
  "FlowCellSerial",
  "FlongleAdapter",
  "SeqDevice",
  "reads_unclassified"
)
     

summary_variables <- c(
  "study_day",
  "CollectionDate",
  "Subj_Certainty",
  "subject",
  "identifier",
  "steps_remaining",
  "bristol",
  "probiotic",
  "fiber",
  "steroid",
  "antibiotic",
  "antidiarrheal",
  "diet_name",                 
  "Total_rel_max"                ,
  "Total_Protein"                ,
  "Total_Fat"                    ,
  "Total_CHO_by_diff"            ,
  "Total_Ash"                    ,
  "holding",
  "warb_status",
  "pair_access",
  "keeper_note",
  "Sex",
  "subject_age",
  "StudbookID",
  "SampleID",
  "SampleNotes",
  "ExtractID",
  "ExtractDate",
  "ExtractConc",
  "ExtractKit",
  "ExtractBox",
  "ExtractNotes",
  "SequenceID",
  "LibPrepDate",
  "LibraryCode",
  "LibPrepKit",
  "LibraryBarcode",
  "Conc_QC2",
  "SeqDate",
  "FlowCellType",
  "SeqDevice",
  "reads_unclassified",
  "diet_num"           , 
  "holding_num"        , 
  "warb_status_num"    , 
  "steps_remaining_num" 
)

Script

Organizing Dates

The toughest variables to match and wrange in R are often dates, especially when you are dealing with both states (start and end dates for intervals) and events (single dates). For studies like this one based around daily sample collection, I find it easiest to start by populating a blank dataframe with one row per sample collection day. Then I match date-based variables to this dataframe and join my SampleIDs to it.

Once we combine all the pieces together, we will have a metadata table with one row per day for each subject. Then we can match every sample to subject and day using the same table.

sample.days <- tibble(CollectionDate = seq.Date(
                                from = ymd(path$day1), 
                                to   = today(), 
                                by   = "day")
                      ) %>%
  expand(CollectionDate, subject = list_assign(subject_list, UNKN = "Unknown")) %>%
  mutate(subject = str_to_lower(as.character(subject))) %>%
  group_by(subject) %>%
  mutate(study_day = row_number()) %>% ungroup()

Sample Inventory

First I will read in the sample inventory, which is actually already a metadata table itself. Later we will join this to our daily metadata table to create one large dataframe with all our variable scores matched to a sample.

samples <- read_tsv(path$inventories$all_stages, show_col_types = FALSE) %>%
            filter(!is.na(CollectionDate)) %>%
  mutate(across(any_of(date.vars),   ~ ymd(.)),
         across(any_of(yn.vars),     ~ str_to_lower(as.character(.))),
         across(any_of(ids),         ~ str_to_lower(.)),
         subject = str_to_lower(Subject), .keep = "unused") %>%
            mutate(identifier = case_when(
              !is.na(SequenceID)                    ~ SequenceID,
              is.na(SequenceID) & !is.na(ExtractID) ~ ExtractID,
              is.na(ExtractID)  & !is.na(SampleID)  ~ SampleID,
              .default = SampleID
            )) %>% relocate(identifier) %>%
  left_join(sample.days, by = join_by(CollectionDate, subject)) %>%
  mutate(subject  = fct(subject),
         subj_day = fct(str_glue("{subject}", "_", "{study_day}"))) %>%
  mutate(holding = case_when(
    CollectionDate < new_holding_start$culi   & subject == "culi"   ~ "old",
    CollectionDate < new_holding_start$warble & subject == "warble" ~ "old",
                             .default = "new"))

samples

Ordered Sample Lists for Subsetting

sample.list <- samples %>% 
               distinct(identifier, subject, CollectionDate) %>%
               arrange(subject, CollectionDate) %>%
               distinct(identifier) %>%
                   map(\(x) as.list(x)) %>%
  list_flatten(name_spec = "")

sample.vecs <- sample.list %>% unlist()

samp.list.culi  <- samples %>% 
                   filter(subject == "culi") %>%
                   distinct(identifier, CollectionDate) %>%
                   arrange(CollectionDate) %>%
                   distinct(identifier) %>%
                   map(\(x) as.list(x)) %>%
  list_flatten(name_spec = "")

samples.culi       <- samp.list.culi %>% unlist()

samp.list.warb  <- samples %>% 
                   filter(subject == "warble") %>%
                   distinct(identifier, CollectionDate) %>%
                   arrange(CollectionDate) %>%
                   distinct(identifier) %>%
                   map(\(x) as.list(x)) %>%
  list_flatten(name_spec = "")

samples.warb <- samp.list.warb %>% unlist()

libraries <- samples %>%
  arrange(LibPrepDate) %>%
  select(LibraryCode, identifier) %>%
  group_by(LibraryCode) %>%
  group_map(~ {
    setNames(list(as.list(.x$identifier)), .y$LibraryCode)
  }, .keep = TRUE) %>%
  flatten()

working_libraries <- libraries %>%
  keep_at(paste0(params$seqrun)) %>%
  list_c()

Subset Versions

I am also going to create a sample table version that I can easily add back into my dataset after I merge technical and biological replicates by subject and day.

identifier.key <- samples %>%
  select(subj_day, identifier, SampleID, ExtractID, SequenceID)

write.table(identifier.key, 
            path$metadata$sample_table$identifier, 
            row.names = F, 
            sep       = "\t") 

Construct Variables

Diet

We have only two subjects in this dataset: Culi and Warble. Culi underwent a series of diet trials that we organized into start and end dates, while Warble maintained a baseline diet throughout our study.

I organized the schedule of diet trials into a nested list based on the day that each new diet plan began. We can use some reproducible code to turn that into a table where each trial end date is the day before the next trial’s start date, and then expand longer so that we have one row of data for each day of a diet trial. Later we will match those days to a schedule of sample collection so that each sample is matched to this list of dietary context.

Note that the script I am drawing from for this table also nested more detailed tables into individual columns. This is a way to organize our multi-level nutritional data into a single source that is easier to manipulate and restructure, depending on the scale or variables we want to include. So each row will represent one day, and each column represents a value for one of our variables. The nested columns contain a single table linking that day to that dataset, and additional rows organized by other variables.

nutrients <- read_csv("metadata/loris/nutrients_bydiet.csv", show_col_types = FALSE) %>%
  rename_with(~str_replace_all(., "\\s", "_")) %>%
  rename_with(~str_replace_all(., "\\.{3}", "col")) %>%
  select(diet_name = Diet,
         class     = Nutrient_Class,
         item      = Nutrient,
         fed       = col4,
         units     = col5) %>%
  filter(!is.na(fed)) %>%
  mutate(item = case_when(str_detect(units, "DM") ~ "Dry Matter", 
                          str_detect(units, "kcal") ~"KCal",
                          .default = item)) %>%
  mutate(units = case_when(
    units == "g" | units == "g as fed" | units == "g DM" ~ "mg", 
    str_detect(item, ":")  ~ "ratio",
    .default = units)
    ) %>%
  mutate(fed   = if_else(units %in% c("g", "g as fed", "g DM"), fed*1000, fed)) %>%
  group_by(class, item) %>%
  mutate(relative    = fed/max(fed),
         relative_to = "item_max") %>% ungroup()
nutrition <- read_csv("metadata/loris/foods_bydiet.csv", show_col_types = FALSE) %>%
  rename_with(~str_replace_all(., "\\s", "_")) %>%
  rename_with(~str_remove_all(., "\\(|\\)")) %>%
  mutate(item  = str_to_sentence(Feeds),
         fed   = Fed_g * 1000,
         class = "Foods",
         units = "mg") %>%
  select(diet_name = Diet,
         class,
         item,
         fed,
         units) %>%
  group_by(diet_name) %>%
  mutate(total_diet = sum(fed)) %>%
  ungroup() %>% rowwise() %>%
  mutate(relative    = fed/total_diet,
         relative_to = "diet_total") %>% ungroup() %>%
  select(-total_diet) %>%
  bind_rows(nutrients)

write.table(nutrition, 
            "metadata/loris/nutrition.tsv", 
            sep       = "\t", 
            row.names = FALSE)
nutrition_wide <- nutrition %>%
  select(diet_name, class, item, relative) %>%
  mutate(
    across(c(class, item), ~ as.character(str_replace_all(., "\\s|:", "_"))),
    across(c(class, item), ~ str_remove_all(., "[(),+]"))) %>%
  mutate(item = str_to_lower(item)) %>%
  pivot_wider(names_from  = c("class", "item"),
              names_sep   = "_",
              values_from = "relative",
              values_fill = 0) %>%
  relocate(
    ends_with("_total"),
    starts_with("Total_"), .after = "diet_name") %>%
  mutate(diet_name = str_replace_all(
    str_to_lower(diet_name), "%\\s|,\\s|\\s|/", "_")) %>%
  relocate(diet_name)
diet <- enframe(diet_trials, name = NULL) %>%
  unnest_wider(value) %>%
  rename(diet_name = diet) %>%
  mutate(subject   = "culi", diet_name = str_to_lower(diet_name)) %>%
  mutate(end = if_else(begin < max(begin), lead(begin) - days(1), today())) %>%
  bind_rows(warble_trials) %>%
  mutate(date = map2(begin, end, seq, by = "day")) %>%  
  unnest(date) %>%
  select(-c(begin, end)) %>%
  relocate(date) %>% distinct() %>%
  left_join(nutrition_wide, by = join_by(diet_name))

diet

Now we will do the same for the list that I created for each medication or supplement administered. Because these all have different dosage units and relative effects, I will adjust the dose units to represent the proportion of the max dosage administered. This makes the data easier to interpret and relate.

Finally, I will join the data on nutrition content, diet schedules, and medications/supplements into a single table with one row for each day.

diet_supplements <- enframe(supplements, name = NULL) %>%
  unnest_wider(value) %>%
  mutate(end = if_else(
    begin < max(begin), 
    lead(begin) - days(1), today()),
    subject = "culi") %>%
  bind_rows(warble_supplements) %>%
  pivot_longer(cols      = c(probiotic:antidiarrheal),
               names_to  = "supplement",
               values_to = "dose") %>%
  select(begin, end, subject, supplement, dose) %>%
  group_by(supplement) %>%
  mutate(dose = dose/max(dose)) %>% ungroup() %>%
  pivot_wider(id_cols     = c("begin", "end", "subject"),
              names_from  = "supplement",
              values_from = "dose") %>%
  mutate(date = map2(begin, end, seq, by = "day")) %>%  
  unnest(date) %>%
  select(-c(begin, end)) %>%
  relocate(date) %>%
  right_join(diet, by = join_by(subject, date)) %>% distinct()


diet_supplements

Subject Info

Now I will read in some useful info about each subject from their AZA studbook.

studbook.info <- read_csv(path$metadata$studbook, show_col_types = FALSE) %>%
  rename_with(~str_replace_all(., "\\s", "_")) %>%
  mutate(
          subject       = factor(str_to_lower(Name), levels = unique(str_to_lower(Name))),
          StudbookID    = factor(ID, levels = unique(ID)),
          Sex           = factor(Sex, levels = unique(Sex)),
          MotherID      = factor(Mother, levels = unique(Mother)),
          FatherID      = factor(Father, levels = unique(Father)),
          BirthLocation = factor(Birth_Location, levels = unique(Birth_Location)),
          BirthYear     = year(make_date(year = Born))
          ) %>%
  select(
    subject,
    StudbookID,
    Sex,
    MotherID,
    FatherID,
    BirthYear,
    BirthLocation
  )

Bristol Scores

bristols <- read_tsv(path$metadata$bristol) %>%
  mutate(date = ymd(date))
bristols

Complete Metadata Table

metadata <- samples %>%
  left_join(studbook.info, by = join_by(subject)) %>%
  mutate(subject_age = year(CollectionDate) - BirthYear) %>% 
  select(-BirthYear) %>%
  left_join(bristols    , by = join_by(subject, CollectionDate == date)) %>%
  left_join(keeper_notes, by = join_by(subject, CollectionDate == date)) %>%
  left_join(cycle_dates , by = join_by(CollectionDate == date)) %>%
  left_join(access_dates, by = join_by(CollectionDate == date)) %>%
  mutate(warb_status = replace_na(warb_status, "anestrus"),
         pair_access = replace_na(pair_access, "n")) %>%
  left_join(diet_supplements, by = join_by(subject, CollectionDate == date)) %>% 
  distinct() %>%
  arrange(study_day) %>%
  group_by(subject) %>%
  fill(bristol_mean) %>%
  ungroup() %>%
  mutate(SampleSet = params$sampleset, bristol = bristol_mean) %>%
  arrange(study_day, subject, identifier) %>%
    select(
    identifier                              ,
    steps_remaining                         ,
    sample_id   = SampleID                  ,
    extract_id  = ExtractID                 ,
    sequence_id = SequenceID                ,
    subject                                 ,
    subject_certainty      = Subj_Certainty ,
    subject_studbook_id    = StudbookID     ,
    subject_sex            = Sex            ,
    subject_dam_id         = MotherID       ,
    subject_sire_id        = FatherID       ,
    subject_birth_location = BirthLocation  ,
    subject_age                             ,
    subject_day            = subj_day       ,
    collection_day         = study_day      ,
    collection_date        = CollectionDate ,
    environment_holding    = holding        ,
    bristol_min                             ,
    bristol_mean                            ,
    bristol_max                             ,
    repro_warb_status        = warb_status  ,
    environment_pair_access  = pair_access  ,
    supplement_probiotic     = probiotic    ,
    supplement_steroid       = steroid      ,
    supplement_fiber         = fiber        ,
    supplement_antibiotic    = antibiotic   ,
    supplement_antidiarrheal = antidiarrheal,
    diet_name                               ,
    diet_Total_total                         = Total_total                         ,
    diet_Protein_total                       = Protein_total                       ,
    diet_Fat_total                           = Fat_total                           ,
    diet_CHO_by_diff_total                   = CHO_by_diff_total                   ,
    diet_Ash_total                           = Ash_total                           ,
    diet_Total_dry_matter                    = Total_dry_matter                    ,
    diet_Total_kcal                          = Total_kcal                          ,
    diet_Foods_biscuit_rotation              = Foods_biscuit_rotation              ,
    diet_Foods_invertebrate_misc             = Foods_invertebrate_misc             ,
    diet_Foods_mazuri_enrich_gum_arabic_5b35 = Foods_mazuri_enrich_gum_arabic_5b35 ,
    diet_Foods_protein_rotation              = Foods_protein_rotation              ,
    diet_Foods_seasonal_vegetables           = Foods_seasonal_vegetables           ,
    diet_Foods_egg_whole_cooked_meat_prep    = Foods_egg_whole_cooked_meat_prep    ,
    diet_Foods_potato_sweet                  = Foods_potato_sweet                  ,
    diet_Foods_bean_green_fresh              = Foods_bean_green_fresh              ,
    diet_Foods_carrot                        = Foods_carrot                        ,
    diet_Foods_pumpkin_canned                = Foods_pumpkin_canned                ,
    diet_Foods_egg_whole_raw_meat_prep       = Foods_egg_whole_raw_meat_prep       ,
    diet_Foods_seasonal_vegetables_root      = Foods_seasonal_vegetables_root      ,
    diet_Foods_seasonal_vegetables_non_root  = "Foods_seasonal_vegetables_non-root", 
    diet_Foods_egg_white_only_cooked         = Foods_egg_white_only_cooked         ,
    diet_Foods_potato_sweet_cooked           = Foods_potato_sweet_cooked           ,
    diet_Foods_celery                        = Foods_celery                        ,
    diet_Foods_lettuce_romaine               = Foods_lettuce_romaine               ,
    diet_Foods_ohdz_oatmeal_gel              = Foods_ohdz_oatmeal_gel              ,
    diet_Protein_taurine                     = Protein_taurine                     ,
    diet_Protein_methionine                  = Protein_methionine                  ,
    diet_Fat_omega_3_ala__epa__dha           = Fat_omega_3_ala__epa__dha           ,
    diet_Fat_omega_6_la__gla__aa             = Fat_omega_6_la__gla__aa             ,
    diet_CHO_by_diff_starch                  = CHO_by_diff_starch                  ,
    diet_CHO_by_diff_ndf                     = CHO_by_diff_ndf                     ,
    diet_CHO_by_diff_adf                     = CHO_by_diff_adf                     ,
    diet_CHO_by_diff_crude_fiber             = CHO_by_diff_crude_fiber             ,
    diet_CHO_by_diff_tdf                     = CHO_by_diff_tdf                     ,
    diet_Ash_calcium                         = Ash_calcium                         ,
    diet_Ash_phosphorus                      = Ash_phosphorus                      ,
    diet_Ash_potassium                       = Ash_potassium                       ,
    diet_Ash_magnesium                       = Ash_magnesium                       ,
    diet_Ash_copper                          = Ash_copper                          ,
    diet_Ash_iron                            = Ash_iron                            ,
    diet_Ash_zinc                            = Ash_zinc                            ,
    diet_Ash_manganese                       = Ash_manganese                       ,
    diet_Ash_iodine                          = Ash_iodine                          ,
    diet_Ash_ca_p                            = Ash_ca_p                            ,
    diet_Vitamins_vit_a_iu                   = Vitamins_vit_a_iu                   ,
    diet_Vitamins_vit_d3                     = Vitamins_vit_d3                     ,
    diet_Vitamins_vit_e                      = Vitamins_vit_e                      ,
    diet_Vitamins_vit_k                      = Vitamins_vit_k                      ,
    diet_Vitamins_vit_b1_thiamin             = Vitamins_vit_b1_thiamin             ,
    diet_Vitamins_vit_b2_riboflavin          = Vitamins_vit_b2_riboflavin          ,
    diet_Vitamins_vit_b3_niacin              = Vitamins_vit_b3_niacin              ,
    diet_Vitamins_choline                    = Vitamins_choline                    ,
    diet_Vitamins_vit_b5_pantothenic_acid    = Vitamins_vit_b5_pantothenic_acid    ,
    diet_Vitamins_vit_b6_pyridoxine          = Vitamins_vit_b6_pyridoxine          ,
    diet_Vitamins_vit_b7_biotin              = Vitamins_vit_b7_biotin              ,
    diet_Vitamins_folic_acid                 = Vitamins_folic_acid                 ,
    diet_Vitamins_vit_b12                    = Vitamins_vit_b12                    ,
    diet_Vitamins_vit_c                      = Vitamins_vit_c                      ,
    diet_Vitamins_beta_carotene              = Vitamins_beta_carotene              ,
    diet_Vitamins_lycopene                   = Vitamins_lycopene                   ,
    extract_date                             = ExtractDate                         ,
    extract_by                               = ExtractedBy                         ,
    extract_kit                              = ExtractKit                          ,
    extract_qc_conc                          = ExtractConc                         ,
    library_id                               = LibraryCode                         ,
    library_tube                             = LibraryTube                         ,
    library_barcode                          = LibraryBarcode                      ,
    library_qc2_conc                         = Conc_QC2                            ,
    library_workflow                         = LibPrepWorkflow                     ,
    library_kit                              = LibPrepKit                          ,
    seq_run_id                               = SeqRunID                            ,
    seq_run_date                             = SeqDate                             ,
    seq_run_flow_cell                        = FlowCellType          
    ) %>%
  mutate(across(where(is.factor), ~as.character(.))) %>%
  mutate(across(where(is.character), ~str_to_lower(.)))

write.table(metadata, path$metadata$summary , row.names = F, sep = "\t")


metadata

Next Steps

Now you should proceed to a Bioinformatics or Statistical Workflow to Begin Merging Metadata with Results for Analysis.