Skip to contents

This methods places mutations on a samples forest.

Arguments

samples_forest

A samples forest.

num_of_preneoplatic_SNVs

The number of pre-neoplastic SNVs.

preneoplatic_SNV_signature_name

The name of the SNV signature for the preneoplastic SNV generation (optional).

num_of_preneoplatic_indels

The number of pre-neoplastic indels.

preneoplatic_indel_signature_name

The name of the indel signature for the preneoplastic indel generation.

seed

The seed for random number generator (optional).

Value

A phylogenetic forest whose structure corresponds to samples_forest.

Details

Each node of a samples forest is labelled by the mutations occuring in the cell represented by the node itself and produces a phylogenetic forest.

Examples

# set the seed of the random number generator
set.seed(0)

# create a simulation
sim <- SpatialSimulation()
sim$add_mutant("A", c(SNV = 0.2), 0.01)
sim$place_cell("A", 500, 500)

sim$death_activation_level <- 100
sim$run_up_to_size(species = "A", num_of_cells = 50000)
#> 
 [████████████████████████████████████████] 100% [00m:00s] Saving snapshot                                        


# sample the region [450,500]x[475,550]
sim$sample_cells("S1", lower_corner = c(450, 475),
                       upper_corner = c(500, 550))

# build the samples forest
samples_forest <- sim$get_samples_forest()

# build a mutation engine
m_engine <- MutationEngine(setup_code = "demo")
#> 
 [█---------------------------------------] 0% [00m:00s] Loading context index                                    

 [████████████████████████████████████████] 100% [00m:00s] Context index loaded                                   

#> 
 [█---------------------------------------] 0% [00m:00s] Loading RS index                                         

 [████████████████------------------------] 39% [00m:01s] Loading RS index                                        

 [███████████████████████████████---------] 77% [00m:02s] Loading RS index                                        

 [████████████████████████████████████████] 100% [00m:02s] RS index loaded                                        

#> 
 [█---------------------------------------] 0% [00m:00s] Loading germline                                         

 [████████████████████████████████████████] 100% [00m:00s] Germline loaded                                        


# add the mutant "A" to the engine
m_engine$add_mutant("A", c(SNV = 3e-9), list(SNV("22", 12028576, "G")))
#> 
 [█---------------------------------------] 0% [00m:00s] Retrieving "A" SNVs                                      

 [█---------------------------------------] 0% [00m:00s] Found 22                                                 

 [█---------------------------------------] 0% [00m:00s] Reading 22                                               

 [█---------------------------------------] 0% [00m:01s] Reading 22                                               

 [████████████████████████████████████████] 100% [00m:01s] "A" SNVs retrieved                                     


# add the default set of SNV signature coefficients
m_engine$add_exposure(c(SBS13 = 0.3, SBS1 = 0.7, ID2 = 0.3, ID21 = 0.5,
                        ID3 = 0.2))

# place the mutations on the samples forest assuming 1000 pre-neoplastic
# SNVs and 500 indels
phylogenetic_forest <- m_engine$place_mutations(samples_forest, 1000, 500)
#> 
 [█---------------------------------------] 0% [00m:00s] Placing mutations                                        

 [████████████████████████████████████████] 100% [00m:00s] Mutations placed                                       


phylogenetic_forest
#> PhylogeneticForest
#>   # of trees: 1
#>   # of nodes: 12077
#>   # of leaves: 3863
#>   samples: {"S1"}
#> 
#>   # of emerged SNVs and indels: 2035
#>   # of emerged CNAs: 0
#>