diff --git a/omics/kelly/Octanoic VFA_inverse model example.xlsx b/omics/kelly/Octanoic VFA_inverse model example.xlsx new file mode 100644 index 0000000..d87ce04 Binary files /dev/null and b/omics/kelly/Octanoic VFA_inverse model example.xlsx differ diff --git a/omics/kelly/data-raw/ph.csv b/omics/kelly/data-raw/ph.csv new file mode 100644 index 0000000..7c584c3 --- /dev/null +++ b/omics/kelly/data-raw/ph.csv @@ -0,0 +1,130 @@ +Feedstock,Replicate,Time (hours),pH +N/A,1,-1,7.72 +N/A,2,-1,7.73 +N/A,3,-1,7.71 +N/A,4,-1,7.73 +Casein,1,0,7.70 +Casein,2,0,7.71 +Casein,3,0,7.64 +Casein,4,0,7.67 +Casein,1,3,7.87 +Casein,2,3,7.74 +Casein,3,3,7.86 +Casein,4,3,7.97 +Casein,1,6,7.71 +Casein,2,6,7.74 +Casein,3,6,7.75 +Casein,4,6,7.69 +Casein,1,24,7.95 +Casein,2,24,7.93 +Casein,3,24,7.94 +Casein,4,24,7.89 +Casein,1,48,8.02 +Casein,2,48,7.93 +Casein,3,48,7.96 +Casein,4,48,7.94 +Casein,1,54,7.96 +Casein,2,54,7.91 +Casein,3,54,7.90 +Casein,4,54,7.93 +Casein,1,72,7.87 +Casein,2,72,7.89 +Casein,3,72,7.89 +Casein,4,72,7.90 +Casein,1,96,7.96 +Casein,2,96,8.01 +Casein,3,96,7.98 +Casein,4,96,7.95 +Casein,1,168,7.92 +Casein,2,168,7.90 +Casein,3,168,7.93 +Casein,4,168,7.93 +Casein,1,192,7.90 +Casein,2,192,7.97 +Casein,3,192,7.98 +Casein,4,192,8.00 +Keratin,1,0,7.57 +Keratin,2,0,7.72 +Keratin,3,0,7.41 +Keratin,4,0,7.56 +Keratin,1,3,n/a +Keratin,2,3,n/a +Keratin,3,3,n/a +Keratin,4,3,n/a +Keratin,1,6,7.64 +Keratin,2,6,7.82 +Keratin,3,6,7.73 +Keratin,4,6,7.7 +Keratin,1,24,8.12 +Keratin,2,24,7.99 +Keratin,3,24,7.77 +Keratin,4,24,7.92 +Keratin,1,48,8.02 +Keratin,2,48,7.93 +Keratin,3,48,8.02 +Keratin,4,48,7.88 +Keratin,1,54,7.86 +Keratin,2,54,7.87 +Keratin,3,54,7.8 +Keratin,4,54,7.82 +Keratin,1,72,7.8 +Keratin,2,72,7.81 +Keratin,3,72,7.82 +Keratin,4,72,7.8 +Keratin,1,96,8.02 +Keratin,2,96,7.97 +Keratin,3,96,8.04 +Keratin,4,96,8.12 +Keratin,1,168,7.87 +Keratin,2,168,7.98 +Keratin,3,168,8.03 +Keratin,4,168,7.96 +Keratin,1,192,7.88 +Keratin,2,192,7.69 +Keratin,3,192,7.78 +Keratin,4,192,7.85 +Acetate,1,0,7.83 +Acetate,2,0,7.85 +Acetate,3,0,7.81 +Acetate,1,3,7.69 +Acetate,2,3,7.67 +Acetate,3,3,7.71 +Acetate,1,6,7.75 +Acetate,2,6,7.74 +Acetate,3,6,7.76 +Acetate,1,24,7.93 +Acetate,2,24,7.95 +Acetate,3,24,7.96 +Acetate,1,48,7.75 +Acetate,2,48,7.77 +Acetate,3,48,7.77 +Hexanoate,1,0,7.85 +Hexanoate,2,0,7.85 +Hexanoate,3,0,7.85 +Hexanoate,1,3,7.75 +Hexanoate,2,3,7.79 +Hexanoate,3,3,7.80 +Hexanoate,1,6,7.71 +Hexanoate,2,6,7.78 +Hexanoate,3,6,7.76 +Hexanoate,1,24,7.92 +Hexanoate,2,24,7.84 +Hexanoate,3,24,7.92 +Hexanoate,1,48,7.92 +Hexanoate,2,48,7.85 +Hexanoate,3,48,7.93 +Decanoate,1,0,7.73 +Decanoate,2,0,7.66 +Decanoate,3,0,7.69 +Decanoate,1,3,7.88 +Decanoate,2,3,7.79 +Decanoate,3,3,7.80 +Decanoate,1,6,7.71 +Decanoate,2,6,7.76 +Decanoate,3,6,7.74 +Decanoate ,1,24,7.71 +Decanoate ,2,24,7.00 +Decanoate,3,24,7.73 +Decanoate,1,48,7.61 +Decanoate,2,48,7.68 +Decanoate ,3,48,7.65 \ No newline at end of file diff --git a/omics/kelly/data-raw/vfa2.csv b/omics/kelly/data-raw/vfa2.csv new file mode 100644 index 0000000..2ed980d --- /dev/null +++ b/omics/kelly/data-raw/vfa2.csv @@ -0,0 +1,171 @@ +Set number,replicate,Treatment,Time day,Acetate,Propanoate,Isobutyrate,Butyrate,Isopentanoate,Pentanoate,Isohexanoate,Hexanoate +2,1,Acetate,1,10.9,0,0,0,0,0,0,0 +2,2,Acetate,1,11.2,0,0,0,0,0,0,0 +2,3,Acetate,1,12.8,0,0,0,0,0,0,0 +2,1,Acetate,2,5.6,0,0,0,0,0,0,0 +2,2,Acetate,2,5.3,0,0,0,0,0,0,0 +2,3,Acetate,2,6.1,0,0,0,0,0,0,0 +2,1,Acetate,3,1.2,0,0,0,0,0,0,0 +2,2,Acetate,3,0.9,0,0,0,0,0,0,0 +2,3,Acetate,3,1.1,0,0,0,0,0,0,0 +2,1,Acetate,4,0.1,0,0,0,0,0,0,0 +2,2,Acetate,4,0,0,0,0,0,0,0,0 +2,3,Acetate,4,0,0,0,0,0,0,0,0 +2,1,Acetate,5,0,0,0,0,0,0,0,0 +2,2,Acetate,5,0,0,0,0,0,0,0,0 +2,3,Acetate,5,0,0,0,0,0,0,0,0 +2,1,Acetate,6,11.8,0,0,0,0,0,0,0 +2,2,Acetate,6,11.2,0,0,0,0,0,0,0 +2,3,Acetate,6,12,0,0,0,0,0,0,0 +2,1,Acetate,7,4.9,0,0,0,0,0,0,0 +2,2,Acetate,7,4.3,0,0,0,0,0,0,0 +2,3,Acetate,7,4.8,0,0,0,0,0,0,0 +2,1,Acetate,8,0.3,0,0,0,0,0,0,0 +2,2,Acetate,8,0.5,0,0,0,0,0,0,0 +2,3,Acetate,8,0.9,0,0,0,0,0,0,0 +2,1,Acetate,9,0,0,0,0,0,0,0,0 +2,2,Acetate,9,0,0,0,0,0,0,0,0 +2,3,Acetate,9,0,0,0,0,0,0,0,0 +2,1,Acetate,10,0,0,0,0,0,0,0,0 +2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,1,Decanoic,1,0,0,0,0,0,0,0,0 +2,2,Decanoic,1,0,0,0,0,0,0,0,0 +2,3,Decanoic,1,0,0,0,0,0,0,0,0 +2,1,Decanoic,2,0,0,0,0,0,0,0,0 +2,2,Decanoic,2,0,0,0,0,0,0,0,0 +2,3,Decanoic,2,0,0,0,0,0,0,0,0 +2,1,Decanoic,3,0.3,0,0,0,0,0,0,0.1 +2,2,Decanoic,3,0.4,0,0,0,0,0,0,0 +2,3,Decanoic,3,0.5,0,0,0,0,0,0,0.2 +2,1,Decanoic,4,3,0,0,0,0,0,0,0.8 +2,2,Decanoic,4,3.2,0,0,0,0,0,0,0.9 +2,3,Decanoic,4,4,0,0,0,0,0,0,1.1 +2,1,Decanoic,5,1.1,0,0,0,0,0,0,0 +2,2,Decanoic,5,1.3,0,0,0,0,0,0,0 +2,3,Decanoic,5,0.8,0,0,0,0,0,0,0 +2,1,Decanoic,6,0,0,0,0,0,0,0,0 +2,2,Decanoic,6,0,0,0,0,0,0,0,0 +2,3,Decanoic,6,0,0,0,0,0,0,0,0 +2,1,Decanoic,7,0,0,0,0,0,0,0,0 +2,2,Decanoic,7,0,0,0,0,0,0,0,0 +2,3,Decanoic,7,0,0,0,0,0,0,0,0 +2,1,Decanoic,8,0.6,0,0,0,0,0,0,0.1 +2,2,Decanoic,8,0.9,0,0,0,0,0,0,0.1 +2,3,Decanoic,8,0.8,0,0,0,0,0,0,0.3 +2,1,Decanoic,9,3.7,0,0,0,0,0,0,1.3 +2,2,Decanoic,9,4.1,0,0,0,0,0,0,1.7 +2,3,Decanoic,9,3.9,0,0,0,0,0,0,1.5 +2,1,Decanoic,10,0.9,0,0,0,0,0,0,0 +2,2,Decanoic,10,0.6,0,0,0,0,0,0,0 +2,3,Decanoic,10,0.4,0,0,0,0,0,0,0 +1,1,Casein,1,0,0,0,0,0,0,0,0 +1,2,Casein,1,0,0,0,0,0,0,0,0 +1,3,Casein,1,0,0,0,0,0,0,0,0 +1,4,Casein,1,0,0,0,0,0,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.1 +1,4,Casein,9,8.1,0.9,1.4,3,0,0,2.2,4.5 +1,1,Casein,10,8.8,0.2,0,1.4,0,0,0.1,3.1 +1,2,Casein,10,8.3,0,0.1,1.2,0,0,0.3,2.6 +1,3,Casein,10,7.8,0.1,0,1.7,0,0,0,2.8 +1,4,Casein,10,8.5,0,0,1.1,0,0,0.1,2.3 +1,1,Keratin,1,0,0,0,0,0,0,0,0 +1,2,Keratin,1,0,0,0,0,0,0,0,0 +1,3,Keratin,1,0,0,0,0,0,0,0,0 +1,4,Keratin,1,0,0,0,0,0,0,0,0 +1,1,Keratin,2,0,0,0,0,0,0,0,0 +1,2,Keratin,2,0,0,0,0,0,0,0,0 +1,3,Keratin,2,0,0,0,0,0,0,0,0 +1,4,Keratin,2,0,0,0,0,0,0,0,0 +1,1,Keratin,3,0,0,0,0,0,0,0,0 +1,2,Keratin,3,0,0,0,0,0,0,0,0 +1,3,Keratin,3,0,0,0,0,0,0,0,0 +1,4,Keratin,3,0,0,0,0,0,0,0,0 +1,1,Keratin,4,0,0,0,0,0,0,0,0 +1,2,Keratin,4,0,0,0,0,0,0,0,0 +1,3,Keratin,4,0,0,0,0,0,0,0,0 +1,4,Keratin,4,0,0,0,0,0,0,0,0 +1,1,Keratin,5,0,0,0,0,0,0,0,0 +1,2,Keratin,5,0,0,0,0,0,0,0,0 +1,3,Keratin,5,0,0,0,0,0,0,0,0 +1,4,Keratin,5,0,0,0,0,0,0,0,0 +1,1,Keratin,6,2.1,0,0,0.3,0,0,0,0.4 +1,2,Keratin,6,2.4,0,0,0.4,0,0,0,0.2 +1,3,Keratin,6,1.7,0,0,0.2,0,0,0,0.5 +1,4,Keratin,6,2.5,0,0,0.1,0,0,0,0.3 +1,1,Keratin,7,5,0,0,3,0,0,0,1.4 +1,2,Keratin,7,5.6,0,0,4.2,0,0,0,1.6 +1,3,Keratin,7,4.7,0,0,4,0,0,0,1.2 +1,4,Keratin,7,5.2,0,0,2,0,0,0,1.5 +1,1,Keratin,8,7.1,5,2.6,0.2,4.4,3.7,1.2,3.1 +1,2,Keratin,8,7.3,4.8,2.2,0.4,4.2,3.5,1.4,3.5 +1,3,Keratin,8,6.9,4.9,2.4,0.3,3.8,3.4,0.7,3.2 +1,4,Keratin,8,7,5.3,2.3,0.1,2.9,4.1,1.1,3.3 +1,1,Keratin,9,9.8,5.3,0.4,0,6,5.2,0.1,3.3 +1,2,Keratin,9,10.1,5.4,0.3,0,6.3,4.9,0.3,3 +1,3,Keratin,9,9.6,5.3,0.3,0,6.2,5.1,0.2,2.9 +1,4,Keratin,9,9.9,5.7,0.2,0,5.9,5,0.1,2.8 +1,1,Keratin,10,10.1,5.2,0,0,5.3,6,0,3.4 +1,2,Keratin,10,9.7,5.3,0,0,5.2,6.1,0,3.6 +1,3,Keratin,10,9.9,3.8,0,0,5.5,7.3,0,3.2 +1,4,Keratin,10,10.3,5.9,0,0,5.6,6.4,0,3.5 \ No newline at end of file diff --git a/omics/kelly/temp/example.R b/omics/kelly/temp/example.R deleted file mode 100644 index 46db641..0000000 --- a/omics/kelly/temp/example.R +++ /dev/null @@ -1,3 +0,0 @@ -library(tidyverse) -example <- read_csv("omics/kelly/temp/example.csv") |> janitor::clean_names() - diff --git a/omics/kelly/temp/example.csv b/omics/kelly/temp/example.csv deleted file mode 100644 index 5327aab..0000000 --- a/omics/kelly/temp/example.csv +++ /dev/null @@ -1,42 +0,0 @@ -"","t","fluorI" -"1",0,10.1385967718684 -"2",1,8.35533475533268 -"3",2,6.76788471742473 -"4",3,5.36280912133003 -"5",4,4.48247204833858 -"6",5,4.18185893519706 -"7",6,3.34896480340668 -"8",7,2.71315594667858 -"9",8,2.62614956633054 -"10",9,2.06087018509515 -"11",10,1.86074194679208 -"12",11,1.97873314323764 -"13",12,1.83378700440039 -"14",13,1.51439267158402 -"15",14,1.30714846254938 -"16",15,0.741412075403802 -"17",16,0.631299882299171 -"18",17,1.02965656564605 -"19",18,0.902298811540632 -"20",19,0.558746438644141 -"21",20,0.400682660920331 -"22",21,0.802962302399545 -"23",22,0.515497522312792 -"24",23,0.905477723273229 -"25",24,0.344178788232269 -"26",25,0.103340446000128 -"27",26,0.879290356441754 -"28",27,0.577592309885709 -"29",28,0.493046226597491 -"30",29,0.366163886781245 -"31",30,0.125189162368687 -"32",31,0.466644952642418 -"33",32,-0.095514224245819 -"34",33,0.177120019463404 -"35",34,0.20511866185474 -"36",35,0.312909299607934 -"37",36,0.184261436760406 -"38",37,0.151930611035154 -"39",38,0.216249309890573 -"40",39,-0.0782341680185992 -"41",40,0.32520930978664 diff --git a/omics/kelly/workshop.qmd b/omics/kelly/workshop.qmd index 3810f06..c7c17c1 100644 --- a/omics/kelly/workshop.qmd +++ b/omics/kelly/workshop.qmd @@ -635,6 +635,471 @@ ggplot(data = vfa_delta, aes(x = time_day, colour = treatment)) + I have not yet worked out the best way to plot the modelled reaction rate + +# Workflow 2024-04-04 + +This workflow has been written for the data files I now have! Bear in mind that what you might need from here is going to depend on the narrative of your report. You only need include in the compendium things that support your report. + +- [VFAs](https://docs.google.com/spreadsheets/d/1evdDxURggeYih0e4WX1mer9-qjwi0ADZsqlN3JEj3-o/edit#gid=191095748) + + +- [pH](https://docs.google.com/spreadsheets/d/19nDa1EXuZ9Yf7SSwnVPjHQm9MU_zqpaaCeO3VuZtRsk/edit#gid=0) + +I fixed some inconsistent formatting and unhelpful naming (sigh!) and down loaded these as csv files and saved them in the data-raw folder as: + +- [vfa2.csv](data-raw/vfa2.csv) + +- [ph.csv](data-raw/ph.csv) + +- We also have the Molecular weights for each VFA in grams per mole + [mol_wt.txt](data-raw/mol_wt.txt) + +I recommend restarting R before you start this workflow: Control-Shift-F10 (or use the Session menu) + + + +## VFA data + + +🎬 Load packages +```{r} +library(tidyverse) +``` + + + +```{r} + +vfa_cummul <- read_csv("data-raw/vfa2.csv") |> janitor::clean_names() +``` + +This what I think we have: +- set_number Two data sets, one about VFA treatment (2) and one about Protein treatments (1) + +- replicate + + - for set 1: 1-4 + - for set 2: 1-3 + +- treatment + + - for set 1: Casein, Keratin + - for set 2: Acetate, Hexanoic, Decanoic + +- time_day time in days (note time in the ph data in in hours) + +- then columns for each of the 8 measured VFA: acetate, propanoate, isobutyrate, butyrate, isopentanoate, pentanoate, isohexanoate, hexanoate + + +I think some of the data have been mislabelled as set 2 when it is set 1. I changed these in the csv file. + + +I'm going to split these into the two data sets and work on them separately + +🎬 Split the data into the two sets. Note we also remove the set number column as it is no longer needed + +```{r} +vfa_cummul_protein <- vfa_cummul |> + filter(set_number == 1) |> + select(-set_number) + +vfa_cummul_vfa <- vfa_cummul |> + filter(set_number == 2) |> + select(-set_number) +``` + + +`vfa_cummul_protein` has 2 treatments, four replicates and 10 days = 2 x 4 x 10 = 80 rows + +`vfa_cummul_vfa` has 3 treatments, 3 replicates and 10 days = 3 x 3 x 10 = 90 rows + +🎬 import molecular weight data + +```{r} +mol_wt <- read_table("data-raw/mol_wt.txt") |> + mutate(vfa = tolower(vfa)) +``` + +### Set 1: Protein treatments + +#### 1. Calculate *Change* in VFA g/l with time + +🎬 Create dataframe for the change in VFA the change in time + +```{r} +vfa_delta_protein <- vfa_cummul_protein |> + group_by(treatment, replicate) |> + arrange(treatment, replicate, time_day) |> + mutate(acetate = acetate - lag(acetate), + propanoate = propanoate - lag(propanoate), + isobutyrate = isobutyrate - lag(isobutyrate), + butyrate = butyrate - lag(butyrate), + isopentanoate = isopentanoate - lag(isopentanoate), + pentanoate = pentanoate - lag(pentanoate), + isohexanoate = isohexanoate - lag(isohexanoate), + hexanoate = hexanoate - lag(hexanoate), + delta_time = time_day - lag(time_day)) +``` + +Now we have two dataframes, one for the cumulative data and one for the +change in VFA and time. Note that the VFA values have been replaced by the change in VFA but the change in time is in a separate column. I have done this because we later want to plot flux. Note that unlike the sample data, the time steps are all 1 day so the change in time is always 1 and not really needed. I have included it here to make more clear that the units of flux are which is the change in VFA concentration per unit of time per unit of weight or volume of material + +#### 2. Recalculate the data into grams per litre + +To make conversions from mM to g/l we need to do mM \* 0.001 \* MW. We +will pivot the VFA data to long format +and join the molecular weight data to the VFA data. Then we can +calculate the g/l. We will do this for both the cumulative and delta +dataframes. + + + +🎬 Pivot the cumulative data to long format: + +```{r} + +vfa_cummul_protein <- vfa_cummul_protein |> + pivot_longer(cols = -c(treatment, + replicate, + time_day), + values_to = "conc_mM", + names_to = "vfa") +``` + +View `vfa_cummul_protein` to check you understand what you have done. + +🎬 Join molecular weight to data and calculate g/l (mutate to convert to +g/l \* 0.001 \* MW): + +```{r} +vfa_cummul_protein <- vfa_cummul_protein |> + left_join(mol_wt, by = "vfa") |> + mutate(conc_g_l = conc_mM * 0.001 * mw) +``` + +View `vfa_cummul_protein` to check you understand what you have done. + +Repeat for the delta data. + +🎬 Pivot the change data, `vfa_delta_protein` to long format (📢 delta_time is added to the list of columns that do not need to be pivoted but repeated): + +```{r} +vfa_delta_protein <- vfa_delta_protein |> + pivot_longer(cols = -c(treatment, + replicate, + time_day), + values_to = "conc_mM", + names_to = "vfa") +``` + +View `vfa_delta_protein` to check it looks like `vfa_cummul_protein`. + +🎬 Join molecular weight to data and calculate g/l (mutate to convert to +g/l \* 0.001 \* MW): + +```{r} + +vfa_delta_protein <- vfa_delta_protein |> + left_join(mol_wt, by = "vfa") |> + mutate(conc_g_l = conc_mM * 0.001 * mw) +``` + +## 3. Calculate the percent representation of each VFA + +by mM and by weight + +🎬 Add a column which is the percent representation of each VFA for mM +and g/l: + +```{r} +vfa_cummul_protein <- vfa_cummul_protein |> + group_by(treatment, replicate, time_day) |> + mutate(percent_conc_g_l = conc_g_l / sum(conc_g_l) * 100, + percent_conc_mM = conc_mM / sum(conc_mM) * 100) + +``` + +## Graphs for info so far + +🎬 Make summary data for graphing + +```{r} +vfa_cummul_protein_summary <- vfa_cummul_protein |> + group_by(treatment, time_day, vfa) |> + summarise(mean_g_l = mean(conc_g_l), + se_g_l = sd(conc_g_l)/sqrt(length(conc_g_l)), + mean_mM = mean(conc_mM), + se_mM = sd(conc_mM)/sqrt(length(conc_mM))) |> + ungroup() +``` + +```{r} +vfa_delta_protein_summary <- vfa_delta_protein |> + group_by(treatment, time_day, vfa) |> + summarise(mean_g_l = mean(conc_g_l), + se_g_l = sd(conc_g_l)/sqrt(length(conc_g_l)), + mean_mM = mean(conc_mM), + se_mM = sd(conc_mM)/sqrt(length(conc_mM))) |> + ungroup() +``` + +🎬 Graph the cumulative data, grams per litre: + +```{r} + +vfa_cummul_protein_summary |> + ggplot(aes(x = time_day, colour = vfa)) + + geom_line(aes(y = mean_g_l), + linewidth = 1) + + geom_errorbar(aes(ymin = mean_g_l - se_g_l, + ymax = mean_g_l + se_g_l), + width = 0.5, + show.legend = F, + linewidth = 1) + + scale_color_viridis_d(name = NULL) + + scale_x_continuous(name = "Time (days)") + + scale_y_continuous(name = "Mean VFA concentration (g/l)") + + theme_bw() + + facet_wrap(~treatment) + + theme(strip.background = element_blank()) + + + +``` + +🎬 Graph the change data, grams per litre: + +```{r} + +vfa_delta_protein_summary |> + ggplot(aes(x = time_day, colour = vfa)) + + geom_line(aes(y = mean_g_l), + linewidth = 1) + + geom_errorbar(aes(ymin = mean_g_l - se_g_l, + ymax = mean_g_l + se_g_l), + width = 0.5, + show.legend = F, + linewidth = 1) + + scale_color_viridis_d(name = NULL) + + scale_x_continuous(name = "Time (days)") + + scale_y_continuous(name = "Mean change in VFA concentration (g/l)") + + theme_bw() + + facet_wrap(~treatment) + + theme(strip.background = element_blank()) + + + +``` + +🎬 Graph the mean percent representation of each VFA g/l. Note +`geom_col()` will plot proportion if we set`position = "fill"` + +```{r} +vfa_cummul_protein_summary |> + ggplot(aes(x = time_day, y = mean_g_l, fill = vfa)) + + geom_col(position = "fill") + + scale_fill_viridis_d(name = NULL) + + scale_x_continuous(name = "Time (days)") + + scale_y_continuous(name = "Mean Proportion VFA") + + theme_bw() + + facet_wrap(~treatment) + + theme(strip.background = element_blank()) +``` + + + +### Set 2: VFA treatments + +#### 1. Calculate *Change* in VFA g/l with time + +🎬 Create dataframe for the change in VFA the change in time + +```{r} +vfa_delta_vfa <- vfa_cummul_vfa |> + group_by(treatment, replicate) |> + arrange(treatment, replicate, time_day) |> + mutate(acetate = acetate - lag(acetate), + propanoate = propanoate - lag(propanoate), + isobutyrate = isobutyrate - lag(isobutyrate), + butyrate = butyrate - lag(butyrate), + isopentanoate = isopentanoate - lag(isopentanoate), + pentanoate = pentanoate - lag(pentanoate), + isohexanoate = isohexanoate - lag(isohexanoate), + hexanoate = hexanoate - lag(hexanoate), + delta_time = time_day - lag(time_day)) +``` + +Now we have two dataframes, one for the cumulative data and one for the +change in VFA and time. Note that the VFA values have been replaced by the change in VFA but the change in time is in a separate column. I have done this because we later want to plot flux. Note that unlike the sample data, the time steps are all 1 day so the change in time is always 1 and not really needed. I have included it here to make more clear that the units of flux are which is the change in VFA concentration per unit of time per unit of weight or volume of material + +#### 2. Recalculate the data into grams per litre + +To make conversions from mM to g/l we need to do mM \* 0.001 \* MW. We +will pivot the VFA data to long format +and join the molecular weight data to the VFA data. Then we can +calculate the g/l. We will do this for both the cumulative and delta +dataframes. + + +🎬 Pivot the cumulative data to long format: + +```{r} + +vfa_cummul_vfa <- vfa_cummul_vfa |> + pivot_longer(cols = -c(treatment, + replicate, + time_day), + values_to = "conc_mM", + names_to = "vfa") +``` + +View `vfa_cummul_vfa` to check you understand what you have done. + +🎬 Join molecular weight to data and calculate g/l (mutate to convert to +g/l \* 0.001 \* MW): + +```{r} +vfa_cummul_vfa <- vfa_cummul_vfa |> + left_join(mol_wt, by = "vfa") |> + mutate(conc_g_l = conc_mM * 0.001 * mw) +``` + +View `vfa_cummul_vfa` to check you understand what you have done. + +Repeat for the delta data. + +🎬 Pivot the change data, `vfa_delta_vfa` to long format (📢 delta_time is added to the list of columns that do not need to be pivoted but repeated): + +```{r} +vfa_delta_vfa <- vfa_delta_vfa |> + pivot_longer(cols = -c(treatment, + replicate, + time_day), + values_to = "conc_mM", + names_to = "vfa") +``` + +View `vfa_delta_vfa` to check it looks like `vfa_cummul_vfa`. + +🎬 Join molecular weight to data and calculate g/l (mutate to convert to +g/l \* 0.001 \* MW): + +```{r} + +vfa_delta_vfa <- vfa_delta_vfa |> + left_join(mol_wt, by = "vfa") |> + mutate(conc_g_l = conc_mM * 0.001 * mw) +``` + +## 3. Calculate the percent representation of each VFA + +by mM and by weight + +🎬 Add a column which is the percent representation of each VFA for mM +and g/l: + +```{r} +vfa_cummul_vfa <- vfa_cummul_vfa |> + group_by(treatment, replicate, time_day) |> + mutate(percent_conc_g_l = conc_g_l / sum(conc_g_l) * 100, + percent_conc_mM = conc_mM / sum(conc_mM) * 100) + +``` + +## Graphs for info so far + +🎬 Make summary data for graphing + +```{r} +vfa_cummul_vfa_summary <- vfa_cummul_vfa |> + group_by(treatment, time_day, vfa) |> + summarise(mean_g_l = mean(conc_g_l), + se_g_l = sd(conc_g_l)/sqrt(length(conc_g_l)), + mean_mM = mean(conc_mM), + se_mM = sd(conc_mM)/sqrt(length(conc_mM))) |> + ungroup() +``` + +```{r} +vfa_delta_vfa_summary <- vfa_delta_vfa |> + group_by(treatment, time_day, vfa) |> + summarise(mean_g_l = mean(conc_g_l), + se_g_l = sd(conc_g_l)/sqrt(length(conc_g_l)), + mean_mM = mean(conc_mM), + se_mM = sd(conc_mM)/sqrt(length(conc_mM))) |> + ungroup() +``` + +🎬 Graph the cumulative data, grams per litre: + +```{r} + +vfa_cummul_vfa_summary |> + ggplot(aes(x = time_day, colour = vfa)) + + geom_line(aes(y = mean_g_l), + linewidth = 1) + + geom_errorbar(aes(ymin = mean_g_l - se_g_l, + ymax = mean_g_l + se_g_l), + width = 0.5, + show.legend = F, + linewidth = 1) + + scale_color_viridis_d(name = NULL) + + scale_x_continuous(name = "Time (days)") + + scale_y_continuous(name = "Mean VFA concentration (g/l)") + + theme_bw() + + facet_wrap(~treatment) + + theme(strip.background = element_blank()) + + + +``` + +🎬 Graph the change data, grams per litre: + +```{r} + +vfa_delta_vfa_summary |> + ggplot(aes(x = time_day, colour = vfa)) + + geom_line(aes(y = mean_g_l), + linewidth = 1) + + geom_errorbar(aes(ymin = mean_g_l - se_g_l, + ymax = mean_g_l + se_g_l), + width = 0.5, + show.legend = F, + linewidth = 1) + + scale_color_viridis_d(name = NULL) + + scale_x_continuous(name = "Time (days)") + + scale_y_continuous(name = "Mean change in VFA concentration (g/l)") + + theme_bw() + + facet_wrap(~treatment) + + theme(strip.background = element_blank()) + + + +``` + +🎬 Graph the mean percent representation of each VFA g/l. Note +`geom_col()` will plot proportion if we set`position = "fill"` + +```{r} +vfa_cummul_vfa_summary |> + ggplot(aes(x = time_day, y = mean_g_l, fill = vfa)) + + geom_col(position = "fill") + + scale_fill_viridis_d(name = NULL) + + scale_x_continuous(name = "Time (days)") + + scale_y_continuous(name = "Mean Proportion VFA") + + theme_bw() + + facet_wrap(~treatment) + + theme(strip.background = element_blank()) +``` + + + + + + + + Pages made with R [@R-core], Quarto [@allaire2022], `knitr` [@knitr], `kableExtra` [@kableExtra]