Skip to main content
Skip table of contents

Batch Simulation Run

This RMarkdown file executes run type of batch simulation. The script utilizes the gastroPlusAPI package to communicate with the GastroPlus X 10.2 service.A batch simulation allows you to run multiple defined simulations for any number of compounds or scenarios.

The output from the batch simulation run is then used to create a Cp-time plot.

To customize your study with this script for a different simulation / project / variables, please make changes to the set-input-information code-chunk.

Configure required packages

  1. Load other necessary packages(tidyverse) required to execute the data manipulation and visualization in the script

  2. Load gastroPlusAPI package

R
library(tidyverse)
library(gastroPlusAPI)

Set working directory

Set working directory as the current source editor context

R
if (rstudioapi::isAvailable()){
  current_working_directory <- dirname(rstudioapi::getSourceEditorContext()$path)
  setwd(current_working_directory)
}

Start GPX Service

Establishes a connection to the GastroPlus service, which allows R to communicate with GastroPlus through its API

R
gpx_service <- start_service(verbose=FALSE)
CODE
✔ Configured the GastroPlus Service
R
gpx_service$is_alive()
CODE
[1] TRUE

Setup Input Information

Make modification to the variables in this chunk to customize your workflow.

project_path: Location of the gpx project

simulation_name: Simulation name that will be included to the run

run_name: Name of the run that will be created

observed_data_group_names & observed_data_series_names: Observed data details to be used for plotting. Details can be retrieved by get_exposure_data().

R
project_path <- "../../ProjectFiles/GPX Library.gpproject"

simulation_name <- "Metoprolol Tartrate 200mg PO tablet"

run_name <- "BatchSimRun"

compound_name <- "Metoprolol Tartrate"

observed_data_group_name <- "Metoprolol Tartrate PO Cp time"
observed_data_series_name <- "Metoprolol Tartrate Exposure Plasma"

Execute the Run

Based on the details mentioned in the previous code chunk, the batch simulation run will be created, executed and results will be shown

R
#Load the project
open_project(project_path)

#Create run and execute simulation
create_run(run_name = run_name, run_type = RunType$BatchSimulation)

add_simulations_to_run(run_name = run_name, simulation_names = simulation_name)

execute_run(run_name = run_name)

Process Run Output

This section retrieves and processes the results from the batch simulation run, including:

Getting summary output with pharmacokinetic parameters

Identifying and retrieving the concentration-time series data

Retrieving observed data for comparison

R
#Get simulation keys and summary output

simulation_keys <- get_simulation_keys(run_name)
summary_output <- get_summary_output(run_name, simulation_keys$simulation_iteration_key_name)

#Get all available series outputs
available_conc_series <- get_available_series_output(run_name, OutputSeriesType$Concentration, simulation_name)

# Check whether we need to use compartmental or PBPK concentration data
# First try to find plasma concentration in systemic circulation (compartmental model)
plasma_concentration_series_descriptor <- paste(
  compound_name,
  CompartmentType$SystemicCirculation,
  StateType$ConcentrationPlasma,
  sep = " - "
)
# Alternative: check for venous return concentration (PBPK model)
venous_return_concentration_series_descriptor <- paste(
  compound_name,
  CompartmentType$VenousReturn,
  StateType$ConcentrationPlasma,
  sep = " - "
)

# Select the appropriate concentration-time descriptor based on availability
CpTime_descriptor <- ""

if(plasma_concentration_series_descriptor %in% available_conc_series$state_descriptor){
  CpTime_descriptor <- plasma_concentration_series_descriptor
}else if(venous_return_concentration_series_descriptor %in% available_conc_series$state_descriptor) {
   CpTime_descriptor <- venous_return_concentration_series_descriptor
}

# Get the concentration-time series data
series_data <- get_series_data(run_name, simulation_name, CpTime_descriptor)

#Get observed data of simulation
observed_series_key <- SeriesKey$new(group_type = ObservedDataGroupType$ExposureData, 
              group_name = observed_data_group_name, 
              series_type = ObservedDataSeriesType$UncertainConcentrationSeries, 
              series_name = observed_data_series_name)

# Get the observed data series
observed_series <- get_observed_series(observed_series_key)$series_as_data_frame()

Plot Results

Creates a concentration-time plot comparing the simulated results with observed data. This visualization helps assess the predictive performance of the simulation.

R
#Plotting
ggplot() + 
  geom_line(data=series_data, 
            mapping=aes(x=independent, y=dependent),
            linewidth=1.25, 
            color="#051082") +
  geom_point(data=observed_series, 
             mapping=aes(x=independent, y=dependent),
             size = 3.5, 
             alpha=0.75, 
             shape=22, 
             color="#051082") +
  theme_classic() + 
  labs(title= paste0(simulation_name," Cp-Time Graph"), x= paste("Time (", series_data$independent_unit[[1]], ")"), y=paste("Concentration (", series_data$dependent_unit[[1]], ")")) +
  theme(
    axis.title.x = element_text(face = "bold", size = 12),
    axis.title.y = element_text(face = "bold", size = 12),
    axis.text.x = element_text(face = "bold", size = 11),
    axis.text.y = element_text(face = "bold", size = 11),
    plot.title = element_text(hjust = 0.5, face = "bold", size = 12, color="#051082")
  )
batch_run_figure.jfif

Kill GPX Service

R
gpx_service$kill()
CODE
[1] TRUE
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.