Skip to content

Commit

Permalink
Final version of SPN01
Browse files Browse the repository at this point in the history
  • Loading branch information
giorgiagandolfi committed Dec 16, 2024
1 parent b88b96c commit c54cf49
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 72 deletions.
117 changes: 59 additions & 58 deletions SPN01/0_sim_tissue.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ library(rRACES)
library(dplyr)
library(patchwork)
library(ggplot2)
library(english)
library(cli)
library(ggrepel)
library(ggpubr)
source("/orfeo/cephfs/scratch/cdslab/ggandolfi/prj_races/rRACES-examples/plotting/spn_blueprint/plot_tissue_dynamics.R")
#library(english)
#library(cli)
#library(ggrepel)
#library(ggpubr)
#source("/orfeo/cephfs/scratch/cdslab/ggandolfi/prj_races/rRACES-examples/plotting/spn_blueprint/plot_tissue_dynamics.R")
#source("/orfeo/cephfs/scratch/cdslab/ggandolfi/prj_races/rRACES-examples/SPN02/plotting_sampling.R")

dir <- getwd()
print(dir)
set.seed(12345)
sim <- SpatialSimulation(name = 'SPN01', seed = 12345)
tissue_size <- sim$get_tissue_size()
Expand Down Expand Up @@ -95,15 +96,15 @@ muller <- plot_muller(sim)
print("End simulation")

### Table with info ###
data_final <- inner_join(sim$get_species(),sim$get_counts(),by=c("mutant","epistate")) %>%
#mutate(percetage=counts/sum(counts)*100) %>%
select(c("mutant","epistate","growth_rate","death_rate","overall"))
tbl <- ggtexttable(data_final, rows = NULL, theme = ttheme("blank",base_size = 8)) %>%
tab_add_hline(at.row = 1:2, row.side = "top", linewidth = 2) %>%
tab_add_hline(at.row = 5, row.side = "bottom", linewidth = 3, linetype = 1) %>%
tab_add_footnote(text = "*Values referring to end of simulation", size = 8, face = "italic")

print("Table written")
#data_final <- inner_join(sim$get_species(),sim$get_counts(),by=c("mutant","epistate")) %>%
# #mutate(percetage=counts/sum(counts)*100) %>%
# select(c("mutant","epistate","growth_rate","death_rate","overall"))
#tbl <- ggtexttable(data_final, rows = NULL, theme = ttheme("blank",base_size = 8)) %>%
# tab_add_hline(at.row = 1:2, row.side = "top", linewidth = 2) %>%
# tab_add_hline(at.row = 5, row.side = "bottom", linewidth = 3, linetype = 1) %>%
# tab_add_footnote(text = "*Values referring to end of simulation", size = 8, face = "italic")
#
#print("Table written")
### Sampling ###

bboxC <- sim$search_sample(c("Clone 4"= 1000),50, 50)
Expand Down Expand Up @@ -145,47 +146,47 @@ timing = list("T1" = s)

# Forest
forest <- sim$get_samples_forest()
forest$save("data/samples_forest_1.sff")

plt_forest <- plot_forest(forest) %>%
annotate_forest(forest)+
theme(legend.position = "none")
piechart <- plot_state(sim)+theme(legend.position = "none")
timeseries <- plot_timeseries(sim)+
CNAqc:::my_ggplot_theme()+
theme(legend.position = "none")

tissue_plots <- list(t1,t2,t3,t4,t5,t6)
state_plots <- list(s1,s2,s3,s4,s5,s6)
plot_tissue_dynamics <- plot_tissue_dynamics(tissue_plots,state_plots,SPN_id="SPN01")
muller <- plot_muller(sim)+
CNAqc:::my_ggplot_theme()+
theme(legend.position = "none")
saveRDS(muller,"muller_plot.rds")
page1.1_layout <- "AAAAA\nAAAAA\nAAAAA\nBBBBB\nBBBBB\nCCCDD"
page1.2_layout <- "AAAAA\nBBBBB\nCCCCC\nCCCCC\nCCCCC\nCCCCC"
part1 <-plot_tissue_dynamics # ggplot()
part2 <- ggplot()
part3 <- ggplot()
part4 <- ggplot()
part5 <- ggplot()
### Table with info ###
#data_final <- inner_join(sim$get_species(),sim$get_counts(),by=c("mutant","epistate")) %>%
# mutate(percetage=counts/sum(counts)*100)
#tbl <- ggtexttable(data_final, rows = NULL, theme = ttheme("blank",base_size = 8)) %>%
# tab_add_hline(at.row = 1:2, row.side = "top", linewidth = 2) %>%
# tab_add_hline(at.row = 5, row.side = "bottom", linewidth = 3, linetype = 1) %>%
# tab_add_footnote(text = "*Values referring to end of simulation", size = 8, face = "italic")
page1.1 <- wrap_plots(list(plot_tissue_dynamics,muller,tbl,timeseries),design = page1.1_layout)+
patchwork::plot_annotation(title= "SPN01 final report",subtitle = "Tissue dynamics")
data_info_samples <- sim$get_samples_info()
tbl_sample <- ggtexttable(data_info_samples, rows = NULL, theme = ttheme("blank",base_size = 8)) %>%
tab_add_hline(at.row = 1:2, row.side = "top", linewidth = 2) %>%
tab_add_hline(at.row = 4, row.side = "bottom", linewidth = 3, linetype = 1)
ggsave("plot_forest.pdf",plt_forest,width = 250, height = 320, units = "mm", dpi = 300)
#page1.2 <- wrap_plots(list(sampling_plot,tbl_sample,plt_forest),design = page1.2_layout)+
# patchwork::plot_annotation(title= "SPN01 final report",subtitle = "Tissue dynamics")
saveRDS(page1.1,"page1.1.rds")
#saveRDS(page1.2,"page1.2.rds")
ggsave("page1.1.pdf",plot=page1.1,width = 250, height = 320, units = "mm", dpi = 300)
#ggsave("page1.2.pdf",plot=page1.2,width = 250, height = 320, units = "mm", dpi = 300)
forest$save("data/samples_forest_singularity.sff")

#plt_forest <- plot_forest(forest) %>%
# annotate_forest(forest)+
# theme(legend.position = "none")
#piechart <- plot_state(sim)+theme(legend.position = "none")
#timeseries <- plot_timeseries(sim)+
# CNAqc:::my_ggplot_theme()+
# theme(legend.position = "none")
#
#tissue_plots <- list(t1,t2,t3,t4,t5,t6)
#state_plots <- list(s1,s2,s3,s4,s5,s6)
#plot_tissue_dynamics <- plot_tissue_dynamics(tissue_plots,state_plots,SPN_id="SPN01")
#muller <- plot_muller(sim)+
# CNAqc:::my_ggplot_theme()+
# theme(legend.position = "none")
#saveRDS(muller,"muller_plot.rds")
#page1.1_layout <- "AAAAA\nAAAAA\nAAAAA\nBBBBB\nBBBBB\nCCCDD"
#page1.2_layout <- "AAAAA\nBBBBB\nCCCCC\nCCCCC\nCCCCC\nCCCCC"
#part1 <-plot_tissue_dynamics # ggplot()
#part2 <- ggplot()
#part3 <- ggplot()
#part4 <- ggplot()
#part5 <- ggplot()
#### Table with info ###
##data_final <- inner_join(sim$get_species(),sim$get_counts(),by=c("mutant","epistate")) %>%
## mutate(percetage=counts/sum(counts)*100)
##tbl <- ggtexttable(data_final, rows = NULL, theme = ttheme("blank",base_size = 8)) %>%
## tab_add_hline(at.row = 1:2, row.side = "top", linewidth = 2) %>%
## tab_add_hline(at.row = 5, row.side = "bottom", linewidth = 3, linetype = 1) %>%
## tab_add_footnote(text = "*Values referring to end of simulation", size = 8, face = "italic")
#page1.1 <- wrap_plots(list(plot_tissue_dynamics,muller,tbl,timeseries),design = page1.1_layout)+
# patchwork::plot_annotation(title= "SPN01 final report",subtitle = "Tissue dynamics")
#data_info_samples <- sim$get_samples_info()
#tbl_sample <- ggtexttable(data_info_samples, rows = NULL, theme = ttheme("blank",base_size = 8)) %>%
# tab_add_hline(at.row = 1:2, row.side = "top", linewidth = 2) %>%
# tab_add_hline(at.row = 4, row.side = "bottom", linewidth = 3, linetype = 1)
#ggsave("plot_forest.pdf",plt_forest,width = 250, height = 320, units = "mm", dpi = 300)
##page1.2 <- wrap_plots(list(sampling_plot,tbl_sample,plt_forest),design = page1.2_layout)+
## patchwork::plot_annotation(title= "SPN01 final report",subtitle = "Tissue dynamics")
#saveRDS(page1.1,"page1.1.rds")
##saveRDS(page1.2,"page1.2.rds")
#ggsave("page1.1.pdf",plot=page1.1,width = 250, height = 320, units = "mm", dpi = 300)
##ggsave("page1.2.pdf",plot=page1.2,width = 250, height = 320, units = "mm", dpi = 300)
26 changes: 12 additions & 14 deletions SPN01/1_mutation_engine.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ library(rRACES)
library(dplyr)
library(patchwork)
library(ggplot2)
library(ggpubr)
library(ggrepel)
#library(ggpubr)
#library(ggrepel)
dir <- getwd()
set.seed(12345)
forest <- load_samples_forest("data/samples_forest_1.sff")
#setwd("/orfeo/cephfs/scratch/cdslab/ggandolfi/prj_races/rRACES-examples/SPN01/new_simulation/sim6")
#source("/orfeo/cephfs/scratch/cdslab/ggandolfi/prj_races/rRACES-examples/plotting/spn_blueprint/signature_palette.R")
forest <- load_samples_forest("data/samples_forest_singularity.sff")
setwd("/orfeo/scratch/cdslab/shared/races/GRCh38/")
m_engine <- MutationEngine(setup_code = "GRCh38",tumour_type = "COAD",
tumour_study = "US")
Expand All @@ -27,35 +25,35 @@ df <- df %>%
mutate(mu_SNV=c(1e-8,1e-8,1e-8,1e-8),
mu_CNA=c(0,1e-10, 1e-12, 1e-12),
mu_indels=c(0,0,0,0))
tbl <- ggtexttable(df, rows = NULL, theme = ttheme("blank",base_size = 8)) %>%
tab_add_hline(at.row = 1:2, row.side = "top", linewidth = 2) %>%
tab_add_hline(at.row = 4, row.side = "bottom", linewidth = 3, linetype = 1)
#tab_add_footnote(text = "*Values referring to end of simulation", size = 8, face = "italic")
#tbl <- ggtexttable(df, rows = NULL, theme = ttheme("blank",base_size = 8)) %>%
# tab_add_hline(at.row = 1:2, row.side = "top", linewidth = 2) %>%
# tab_add_hline(at.row = 4, row.side = "bottom", linewidth = 3, linetype = 1)
# #tab_add_footnote(text = "*Values referring to end of simulation", size = 8, face = "italic")

mu_SNV = 1e-8
mu_CNA = 1e-10
##112707518-112846239
CNA_Clone2 = rRACES::CNA(type = "D", "5",
chr_pos = 107707518, len = 1e7,allele = 0)
chr_pos = 107707518, len = 2e7,allele = 0)

## Drivers for the tumors
m_engine$add_mutant(mutant_name = "Clone 1",
passenger_rates = c(SNV = mu_SNV, CNA = 0),drivers = list(list("APC R1450*", allele = 1)))
m_engine$add_mutant(mutant_name = "Clone 2",passenger_rates = c(SNV = mu_SNV, CNA = mu_CNA),drivers = list(CNA_Clone2))
mu_SNV = 1e-8
mu_CNA = 1e-12
mu_CNA = 1e-13
m_engine$add_mutant(mutant_name = "Clone 3",passenger_rates = c(SNV = mu_SNV, CNA = mu_CNA),drivers = list("TP53 R175H"))

m_engine$add_mutant(mutant_name = "Clone 4",passenger_rates = c(SNV = mu_SNV, CNA = mu_CNA),drivers = list(WGD))


# Mutational signatures
m_engine$add_exposure(time = 0,coefficients = c(SBS1 = 0.40,SBS5 = 0.20,
SBS17a = 0.15,SBS17b = 0.15,ID1 = 0.60,ID2 = 0.40,SBS13 = 0.1))
m_engine$add_exposure(time = 0,coefficients = c(SBS1 = 0.20,SBS5 = 0.35,
SBS18 = 0.15,SBS17b = 0.25,ID1 = 0.60,ID2 = 0.40,SBS88 = 0.05))
print("Mutation engine created")
phylo_forest <- m_engine$place_mutations(forest, num_of_preneoplatic_SNVs=800, num_of_preneoplatic_indels=200)

phylo_forest$save(paste0(dir,"/","data/phylo_forest_1.sff"))
phylo_forest$save(paste0(dir,"/","data/phylo_forest_singularity.sff"))

#setwd(dir)
########### Plotting ##########
Expand Down

0 comments on commit c54cf49

Please sign in to comment.