admModel.txt

Download

[LONGITUDINAL]
input = {F, ka, V, Cl}

PK:
depot(type=1, target=Ad, p=F)
depot(type=2, target=Ac)

EQUATION:
k = Cl/V
ddt_Ad = -ka*Ad
ddt_Ac =  ka*Ad - k*Ac
Cc = Ac/V

simulxCode.R

ui.R

Download

#-------------------------------------------------------------------------
#  This application is governed by the CeCILL-B license. 
#  You can  use, modify and/ or redistribute this code under the terms
#  of the CeCILL license:  http://www.cecill.info/index.en.html
#
#  Marc Lavielle, Inria Saclay
#  April 29th, 2015
#-------------------------------------------------------------------------

library(shinydashboard)

sidebar <- dashboardSidebar(
  hr(),
  sidebarMenu(id="tabs",
              menuItem("Plot", tabName = "plot", icon = icon("line-chart"), selected=TRUE),
              menuItem("Table", tabName = "table", icon = icon("table")),
              menuItem("Codes",  icon = icon("file-text-o"),
                       menuSubItem("Mlxtran", tabName = "mlxtran", icon = icon("angle-right")),
                       menuSubItem("Simulx", tabName = "pkmodel", icon = icon("angle-right")),
                       menuSubItem("ui.R", tabName = "ui", icon = icon("angle-right")),
                       menuSubItem("server.R", tabName = "server", icon = icon("angle-right"))
              ),
              menuItem("ReadMe", tabName = "readme", icon = icon("mortar-board")),
              menuItem("About", tabName = "about", icon = icon("question"))
  ),
  hr(),
  conditionalPanel("input.tabs=='plot'",
                   sidebarMenu(
                     menuItem("Administration", icon = icon("chevron-circle-right"),
                              menuSubItem("oral", tabName = "oral", icon = icon("angle-right")),
                              menuSubItem("iv", tabName = "iv", icon = icon("angle-right"))
                     ),
                     menuItem("Parameters", tabName = "parameter", icon = icon("chevron-circle-right"), selected=TRUE),
                     menuItem("Output", tabName = "output", icon = icon("chevron-circle-right"))
                   ),
                   hr()
  )
)

body <- dashboardBody(
  tabItems(
    tabItem(tabName = "plot",
            fluidRow( 
              box(width = 12, status = "primary",
                  plotOutput("plot",  height="400px")
              ),
              tabItems(
                tabItem(tabName = "oral",
                        box(width = 4, status = "primary",          
                            sliderInput("tfd1", "Time of first dose:", value=0, min=-20, max = 20, step=2),
                            sliderInput("nd1", "Number of doses:", value=15, min=0, max = 20, step=1)
                        ),
                        box(width = 4, status = "primary",          
                            sliderInput("ii1", "Interdose interval:", value = 6, min = 1, max = 15, step=1),
                            sliderInput("amt1", "Amount:", value = 100, min = 0, max = 200, step=10)
                        )
                ),
                tabItem(tabName = "iv",
                        box(width = 4, status = "primary",          
                            sliderInput("tfd2", "Time of first dose:", value=3, min=-20, max = 20, step=2),
                            sliderInput("nd2", "Number of doses:", value=8, min=0, max = 20, step=1)
                        ),
                        box(width = 4, status = "primary",          
                            sliderInput("ii2", "Interdose interval:", value = 12, min = 1, max = 24, step=1),
                            sliderInput("amt2", "Amount:", value = 50, min = 0, max = 200, step=10)
                        ),
                        box(width = 4, status = "primary",          
                            sliderInput("tinf2", "Infusion time:", value = 1, min = 0, max = 5, step=0.2)
                        )
                ),
                tabItem(tabName = "parameter",
                        box(width = 4, status = "primary",        
                            sliderInput("F", "bioavailability F:", value = 0.7, min = 0, max = 1, step=0.05),
                            sliderInput("ka", "absorption rate constant ka:", value = 0.5, min = 0, max = 4, step=0.1) 
                        ),
                        box(width = 4, status = "primary",        
                            sliderInput("V", "volume V:", value = 10, min = 1, max = 20, step=1),
                            sliderInput("Cl", "clearance Cl:", value = 2, min = 0, max = 4, step=0.1)
                        )
                ),
                tabItem(tabName = "output",
                        box(width = 4, status = "primary",          
                            radioButtons("log", "", c("linear scale" = FALSE,"log scale" = TRUE))  
                        ),
                        box(width = 4, status = "primary",
                            sliderInput("range", "time range", min = -10, max = 200, value = c(-5,100), step=5),
                            sliderInput("ngp", "grid size", min = 50, max = 1000, value = 500, step=50)
                        ),
                        box(width = 4, status = "primary", 
                            sliderInput("lsize", "line width", min = 0, max = 5, value = 0.75, step=0.25)
                        )
                )
              )
            )
    ),
    tabItem(tabName = "table",
            box( width = NULL, status = "primary", solidHeader = TRUE, title="Table",                
                 downloadButton('downloadTable', 'Download'),
                 br(),br(),
                 tableOutput("table")
            )
    ),
    tabItem(tabName = "mlxtran",
            box( width = NULL, status = "primary", solidHeader = TRUE, title="admModel.txt",                
                 downloadButton('downloadData4', 'Download'),
                 br(),br(),
                 pre(includeText("admModel.txt"))
            )
    ),
    tabItem(tabName = "pkmodel",
            box( width = NULL, status = "primary", solidHeader = TRUE, title="simulxCode.R",                
                 downloadButton('downloadData1', 'Download'),
                 br(),br(),
                 verbatimTextOutput("RFile")
            )
    ),
    tabItem(tabName = "ui",
            box( width = NULL, status = "primary", solidHeader = TRUE, title="ui.R",
                 downloadButton('downloadData2', 'Download'),
                 br(),br(),
                 pre(includeText("ui.R"))
            )
    ),
    tabItem(tabName = "server",
            box( width = NULL, status = "primary", solidHeader = TRUE, title="server.R",
                 downloadButton('downloadData3', 'Download'),
                 br(),br(),
                 pre(includeText("server.R"))
            )
    ),
    tabItem(tabName = "readme",
            withMathJax(), 
            includeMarkdown("readMe.Rmd")
    ),
    tabItem(tabName = "about",
            includeMarkdown("../../about/about.Rmd")
    )
  )
)

dashboardPage(
  dashboardHeader(title = "Combine oral and iv"),
  sidebar,
  body
)

server.R

Download

#-------------------------------------------------------------------------
#  This application is governed by the CeCILL-B license. 
#  You can  use, modify and/ or redistribute this code under the terms
#  of the CeCILL license:  http://www.cecill.info/index.en.html
#
#  Marc Lavielle, Inria Saclay
#  April 29th, 2015
#-------------------------------------------------------------------------

library(shinydashboard)
library(mlxR)

shinyServer(function(input, output) {
  simulx.text <- ("
              parameter = p,
              output    = Cc)
                
print(ggplot(data=res$Cc, aes(x=time, y=Cc)) + geom_line() +
xlab('time (h)') + ylab('concentration (mg/L)'))
                ")
  
  r <- reactive({  
    if (input$tinf2>input$ii2)
      stop("The infusion time should not exceed the interdose interval")
    
    param.value=c(input$F,input$ka,input$V,input$Cl)
    t.value=seq(input$range[1],input$range[2],length.out=input$ngp)
    t11=input$tfd1
    t12=input$ii1*(input$nd1-1)+t11
    if (t12>=t11){
      t1.dose=seq(t11,t12,by=input$ii1)
      adm1 <- list(time=t1.dose, amount=input$amt1, type=1)
    }else{
      adm1 <- list(time=t11, amount=0, type=1)
    }
    t21=input$tfd2
    t22=input$ii2*(input$nd2-1)+t21
    if (t22>=t21){
      t2.dose=seq(t21,t22,by=input$ii2)
      adm2 <- list(time=t2.dose, amount=input$amt2, rate=input$amt2/input$tinf2, type=2)
    }else{
      adm2 <- list(time=t21, amount=0, type=2)
    }
    
    f  <- list(name=c('Cc'),time=t.value)
    p   <- list(name=c('F','ka','V','Cl'), value=param.value)
    
    res <- simulx( model     = 'admModel.txt',
                   treatment = list(adm1,adm2), 
                   parameter = p,
                   output    = f)
    
    if (input$nd1==0){
      a1.text <- ''
    } else if(input$nd1==1){
      a1.text <- paste0('adm1 <- list(type=1, amount=',input$amt1,', time=',input$tfd1,')\n')
    } else{
      t1=input$tfd1
      t2=input$ii1*(input$nd1-1)+t1
      a1.text <- paste0('adm1 <- list(type=1, amount=',input$amt1,
                        ', time=seq(',t1,', ',t2,', by=',input$ii1,'))\n')
    }
    if (input$nd2==0){
      a2.text <- ''
    }else{
      if(input$nd2==1){
        a2.text <- paste0('adm2 <- list(type=2, amount=',input$amt2,', time=',input$tfd2)
      } else{
        t1=input$tfd2
        t2=input$ii2*(input$nd2-1)+t1
        a2.text <- paste0('adm2 <- list(type=2, amount=',input$amt2,
                          ', time=seq(',t1,', ',t2,', by=',input$ii2,')')
      }
      if (input$tinf2>0){
        a2.text <- paste0(a2.text,', tinf=',input$tinf2,')\n')
      }else{
        a2.text <- paste0(a2.text,')\n')      
      }
    }
    a.text <- paste0(a1.text,a2.text)
    
    m.text <- "res <- simulx(model     = 'admModel.txt',\n              "
    if (input$nd1>0){
      if (input$nd2>0){
        m.text <- paste0(m.text,'treatment = list(adm1, adm2),')
      }else{
        m.text <- paste0(m.text,'treatment = adm1,')        
      }
    }else{
      if (input$nd2>0){
        m.text <- paste0(m.text,'treatment = adm2,')        
      }      
    }
    
    p.text <- paste0('p <- c(F=',input$F,', ka=',input$ka,', V=',input$V,', Cl=',input$Cl,')')
    t.text <- paste0("Cc <- list(name='Cc', time=seq(",input$range[1],', ',input$range[2],
                     ', length=',length.out=input$ngp,'))')
    simulx.text <- paste0(a.text,p.text,'\n',t.text,'\n',m.text,simulx.text)
    
    out <- list(res,simulx.text)
    return(out)
  })
  
  
  output$plot <- renderPlot({
    pl=ggplotmlx(data=r()[[1]]$Cc, aes(x=time, y=Cc)) + geom_line(size=input$lsize) 
    if (input$log==TRUE)
      pl=pl + scale_y_log10()
    print(pl)
  })
  
  output$table <- renderTable({ r()[[1]][[1]] })
  output$RFile  <- renderText(r()[[2]])
  
  output$downloadTable <- downloadHandler(
    filename = "table.csv",
    content = function(file) {
      write.csv(r()[[1]], file)
    }
  )
  
  output$downloadData1 <- downloadHandler(
    filename = "simulxCode.R",
    content = function(file) {
      write(r()[[2]], file)
    }
  )
  
  output$downloadData2 <- downloadHandler(
    filename = "ui.R",
    content = function(file) {
      con        = file("ui.R", open = "r")
      lines      = readLines(con)
      close(con)
      write(lines, file)
    }
  )
  
  output$downloadData3 <- downloadHandler(
    filename = "server.R",
    content = function(file) {
      con        = file("server.R", open = "r")
      lines      = readLines(con)
      close(con)
      write(lines, file)
    }
  )
  
  output$downloadData4 <- downloadHandler(
    filename = "admModel.txt",
    content = function(file) {
      con        = file("admModel.txt", open = "r")
      lines      = readLines(con)
      close(con)
      write(lines, file)
    }
  )
  
})

Combination of repeated oral and intravenous administrations

Let \(A_d\) and \(A_c\) be, respectively, the amounts in the depot compartment (gut) and the central compartment (bloodtsream).

Kinetics of \(A_d\) and \(A_c\) are described by the following system of ODEs \[ \begin{aligned} \dot{A_d}(t) & = - ka \, A_d(t) \\ \dot{A_c}(t) & = ka \, A_d(t) - k \, A_c(t) \end{aligned} \]

The concentration \(C_c\) in the central compartment is defined by \(\ \ C_c(t) = A_c(t)/V\)

  • Define the dosage regimen for the oral administration with menu oral: time of first dose, number of doses, interdose interval, amount.

  • Define the dosage regimen for the intravenous (iv) administration with menu iv: time of first dose, number of doses, interdose interval, infusion time, amount.

  • select the PK parameters with menu Parameters:
    • \(F\), the bioavalabililty (a fraction between 0 and 1) ,
    • \(ka\), the absorption rate constant,
    • \(V\), the volume of the central compartment.
    • \(k\), the elimination rate constant,

  • define the outputs with menu Output :
    • select the scale (linear or log),
    • select the time range where the prediction is computed,
    • select the number of time points of the grid where the prediction is computed.


This application is governed by the CeCILL-B license.
You can use, modify and/or redistribute these codes under the terms of the CeCILL license.


This Shiny application requires the mlxR package.


Marc Lavielle
Inria Saclay, Popix team
April 29th, 2015