forked from agiraldeztrujillo/R_Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vignette_SpatialOncoSimul.Rmd
190 lines (154 loc) · 7.63 KB
/
Vignette_SpatialOncoSimul.Rmd
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
---
title: "SpatialOncoSimul with OncoSimulR"
author: "Antonio Giráldez Trujillo, Mercedes Núñez Bayón, María González Bermejo"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{SpatialOncoSimul function}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
SpatialOncoSimul is a function implemented inside the package OncoSimulR for the
spatial simulation of tumoral cell growth. This function will simulate tumor
progression from one starting position in a 1D, 2D or 3D grid specified by the user.
After the first population of tumoral cells is developed with OncoSimulIndiv, a
small population of tumoral cells will migrate to adjacent or remote spaces based
on the fitness of the tumor genotypes. The migrating cells will occupied new space
coordinates and will be combined with an initial population of wild-type cells
present in the new location. Then, the OncoSimulIndiv function will be launched
again in each space coordinate to simulate tumor progression from the new tumor
composition in each position. This process is repeated the number of times specified
by the user to analyse the tumor progression in a spatial context.
The algorithm of SpatialOncoSimul is based on the main concepts of different spatial
models (Bartlomiej Waclaw, et al., 2015, A. Sottoriva, et al., 2015, R. Sun, et al.,
2017, R. Sun, et al., 2021, Noble, R. et al., 2022) and the ideas set out in the
Master's degree final project of Alberto Parramón Castillo (2018).
## Vignette Info
Using this function will often involve the following steps:
1. Specify fitness effects.
2. Simulate cancer progression in a spatial context.Decide on a model.
This basically amounts to choosing a model with exponential growth (“Exp” or “Bozic”)
or a model with carrying capacity (“McFL”). If exponential growth, you can choose
whether the effects of mutations operate on the death rate (“Bozic”) or the birth
rate (“Exp”). It is recommended to use the model with carrying capacity ("McFL")
as the population in this model is kept more constant during the simulation, which
biologically is more meaningful as the cell growth inside the grid is limited by
space. Whereas in the "Exp" o "Bozic" cell population can grow indefinitely or
decrease until extinct.
3. You must also specify the number of iterations for running the simulation and
the spatial model for representing cell migration. The percentage of migrating cells,
the probability of migration to near and remote spaces can also be specified by
the user.
Of course, at least for initial playing around, you can use the defaults.
```{r, fig.show='hold'}
## Here we specified the Fitness Effects of the population genotypes with restrictions
# in the order of accumulation of mutations using a DAG.
s1 <- allFitnessEffects(
data.frame(parent = c("Root", "Root", "i"),
child = c("u" , "i" , "v"),
s = c(0.1 , -0.05 , 0.25),
sh = -1,
typeDep = "MN"),
epistasis = c("u:i" = -1,"u:v" = -1))
evalAllGenotypes (s1 , order = FALSE, addwt = TRUE)
# Simul the spatial tumor cell growth in 3D during 20 iterations, using default
# migration parameters migrationProb = 0.5, largeDistMigrationProb = 1e-6,
# maxMigrationPercentage = 0.2
Spatial_3D <- SpatialOncoSimul(fp = s1,
model = "McFL",
onlyCancer = FALSE,
finalTime = 500,
mu = 1e-4,
initSize = 1000,
keepPhylog = FALSE,
seed = NULL,
errorHitMaxTries = FALSE,
errorHitWallTime = FALSE, initMutant = c("i"),
spatialIterMax = 20, SpatialModel = "3D")
```
## As a second example, we will use a model where we specify restrictions in the
## order of accumulation of mutations using a DAG with the pancreatic cancer poset
## in Gerstung, Eriksson, et al. (2011).
```{r, echo=FALSE, results='asis'}
# We define fitness effects with a new genotype composition.
pancr <- allFitnessEffects(
data.frame(parent = c("Root", rep("KRAS", 4),
"SMAD4", "CDNK2A",
"TP53", "TP53", "MLL3"),
child = c("KRAS","SMAD4", "CDNK2A",
"TP53", "MLL3",
rep("PXDN", 3), rep("TGFBR2", 2)),
s = 0.1,
sh = -0.9,
typeDep = "MN"),
drvNames = c("KRAS", "SMAD4", "CDNK2A", "TP53",
"MLL3", "TGFBR2", "PXDN"))
evalAllGenotypes (pancr , order = FALSE, addwt = TRUE)
Spatial_3D <- SpatialOncoSimul(fp = pancr,
model = "McFL",
onlyCancer = FALSE,
finalTime = 500,
mu = 1e-4,
initSize = 1000,
keepPhylog = FALSE,
seed = NULL,
errorHitMaxTries = FALSE,
errorHitWallTime = FALSE,
spatialIterMax = 10, SpatialModel = "3D")
```
## Testing the SpatialOncoSimul function using functionality of frequency-dependent
## fitness in OncoSimulR package.
With frequency-dependence fitness we can make fitness (actually, birth rate) depend
on the frequency of other genotypes. We specify how the fitness (birth rate) of
each genotype depends (or not) on other genotypes.
```{r, echo=FALSE, results='asis'}
## Define fitness of the different genotypes
gffd <- data.frame(
Genotype = c("WT", "A", "B", "C", "A, B"),
Fitness = c("1 + 1.5 * f_A_B",
"1.3 + 1.5 * f_A_B",
"1.4",
"1.1 + 0.7*((f_A + f_B) > 0.3) + f_A_B",
"1.2 + sqrt(f_1 + f_C + f_B) - 0.3 * (f_A_B > 0.5)"))
afd <- allFitnessEffects(genotFitness = gffd,
frequencyDependentFitness = TRUE,
frequencyType = "rel")
set.seed(1) ## for reproducibility
sfd <- SpatialOncoSimul(afd,
model = 'McFL',
onlyCancer = FALSE,
finalTime = 55, ## short, for speed
mu = 1e-4,
initSize = 1000,
initMutant = c ("A"),
spatialIterMax = 10, SpatialModel = "3D")
```
## As a fourth example, to hightly the importance of migrationProb parameter,
## a simulation is runned with the maximum probability of migration to near spaces.
```{r, echo=FALSE, results='asis'}
# We define fitness effects with a new genotype composition.
s2 <- allFitnessEffects(epistasis = c ("A:-B:-C"=0.05, "-A:B:-C"=0.05 ,
"-A:-B:C"=0.05 ,"A:B:-C"=0.045 ,
"A:-B:C"=0.045 , "-A:B:C"=0.045 ,
"A:B:C"=0.055))
# Simulation of spatial model changing the migration probability to near spaces.
sp2 <- SpatialOncoSimul (s2, model = 'McFL',
onlyCancer = FALSE,
finalTime = 500,
mu = 1e-4,
initSize = 1000,
initMutant = c ("A"),
migrationProb = 1,
largeDistMigrationProb = 1e-6,
maxMigrationPercentage = 0.2,
spatialIterMax = 10, SpatialModel = "2D")
```
Also a quote using `>`:
> "He who gives up [code] safety for [code] speed deserves neither."
([via](https://twitter.com/hadleywickham/status/504368538874703872))