aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2014-11-12 16:59:48 +0100
committerJohannes Ranke <jranke@uni-bremen.de>2014-11-12 16:59:48 +0100
commitc04d0bb0e795b67b6958150e8524c5265587f618 (patch)
tree4a10eb4a9b612745b4aa9ed1e4f1898a2d6d0ac1
parent401570aa9e58c4a2f2e939f37f496453d97d3f33 (diff)
IORE working for parent and metabolites, introduce mkinsub
-rw-r--r--NEWS.md1
-rw-r--r--R/mkinfit.R9
-rw-r--r--R/mkinsub.R23
-rw-r--r--R/transform_odeparms.R5
-rw-r--r--man/mkinfit.Rd6
-rw-r--r--man/mkinsub.Rd44
6 files changed, 84 insertions, 4 deletions
diff --git a/NEWS.md b/NEWS.md
index cd082280..8d4a7782 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,7 @@
## NEW FEATURES
+- Add the convenience function `mkinsub()` for creating the lists used in `mkinmod()`
- Add the possibility to fit indeterminate order rate equation (IORE) models using an analytical solution (parent only) or a numeric solution. Paths from IORE compounds to metabolites are supported when using of formation fractions (use_of_ff = 'max'). Note that the numerical solution (method.ode = 'deSolve') of the IORE differential equations sometimes fails due to numerical problems.
diff --git a/R/mkinfit.R b/R/mkinfit.R
index a6889b0b..7a465c2b 100644
--- a/R/mkinfit.R
+++ b/R/mkinfit.R
@@ -43,7 +43,7 @@ mkinfit <- function(mkinmod, observed,
{
# Check mkinmod and generate a model for the variable whith the highest value
# if a suitable string is given
- parent_models_available = c("SFO", "FOMC", "DFOP", "HS", "SFORB")
+ parent_models_available = c("SFO", "FOMC", "DFOP", "HS", "SFORB", "IORE")
if (class(mkinmod) != "mkinmod") {
presumed_parent_name = observed[which.max(observed$value), "name"]
if (mkinmod[[1]] %in% parent_models_available) {
@@ -60,7 +60,10 @@ mkinfit <- function(mkinmod, observed,
method.modFit = match.arg(method.modFit)
if (maxit.modFit != "auto") {
if (method.modFit == "Marq") control.modFit$maxiter = maxit.modFit
- if (method.modFit == "Port") control.modFit$iter.max = maxit.modFit
+ if (method.modFit == "Port") {
+ control.modFit$iter.max = maxit.modFit
+ control.modFit$eval.max = maxit.modFit
+ }
if (method.modFit %in% c("SANN", "Nelder-Mead", "BFGS", "CG", "L-BFGS-B")) {
control.modFit$maxit = maxit.modFit
}
@@ -308,6 +311,8 @@ mkinfit <- function(mkinmod, observed,
if (!transform_rates) {
index_k <- grep("^k_", names(lower))
lower[index_k] <- 0
+ index_k.iore <- grep("^k.iore_", names(lower))
+ lower[index_k.iore] <- 0
other_rate_parms <- intersect(c("alpha", "beta", "k1", "k2", "tb"), names(lower))
lower[other_rate_parms] <- 0
}
diff --git a/R/mkinsub.R b/R/mkinsub.R
new file mode 100644
index 00000000..f92af54b
--- /dev/null
+++ b/R/mkinsub.R
@@ -0,0 +1,23 @@
+# Copyright (C) 2014 Johannes Ranke
+# Portions of this code are copyright (C) 2013 Eurofins Regulatory AG
+# Contact: jranke@uni-bremen.de
+
+# This file is part of the R package mkin
+
+# mkin is free software: you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>
+mkinsub <- function(submodel, to = NULL, sink = TRUE)
+{
+ return(list(type = submodel, to = to, sink = sink))
+}
+# vim: set ts=2 sw=2 expandtab:
diff --git a/R/transform_odeparms.R b/R/transform_odeparms.R
index 778f56cd..aa70a0b3 100644
--- a/R/transform_odeparms.R
+++ b/R/transform_odeparms.R
@@ -38,8 +38,7 @@ transform_odeparms <- function(parms, mkinmod,
if (length(k) > 0) {
if(transform_rates) {
transparms[paste0("log_", names(k))] <- log(k)
- }
- else transparms[names(k)] <- k
+ } else transparms[names(k)] <- k
}
# Do not transform exponents in IORE models
@@ -123,6 +122,8 @@ backtransform_odeparms <- function(transparms, mkinmod,
} else {
trans_k <- transparms[grep("^k_", names(transparms))]
parms[names(trans_k)] <- trans_k
+ trans_k.iore <- transparms[grep("^k.iore_", names(transparms))]
+ parms[names(trans_k.iore)] <- trans_k.iore
}
# Do not transform exponents in IORE models
diff --git a/man/mkinfit.Rd b/man/mkinfit.Rd
index c40dff83..a16ed177 100644
--- a/man/mkinfit.Rd
+++ b/man/mkinfit.Rd
@@ -216,6 +216,12 @@ mkinfit(mkinmod, observed,
Gao). A similar implemention can also be found in CAKE 2.0, which is the
other GUI derivative of mkin, sponsored by Syngenta.
}
+\note{
+ When using the "IORE" submodel for metabolites, fitting with
+ "transform_rates = TRUE" (the default) often leads to failures of the
+ numerical ODE solver. In this situation it may help to switch off the
+ internal rate transformation.
+}
\author{
Johannes Ranke
}
diff --git a/man/mkinsub.Rd b/man/mkinsub.Rd
new file mode 100644
index 00000000..637a671c
--- /dev/null
+++ b/man/mkinsub.Rd
@@ -0,0 +1,44 @@
+\name{mkinsub}
+\alias{mkinsub}
+\title{
+ Function to set up a kinetic submodel for one state variable
+}
+\description{
+ This is a convenience function to set up the lists used as arguments for
+ \code{\link{mkinmod}}.
+}
+\usage{
+mkinsub(type, to = NULL, sink = TRUE)
+}
+\arguments{
+ \item{type}{
+ Character vector of length one to specify the submodel type. See
+ \code{\link{mkinmod}} for the list of allowed submodel names.
+ }
+ \item{to}{
+ Vector of the names of the state variable to which a transformation
+ shall be included in the model.
+ }
+ \item{sink}{
+ Should a pathway to sink be included in the model in addition to the
+ pathways to other state variables?
+ }
+}
+\value{
+ A list for use with \code{\link{mkinmod}}.
+}
+\author{
+ Johannes Ranke
+}
+\examples{
+# One parent compound, one metabolite, both single first order.
+SFO_SFO <- mkinmod(
+ parent = list(type = "SFO", to = "m1"),
+ m1 = list(type = "SFO"))
+
+# The same model using mkinsub
+SFO_SFO.2 <- mkinmod(
+ parent = mkinsub("SFO", "m1"),
+ m1 = mkinsub("SFO"))
+}
+

Contact - Imprint