Skip to contents

This function plots the genome-wide B-Allele Frequency (BAF) of a specific sample.

Usage

plot_BAF(seq_result, sample, chromosomes = NULL, cuts = c(0, 1), N = 5000)

Arguments

seq_result

A data frame containing sequencing results.

sample

The name of the sample for which the plot will be generated.

chromosomes

A character vector specifying the chromosomes to include in the plot (default: NULL, i.e., all the chromosomes).

cuts

A numeric vector specifying the range of BAF values to include in the plot (default: c(0, 1)).

N

The number of mutations to sample for plotting (default: 5000).

Value

A ggplot2 object showing the BAF distribution across the genome.

See also

Examples

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

sim <- TissueSimulation()
sim$add_mutant(name = "A",
               growth_rates = 0.2,
               death_rates = 0.0)
sim$place_cell("A", 500, 500)
sim$run_up_to_time(100)
#> 
 [████████████████████████████████████████] 100% [00m:00s] Saving snapshot                         


n_w <- n_h <- 10
ncells <- 0.8 * n_w * n_h
bbox <- sim$search_sample(c("A" = ncells), n_w, n_h)

sim$sample_cells("Sample", bbox$lower_corner, bbox$upper_corner)

forest <- sim$get_sample_forest()
m_engine <- MutationEngine(setup_code = "demo")
#> 
 [█---------------------------------------] 0% [00m:00s] Loading context index                     

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

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

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

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

 [██████████████████████████████████████--] 94% [00m:03s] Loading RS index                         

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

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

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


m_engine$add_mutant(mutant_name="A", passenger_rates=c(SNV=5e-8))
#> 
 [█---------------------------------------] 0% [00m:00s] Retrieving "A" SIDs                       

 [████████████████████████████████████████] 100% [00m:00s] "A"'s SIDs validated                    

m_engine$add_exposure(c(SBS1 = 0.2, SBS5 = 0.8))

phylo_forest <- m_engine$place_mutations(forest, 10, 10)
#> 
 [█---------------------------------------] 0% [00m:00s] Placing mutations                         

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


seq_results <- simulate_seq(
  phylo_forest,
  chromosomes = c('22'),
  coverage = 10,
  write_SAM = F
)
#> 
 [█---------------------------------------] 0% [00m:00s] Processing chr. 22                        

 [█---------------------------------------] 2% [00m:00s] Processing chr. 22                        

 [███-------------------------------------] 6% [00m:01s] Processing chr. 22                        

 [█████-----------------------------------] 11% [00m:02s] Processing chr. 22                       

 [███████---------------------------------] 16% [00m:03s] Processing chr. 22                       

 [█████████-------------------------------] 21% [00m:04s] Processing chr. 22                       

 [███████████-----------------------------] 26% [00m:05s] Processing chr. 22                       

 [█████████████---------------------------] 31% [00m:06s] Processing chr. 22                       

 [███████████████-------------------------] 36% [00m:07s] Processing chr. 22                       

 [█████████████████-----------------------] 41% [00m:08s] Processing chr. 22                       

 [███████████████████---------------------] 46% [00m:09s] Processing chr. 22                       

 [█████████████████████-------------------] 50% [00m:10s] Processing chr. 22                       

 [███████████████████████-----------------] 55% [00m:11s] Processing chr. 22                       

 [█████████████████████████---------------] 60% [00m:12s] Processing chr. 22                       

 [██████████████████████████--------------] 64% [00m:13s] Processing chr. 22                       

 [████████████████████████████------------] 68% [00m:14s] Processing chr. 22                       

 [██████████████████████████████----------] 73% [00m:15s] Processing chr. 22                       

 [████████████████████████████████--------] 78% [00m:16s] Processing chr. 22                       

 [██████████████████████████████████------] 83% [00m:17s] Processing chr. 22                       

 [████████████████████████████████████----] 88% [00m:18s] Processing chr. 22                       

 [██████████████████████████████████████--] 93% [00m:19s] Processing chr. 22                       

 [███████████████████████████████████████-] 97% [00m:20s] Processing chr. 22                       

 [████████████████████████████████████████] 98% [00m:21s] Processing chr. 22                       

 [████████████████████████████████████████] 98% [00m:22s] Processing chr. 22                       

 [████████████████████████████████████████] 99% [00m:23s] Processing chr. 22                       

 [████████████████████████████████████████] 99% [00m:24s] Processing chr. 22                       

 [████████████████████████████████████████] 99% [00m:25s] Processing chr. 22                       

 [████████████████████████████████████████] 99% [00m:26s] Processing chr. 22                       

 [████████████████████████████████████████] 99% [00m:27s] Processing chr. 22                       

 [████████████████████████████████████████] 99% [00m:28s] Processing chr. 22                       

 [████████████████████████████████████████] 99% [00m:29s] Processing chr. 22                       

 [████████████████████████████████████████] 99% [00m:30s] Processing chr. 22                       

 [████████████████████████████████████████] 99% [00m:31s] Processing chr. 22                       

 [████████████████████████████████████████] 99% [00m:32s] Processing chr. 22                       

 [████████████████████████████████████████] 99% [00m:33s] Processing chr. 22                       

 [████████████████████████████████████████] 99% [00m:34s] Processing chr. 22                       

 [████████████████████████████████████████] 99% [00m:35s] Processing chr. 22                       

 [████████████████████████████████████████] 99% [00m:36s] Processing chr. 22                       

 [████████████████████████████████████████] 99% [00m:37s] Processing chr. 22                       

 [████████████████████████████████████████] 99% [00m:38s] Processing chr. 22                       

 [████████████████████████████████████████] 99% [00m:39s] Processing chr. 22                       

 [████████████████████████████████████████] 99% [00m:40s] Processing chr. 22                       

 [████████████████████████████████████████] 100% [00m:41s] Reads simulated                         


library(dplyr)

# filter germinal mutations
f_seq <- seq_results$mutations %>% filter(classes!="germinal")

plot_BAF(f_seq, sample="Sample")


unlink('demo', recursive = T)