## ---- include = FALSE---------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
has_tk <- capabilities("tcltk") && (
  !grepl("darwin", R.version$os, ignore.case = TRUE) ||
  capabilities("X11")
)

## ----setup--------------------------------------------------------------------
library(rbcmodel)

## ----search_species-----------------------------------------------------------
search_enzyme("aestivum")[1:5,]

## ----search_genus-------------------------------------------------------------
#entries chosen to show breadth of genus entries
search_enzyme("Triticum")[c(1,3,7,15,17),]

## ----search_common------------------------------------------------------------
search_enzyme("wheat")[1:5,]

## ----search_taxonomy----------------------------------------------------------
search_enzyme("Cyanobacteria")[1:5,]

## ----search_comprehensive-----------------------------------------------------
#truncated for readability
search_enzyme("Triticum",data="comprehensive")[1:5,]

## ----search_partial-----------------------------------------------------------
search_enzyme("Trit",match="partial")

## ----search_partial2----------------------------------------------------------
search_enzyme("Trit",match="partial",level="genus")[1:5,]

## ----create_wheat-------------------------------------------------------------
Rbc_wheat <- Enzyme("aestivum_Iñiguez_2021",enzyme_name="wheat")

## ----check_wheat--------------------------------------------------------------
check_enzyme(Rbc_wheat)

## ----search_DH----------------------------------------------------------------
search_DHScale("Triticum")
search_DHScale("Cyanobacteria")
search_DHScale("1A")

## ----create_wheat_DH----------------------------------------------------------
#look for wheat-specific data
search_DHScale("Triticum")
#create the wheat one from its known data
wheat_DH<-DHScale("aestivum_orr_2016_dH",data="abridged")
#modify scale to replace Ko value
wheat_DH<-modify_DHScale(wheat_DH,Ko_dH=26.7)
check_DHScale(wheat_DH)

## ----wheat_function-----------------------------------------------------------
wheat_carbon<-CO2_dependence(Rbc_wheat,wheat_DH)

## ----wheat_rate---------------------------------------------------------------
wheat_carbon(15,200,25)

## ----wheat_grid---------------------------------------------------------------
#set up the lists of values for independent variables
CO2_seq<-O2_seq<-seq(0,1000,by=10)
temp_seq<-seq(0,40,by=.1)
#make the grid
wheat_grid<-make_4D_grid(wheat_carbon,CO2_seq,O2_seq,temp_seq,var_names=c("CO2","O2","T","wheat"))

## ----wheat_slice--------------------------------------------------------------
#create the temperature slice at 25C from the grid
s1<-slice_4D_grid(wheat_grid,dim=3,25)

## ----plot_wheat_simple, eval = has_tk-----------------------------------------
plot_slice_3D(s1)

## ----plot_wheat, eval = has_tk------------------------------------------------
#plot the slice with some contours
plot_slice_3D(s1,contours=c(1.5,2,2.5),xlabel="CO2",ylabel="O2")

## ----transpose_wheat----------------------------------------------------------
#transpose the temperature slice we made
s2<-transpose_3D_slice(s1)

## ----plot_tranposed_wheat, eval = has_tk--------------------------------------
#plot the new slice
plot_slice_3D(s2,contours=c(1.5,2,2.5),xlabel="O2",ylabel="CO2")

## ----spinach------------------------------------------------------------------
Rbc_spinach<-Enzyme("oleracea_Iñiguez_2021",enzyme_name="spinach")
spinach_dH<-new_DHScale(46.2,50.2,26.7,-18.15,name="spinach")
spinach_carbon<-CO2_dependence(Rbc_spinach,spinach_dH)

## ----compare------------------------------------------------------------------
#create the comparison
wh_v_sp<-CO2_comparison(wheat_carbon,spinach_carbon)
#the original carbon fixation rates of both enzymes
wheat_carbon(15,200,25)
spinach_carbon(15,200,25)
#using the comparison to calculate the difference between the enzymes
wh_v_sp(15,200,25)

## ----plot_comparison, eval = has_tk-------------------------------------------
#create the grid
wh_v_sp_grid<-make_4D_grid(wh_v_sp,CO2_seq,O2_seq,temp_seq,var_names=c("CO2","O2","T","wheat/spinach comp"))
#slice at 25C
s3<-slice_4D_grid(wh_v_sp_grid,dim=3,25)
#plot the slice
plot_slice_3D(s3,xlabel="CO2",ylabel="O2")

## ----0C_comparison, eval = has_tk---------------------------------------------
#slice at 0C
s4<-slice_4D_grid(wh_v_sp_grid,dim=3,0)
#plot 0C slice
plot_slice_3D(s4,contours=NULL,xlabel="CO2",ylabel="O2")

## ----13C_comparison, eval = has_tk--------------------------------------------
#slice at 13C
s5<-slice_4D_grid(wh_v_sp_grid,dim=3,13)
#plot slice
plot_slice_3D(s5,contours=seq(-0.03,.03,length.out=7),xlabel="CO2",ylabel="O2")

## ----CO2vT_comparison, eval = has_tk------------------------------------------
#slice O2 at 500uM
s6<-slice_4D_grid(wh_v_sp_grid,dim=2,500)
#plot slice
plot_slice_3D(s6,contours=c(-1,0,1,2,3,4),dims=c(1,3,4),xlabel="CO2",ylabel="T")

## ----citing_data--------------------------------------------------------------
cite_Rbc(c("aestivum_orr_2016_dH","oleracea_Iñiguez_2021"))

## ----abridged-----------------------------------------------------------------
search_enzyme("Average")[1,]

## ----comprehensive------------------------------------------------------------
search_enzyme("Triticum",data="comprehensive")[1,]

## ----temp_tables--------------------------------------------------------------
#an entry in the abridged DHScale table
search_DHScale("Triticum",data="abridged")[1,]
#an entry in the averages DHScale table
search_DHScale("1B",data="averaged")[1,]

