This article contains case-studies illustrating the benefits of implementing workflows with CoRC. Example code to get started can be found in the tutorial articles on model entitiy management, task management and model building.

Initial Setup

library(tidyverse)
library(parallel)
library(CoRC)

# helper to run tasks in parallel on all cores
mapInParallel <- function(data, fun, ..., .export = character(), .prep = {}) {
  cl <- makeCluster(detectCores())
  clusterExport(cl = cl, .export)
  clusterCall(cl = cl, fun = eval, .prep, env = .GlobalEnv)
  result <- parLapplyLB(cl = cl, X = data, fun = as_mapper(fun), ..., chunk.size = 50)
  stopCluster(cl)
  result
}

3D Trajectory Plot of a Calcium Model

This example loads the Kummer2000 - Oscillations in Calcium Signalling model. The model has 3 species which oscillate. These oscialltions can be visualized as a trajectory through a 3D space. The example does this once in a deterministic and once in a stochatic fashion.

loadSBML("https://www.ebi.ac.uk/biomodels/model/download/BIOMD0000000329?filename=BIOMD0000000329_url.xml")
#> # A COPASI model reference:
#> Model name: "Kummer2000 - Oscillations in Calcium Signalling"
#> Number of compartments: 1
#> Number of species: 3
#> Number of reactions: 8

# Run 24 sec (2 Periods)
setTimeCourseSettings(duration = 24, intervals = 10000)

timeseries <- list(
  deterministic = runTimeCourse()$result,
  stochastic = runTimeCourse(method = list(method = "directMethod", use_random_seed = TRUE, random_seed = 1))$result
)

# Create the same plot for both timeseries
plots <- map(
  timeseries,
  plotly::plot_ly,
  type = "scatter3d",
  mode = "lines",
  x = ~ `G-alpha`,
  y = ~ activePLC,
  z = ~ Calcium,
  color = ~ Time
)

unloadModel()

plots$deterministic
plots$stochastic