SPRFittingPaper2023.jl API
Biophysical and Simulation Parameters
SPRFittingPaper2023.BioPhysParams
— Typemutable struct BioPhysParams{T<:Number}
Biophysical parameters to use in forward simulations.
Fields
kon
: A –> B rate, units of (μM s)⁻¹koff
: B –> A rate, units of s⁻¹konb
: A+B –> C rate, units of s⁻¹reach
: Reach of A+B –> C reaction, units of nmCP
: CP factor (default = 1.0)antigenconcen
: Concentration of antigen (default =DEFAULT_SIM_ANTIGENCONCEN
μM)antibodyconcen
: Concentration of antibodies, should be consistent with kon's units (default = 1.0 μM)
SPRFittingPaper2023.biopars_from_fitting_vec
— Functionbiopars_from_fitting_vec(p; antibodyconcen=1.0, antigenconcen=1.0)
Generate a BioPhysParams
struct from a parameter vector from fitting.
Notes:
- Assumed that $p = [\log_{10}(\text{kon}), \log_{10}(\text{koff}), \log_{10}(\text{kon}_{\text{b}}), \text{reach}, \log_{10}(\text{CP})]$
SPRFittingPaper2023.SimParams
— Typemutable struct SimParams{T<:Number, DIM}
Biophysical parameters to use in forward simulations.
Fields
N
: Number of particles (default= 1000
)tstop
: Time to end simulations at (default= 600.0
)tstop_AtoB
: Time to turn off A –> B reaction, i.e. time the antibody bath is removed. (default= Inf
)tsave
: Times to save data at (default =nothing
)L
: Domain Lengthinitlocs
: Initial Particle Positions (default = uniform in $[-L/2,L/2]^{\text{DIM}}$)resample_initlocs
: Resampleinitlocs
every simulation (default= true
)nsims
: Number of simulations in runsim (to control sampling error) (default= 1000
)
Keyword Arguments:
- All fields have a corresponding kwarg.
antigenconcen = DEFAULT_SIM_ANTIGENCONCEN
, the default antigenconcen in units of (nm)⁻³ (unless usingconvert_agc_units=false
).DIM = 3
the dimension of the underlying space (i.e. 2 or 3).convert_agc_units = true
, set to false to disable the conversion of the antigen units from assumed units of μM to (nm)⁻³, see below. In this case $L$ is calculated using the antigen concentration value directly.resample_initlocs = true
, if set to falseinitlocs
will be constant, simply reusing the initial value sampled in theSimParams
constructor.
Notes:
- Uses the antigen concentration to determine $L$, and so needs to be updated if this concentration changes. The antigen concentration is first converted from assumed units of μM to units of (nm)⁻³. Then
\[ L = \left(\frac{N}{[\text{antigen}] \text{ in (nm)}^{-3}}\right)^{\tfrac{1}{DIM}}\]
Forward Simulations and Callbacks
SPRFittingPaper2023.run_spr_sim!
— Functionrun_spr_sim!(outputter, biopars::BioPhysParams, simpars::SimParams,
terminator = SimNumberTerminator())
Runs a set of SPR simulations via the particle model for a fixed set of physical parameters.
Notes:
- Use the passed
BioPhysParams
andSimParams
to set simulation parameters (including number of simulations). - Use the
outputter
to specify a callback controlling what data is saved. - Use the
terminator
to specify a callback controlling when the simulation is stopped.
SPRFittingPaper2023.TotalBoundOutputter
— Typestruct TotalBoundOutputter{T}
Callback that saves the amount of bound antibodies (i.e. monovalently + bivalently bound) at each save time.
Fields
bindcnt
SPRFittingPaper2023.TotalAOutputter
— Typestruct TotalAOutputter{T}
Callback that saves the amount of unbound antigen at each save time.
Fields
bindcnt
SPRFittingPaper2023.means
— Functionmeans(o::TotalBoundOutputter)
Vector of means.
means(o::TotalAOutputter)
Vector of means.
SPRFittingPaper2023.means!
— Functionmeans!(m, o::TotalBoundOutputter)
In-place vector of means.
SPRFittingPaper2023.vars
— Functionvars(o::TotalBoundOutputter)
Vector of variances.
SPRFittingPaper2023.sems
— Functionmeans(o::TotalBoundOutputter)
Vector of standard errors.
SPRFittingPaper2023.SimNumberTerminator
— Typemutable struct SimNumberTerminator
Callback that stops simulating when the desired number of simulations is reached.
Fields
num_completed_sims
: How many simulations have been completed
SPRFittingPaper2023.VarianceTerminator
— Typemutable struct VarianceTerminator
Callback that stops simulating when the variance in bound antibodies becomes sufficiently small or a maximum number of simulations is reached.
Fields
ssetol
: The tolerance below which to stop simulating (default = .01).notdone
: True if should keep iterating.minsims
: Minimum number of sims to run (default = 15).maxsims
: Maximum number of sims to run (default = 250).
Alignment of SPR Data
SPRFittingPaper2023.AlignedData
— Typestruct AlignedData
The aligned data from a set of SPR experiments varying antibody concentrations.
Fields
times
: times[i] gives the SPR data timepoints for antibodyconcen[i]refdata
: refdata[i] gives the SPR simulation data for antibodyconcens[i]antibodyconcens
: Antibody concentrations for the SPR data set in μMantigenconcen
: Antigen concentration for the SPR data set in μM
SPRFittingPaper2023.get_aligned_data
— Functionget_aligned_data(fname, antigenconcen)
Read the given CSV file representing aligned SPR data. Returns an AlignedData
structure storing the given SPR experiment data.
Notes:
antigenconcen = nothing
the concentration of antigen used in the experiments in units of μM. If not set assumes the CSV filename has the form ""text-AGCCONCEN_aligned.csv"", and parses the number antigen concentration from AGCCONCEN.
Surrogate
SPRFittingPaper2023.SurrogateParams
— Typestruct SurrogateParams{T<:Number}
Biophysical parameters used in the surrogate.
Fields
logkon_range
: log₁₀ space range ofkon
, first order rate in surrogate (units of s⁻¹).logkoff_range
: log₁₀ space range ofkoff
(units of s⁻¹).logkonb_range
: log₁₀ space range ofkonb
, Doi association rate in surrogate (units of s⁻¹).reach_range
: linear range of reach values (units of nm)antigenconcen
: Surrogate's internal antigen concentration in μM (default isDEFAULT_SIM_ANTIGENCONCEN
).antibodyconcen
: Surrogate's internal antibody concentration in μM (default is 1.0).CP
: Surrogate's internal CP value (default is 1.0)
SPRFittingPaper2023.Surrogate
— Typemutable struct Surrogate{S, T, U, V, W}
Surrogate parameters and data.
Fields
surrogate_size
: Number of points for each coordinate within the surrogate lookup table.itp
: Interpolation of the surrogate lookup table.surpars
:SurrogateParams
used in the surrogate.simpars
: Simulation parameters used in the surrogate.
Arguments (one of the following two):
lutfile =
the name of the file storing a surrogate to load.lutdata =
AbstractArray
representing the raw data points to build the surrogate from.
Notes:
- All fields can also be passed as a keyword arg.
SPRFittingPaper2023.build_surrogate_serial
— Functionbuild_surrogate_serial(surrogate_size::Tuple, surpars::SurrogateParams, simpars::SimParams;
terminator=VarianceTerminator())
Construct the data table array for a new surrogate by varying kon, koff, konb and reach.
Arguments:
surrogate_size =
a Tuple with(nkon,nkoff,nkonb,nreach)
points to use.surpars =
the physical parameters to use in the surrogate. It is strongly recommended to not change the default values ofantigenconcen
,antibodyconcen
, orCP
unless you really know what you are doing – these default values are implicitly assumed in other places.simpars =
the simulation parameters to use (number of particles, simulations, domain size, etc).
Keyword Arguments:
terminator
, can be used to alter how the number of samples for each parameter set is determined. SeeVarianceTerminator
for the default values.
SPRFittingPaper2023.save_surrogate
— Functionsave_surrogate(filename, surrogate_size, surpars::SurrogateParams, simpars::SimParams)
Create a JLD file with the given surrogate metadata.
Arguments:
surrogate_size =
a Tuple with(nkon,nkoff,nkonb,nreach)
points to use.surpars =
the physical parameters to use in the surrogate. It is strongly recommended to not change the default values ofantigenconcen
,antibodyconcen
, orCP
unless you really know what you are doing – these default values are implicitly assumed in other places.simpars =
the simulation parameters to use (number of particles, simulations, domain size, etc).
Fitting
SPRFittingPaper2023.fit_spr_data
— Functionfit_spr_data(surrogate::Surrogate, aligneddat::AlignedData, searchrange;
optimiser = nothing, u₀ = nothing)
Find best fit parameters of the surrogate to the given data.
Notes:
searchrange
should be a BlackBoxOptim compatible vector ofTuple
s of the form:
orsearchrange = [logkon_optrange,logkoff_optrange,logkonb_optrange,reach_optrange,logCP_optrange]
In the latter case the other parameter ranges are set equal to the range within the surrogate.searchrange = [logCP_optrange]
- Uses
default_bivalent_optimiser
by default ifoptimiser = nothing
. Otherwise pass anOptimiser
object. u₀
is an optional guess for the inital search point, methods may or may not use.- Returns the best fit optimization object and the best fit (bio) parameters as a tuple.
SPRFittingPaper2023.optpars_to_physpars
— Functionoptpars_to_physpars(optpars, antibodyconcen, antigenconcen,
surrogate_antigenconcen)
optpars_to_physpars(optpars, aligned_data::AlignedData, surrogate::Surrogate)
Converts parameters vector from BlackBoxOptim to physical parameters, converting the reach from simulation to physical values.
Notes:
- The reach is converted from the internal parameter value, εᵢ, to the physical value, εₑ, via
\[ \varepsilon_e = \varepsilon_i \left(\frac{[AGC]_i}{[AGC]_e}\right)^{\tfrac{1}{3}},\]
where $[AGC]_i$ is the internal simulator's antigen concentration and $[AGC]_e$ is the concentration used in experiments. - Assumes these two concentrations have consistent units.
SPRFittingPaper2023.savefit
— Functionsavefit(optsol, aligneddat::AlignedData, surrogate::Surrogate, simpars::SimParams,
outfile)
Saves the data, simulated data with fit parameters, and fit parameters in an XLSX spreadsheet with the given name.
SPRFittingPaper2023.visualisefit
— Functionvisualisefit(optsol, aligneddat::AlignedData, simpars::SimParams,
surrogate::Surrogate, filename=nothing)
Plots fit between data and simulated curves using fitted parameters across a set of antibody concentrations.
Notes:
filename = nothing
if set will cause the graph to be saved.
Private API Functions
SPRFittingPaper2023.surrogate_sprdata_error
— Functionsurrogate_sprdata_error(optpars, surrogate::Surrogate, aligned_data::AlignedData)
This function takes a set of optimization parameters and interpolates a simulated kinetics curve from the surrogate, returning the $L^2$ error against the provided data.
SPRFittingPaper2023.update_pars_and_run_spr_sim!
— Functionupdate_pars_and_run_spr_sim!(outputter, logpars, simpars::SimParams)
Generate the biophysical parameters and run a forward simulation given parameters from the optimizer.
Arguments:
- outputter = an OutPutter instance for what simulation data to record
- logpars = vector of the five optimization parameters: [logkon,logkoff,logkonb,reach,logCP]
- simpars =
SimParams
instance, should be consistent with the surrogate