Skip to content

Commit

Permalink
Fixes for documentations build under linux
Browse files Browse the repository at this point in the history
  • Loading branch information
albertocasagrande committed Nov 22, 2023
1 parent d11542c commit 1ace457
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 33 deletions.
2 changes: 1 addition & 1 deletion R/plot_muller.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ collapse_loops <- function(df_edges) {
#' sim$add_genotype(name = "A",
#' epigenetic_rates = c("+-" = 0.01, "-+" = 0.01),
#' growth_rates = c("+" = 0.2, "-" = 0.08),
#' death_rates = c("+" = 0.1, "-" = 0.01))
#' death_rates = c("+" = 0.02, "-" = 0.01))
#' sim$history_delta = 1
#' sim$place_cell("A+", 500, 500)
#' sim$run_up_to_time(60)
Expand Down
6 changes: 3 additions & 3 deletions src/drivers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,11 +831,11 @@ List Simulation::get_cells() const
//' sim$add_genotype(genotype = "A",
//' epigenetic_rates = c("+-" = 0.01, "-+" = 0.01),
//' growth_rates = c("+" = 0.2, "-" = 0.08),
//' death_rates = c("+" = 0.1, "-" = 0.01))
//' death_rates = c("+" = 0.02, "-" = 0.01))
//' sim$add_genotype(genotype = "B",
//' epigenetic_rates = c("+-" = 0.02, "-+" = 0.01),
//' growth_rates = c("+" = 0.3, "-" = 0.1),
//' death_rates = c("+" = 0.1, "-" = 0.01))
//' death_rates = c("+" = 0.02, "-" = 0.01))
//' sim$schedule_genotype_mutation(src = "A", dst = "B", time = 50)
//' sim$place_cell("A+", 500, 500)
//' sim$run_up_to_time(70)
Expand Down Expand Up @@ -1672,7 +1672,7 @@ void Simulation::mutate_progeny(const Races::Drivers::Simulation::AxisPosition&
//' sim$add_genotype(genotype = "A",
//' epigenetic_rates = c("+-" = 0.01, "-+" = 0.01),
//' growth_rates = c("+" = 0.2, "-" = 0.08),
//' death_rates = c("+" = 0.1, "-" = 0.01))
//' death_rates = c("+" = 0.01, "-" = 0.01))
//' sim$place_cell("A+", 500, 500)
//' sim$run_up_to_time(70)
//'
Expand Down
38 changes: 22 additions & 16 deletions vignettes/a01_tissue_simulation.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ unlink("Test", recursive = TRUE)
sim <- new(Simulation, "Test")
```

```{r echo=FALSE, results='hide', message=FALSE, warning=FALSE}
sim$death_activation_level <- 50
```

Class `Simulation` exports a `show` method to get information on the
current object.

Expand Down Expand Up @@ -199,7 +203,7 @@ thousands of cells.

```{r, fig.height=4, fig.width=3}
# Piechar for counts
plot_state(sim)
plot_state(sim)
# Spatial distribution for the whole tissue (hexagonal bins)
plot_tissue(sim)
Expand Down Expand Up @@ -279,7 +283,7 @@ sim$get_clock()
plot_tissue(sim)
```

##### **Getting cells (advanced)**
##### **Getting cells (Advanced)**

At this point, if we query the simulation we will find more cells (we
use `dplyr` to process query results). For convenience, the getters
Expand Down Expand Up @@ -337,7 +341,7 @@ therefore new species `B+` and `B-` - as descending from `A,`we need to:
genotype `B`.

```{r}
# We locate a random cell
# We locate a random cell
cell <- sim$choose_cell_in("A")
cell
Expand Down Expand Up @@ -374,7 +378,7 @@ plot_tissue(sim, num_of_bins = 250)
# Facet on species via ggplot
library(ggplot2)
plot_tissue(sim) + facet_wrap(~species)
plot_tissue(sim, num_of_bins = 250) + facet_wrap(~species)
```

If, at this point in the simulation, we generate a new genotype `C` from
Expand All @@ -395,7 +399,7 @@ sim$run_up_to_time(sim$get_clock() + 10)

```{r, fig.height=4, fig.width=3}
plot_state(sim)
plot_tissue(sim)
plot_tissue(sim, num_of_bins = 250)
```

### Other operations
Expand Down Expand Up @@ -472,12 +476,14 @@ the state (by default, `history_delta` is set to $0$).

We show this by re-simulating a tumour with two subclones.

```{r}
```{r echo=FALSE, results='hide', message=FALSE, warning=FALSE}
# Cancel old data
unlink(sim$get_name(), recursive = TRUE)
```

```{r}
# Example time-series on a new simulation, with coarse-grained time-series
sim <- new(Simulation)
sim <- new(Simulation, "Finer Time Series")
sim$history_delta <- 1
sim$death_activation_level <- 100
Expand Down Expand Up @@ -517,7 +523,7 @@ sim$add_genotype(name = "D",
sim$mutate_progeny(sim$choose_cell_in("A"), "D")
sim$run_up_to_size("D+", 4000)
sim$run_up_to_size("D+", 400)
```

The time-series can be plot using `plot_timeseries`.
Expand Down Expand Up @@ -551,12 +557,12 @@ still, it help understand trends.

```{r, fig.height=4, fig.width=6, message=FALSE, warning=FALSE}
# Custom Mullers
clock = sim$get_clock()
clock <- sim$get_clock()
plot_muller(sim) + ggplot2::xlim(clock * 3/4, clock)
plot_muller(sim) +
ggplot2::xlim(clock * 3/4, clock) +
plot_muller(sim) +
ggplot2::xlim(clock * 3/4, clock) +
ggplot2::scale_y_log10()
```

Expand All @@ -573,24 +579,24 @@ and `B-`.
# Current rates
sim
# Raise the death rate to very high levels
# Raise the death rate levels
sim$update_rates("B+", c(death = 3))
sim$update_rates("B-", c(death = 3))
sim$update_rates("C+", c(death = 3))
sim$update_rates("C-", c(death = 3))
# Now D will become larger
sim$run_up_to_size("D+", 60000)
sim$run_up_to_size("D+", 6000)
# Current state
sim
# This now show the change in rates
clock = sim$get_clock()
clock <- sim$get_clock()
plot_muller(sim) + ggplot2::xlim(clock * 3/4, clock)
plot_muller(sim) +
ggplot2::xlim(clock * 3/4, clock) +
plot_muller(sim) +
ggplot2::xlim(clock * 3/4, clock) +
ggplot2::scale_y_log10()
```

Expand Down
42 changes: 29 additions & 13 deletions vignettes/a02_sampling_simulation.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ In general, these plots can be annotated with extra information, such as the sam
# Full plot
plot_forest(forest) %>%
annotate_forest(forest)
# S_1_1 plot
plot_forest(S_1_1_forest) %>%
annotate_forest(S_1_1_forest)
Expand All @@ -194,8 +193,7 @@ unlink(sim$get_name(), recursive = TRUE)


```{r}
# Monoclonal model, no epigenotypes
sim <- new(Simulation, "Monoclonal")
sim <- new(Simulation, "Randomised")
sim$add_genotype(name = "A", growth_rates = 0.1, death_rates = 0.01)
Expand Down Expand Up @@ -241,7 +239,9 @@ current +
geom_rect(xmin = bbox$p[1], xmax = bbox$q[1],
ymin = bbox$p[2], ymax = bbox$q[2],
fill = NA, color = "black")
```

```{r}
sim$sample_cells("S_2_1", bbox$p, bbox$q)
```

Expand All @@ -254,7 +254,9 @@ current +
geom_rect(xmin = bbox$p[1], xmax = bbox$q[1],
ymin = bbox$p[2], ymax = bbox$q[2],
fill = NA, color = "black")
```

```{r}
sim$sample_cells("S_2_2", bbox$p, bbox$q)
```

Expand All @@ -277,13 +279,19 @@ plot_forest(forest) %>%
unlink(sim$get_name(), recursive = TRUE)
```

## Example with two populations
## Two populations with epigenetic state

We are now ready to simulate a model with epigenetic
switches and subclonal expansions.

We can now simulate a rather more complex model, with epigenetic
switches and subclonal expansions
```{r echo=FALSE, results='hide', message=FALSE, warning=FALSE}
unlink("Two Populations", recursive = TRUE)
```

```{r, fig.height=4, fig.width=3}
sim <- new(Simulation, "TwoClones")
sim <- new(Simulation, "Two Populations")
sim$death_activation_level <- 20
# First clone
sim$add_genotype(name = "A",
Expand All @@ -310,7 +318,9 @@ sim$sample_cells("B1",
top_right = c(500 + bbox_width, 500 + bbox_width))
plot_tissue(sim, num_of_bins = 500)
```

```{r, fig.height=4, fig.width=3}
# Let it grow a bit more
sim$run_up_to_time(sim$get_clock() + 15)
Expand Down Expand Up @@ -368,11 +378,14 @@ visualisation.
We build a tumour with three populations, branching.

```{r echo=FALSE, results='hide', message=FALSE, warning=FALSE}
unlink("bbox_sampler_test", recursive = TRUE)
unlink("Three Populations", recursive = TRUE)
```

```{r}
sim <- new(Simulation, "bbox_sampler_test", 1234)
```{r, fig.height=4, fig.width=3}
sim <- new(Simulation, "Three Populations")
sim$death_activation_level <- 20
sim$update_tissue(250, 250)
sim$add_genotype(name = "A", growth_rates = 0.08, death_rates = 0.01)
Expand All @@ -393,10 +406,13 @@ n_w <- n_h <- 7
bbox <- bbox_sampler(sim, "A", ncells, n_w, n_h)
sim$sample_cells("A1", bbox$p, bbox$q)
bbox <- bbox_sampler(sim, "A", ncells, n_w, n_h)
sim$sample_cells("B1", bbox$p, bbox$q)
bbox2 <- bbox_sampler(sim, "A", ncells, n_w, n_h)
sim$sample_cells("B1", bbox2$p, bbox2$q)
plot_tissue(sim)
```

```{r, fig.height=4, fig.width=3, eval=FALSE}
plot_muller(sim)
```

Expand Down Expand Up @@ -429,7 +445,7 @@ Finally, a third clone branching from `A`.

```{r, fig.height=4, fig.width=3}
# New subclone
sim$add_genotype(name = "C", growth_rates = 0.24, death_rates = 0.01)
sim$add_genotype(name = "C", growth_rates = 0.6, death_rates = 0.01)
sim$mutate_progeny(sim$choose_cell_in("A"), "C")
sim$run_up_to_size("C", 500)
Expand Down

0 comments on commit 1ace457

Please sign in to comment.