Helper functions for model definition

Share:

Description

These functions are used to define models. They become more useful as the model has more places and transitions, as pre and post are sparse matrices so their direct manipulation may be error prone. See example of use below.

Usage

1
2
3
4
init(place)
atr(trans.name=NULL)
load.cfn(place, code)
unload.cfns()

Arguments

place

Places

trans.name

Name of the transition (reaction)

code

C code that returns the propensity

Details

Function init accesses the frame of the calling function, creating variables with the names "model", "L", "R", and "h", that are considered reserved to bioPN. It also creates a variable for each element in the place vector submitted to the function init. Function atr creates a variable for each transition name sent. load.cfn and unload.cfns are used on cases where the transitions are of a special form, and a C function wants to be used to compute it for increase performance.

Value

The functions do not return values.

See Also

GillespieOptimDirect, HaseltineRawlings

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
## bioPN has been tested only on 64 bits machines.
## It may fail in 32 bits architecture.
if (.Machine$sizeof.pointer == 8) {

####### Constants definition (convenient but not required)
H <- 10
K <- 6
r <- 0.25
c <- 3
b <- 2
#######

place <- c( "Gi", "Ga", "mRNA", "Protein")

## WARNING: function init() accesses the frame
##          of the calling function, creating variables
##          with the names "model", "L", "R", and "h",
##          that are considered reserved to bioPN.
##          It also creates a variable for each element
##          in the place vector submitted to the function
##          init(). Function atr() creates a variable
##          for each transition name sent.

####### Initialization
init(place)

####### Start of model definition

## Gi -> Ga
h <- c
L[Gi] <- 1
R[Ga] <- 1
atr("gene_activation") ## Add this reaction

## Ga -> Gi
h <- b
L[Ga] <- 1
R[Gi] <- 1
atr("gene_inactivation")

## Ga -> Ga + mRNA
h <- H
L[Ga] <- 1
R[Ga] <- 1; R[mRNA] <- 1
atr("transcription")
  
## mRNA -> mRNA + Protein
h <- K
L[mRNA] <- 1
R[mRNA] <- 1; R[Protein] <- 1
atr("mRNA_degradation")

## mRNA -> 0
h <- 1
L[mRNA] <- 1
atr("translation")

## Protein -> 0
h <- r
L[Protein] <- 1
atr("protein_degradation")

####### End of model definition

model$M=rep(0, model$places)
model$M[Gi] <- 1

timep <- 200
delta <- 1

## Completely Deterministic
Sim <- RungeKuttaDormandPrince45(model, timep, delta)

runs <- 100

## Completely Stochastic
set.seed(19761111)  ## Set a seed (for reproducible results)
Sim <- GillespieOptimDirect(model, timep, delta, runs)

## Hybrid run
model$slow <- rep(0, model$transitions)
model$slow[c(gene_activation, gene_inactivation)] <- 1

set.seed(19761111)  ## Set a seed (for reproducible results)
Sim <- HaseltineRawlings(model, timep, delta, runs)
}