Plot Marginals of Variant Allele Frequency (VAF)
Source:R/plot_vaf_marginals.R
plot_VAF_marginals.Rd
This function generates scatter plots showing the marginal distributions of Variant Allele Frequency (VAF) for pairs of samples on a specific chromosome.
Usage
plot_VAF_marginals(
seq_result,
chromosomes = NULL,
samples = NULL,
labels = NULL,
cuts = c(0, 1)
)
Arguments
- seq_result
A data frame containing sequencing results in wide format.
- samples
A character vector specifying the sample names to include in the plot. (default: NULL. It includes all samples except the "normal_sample").
- cuts
A numeric vector specifying the range of VAF values to include in the plot (default:
c(0, 1)
).- chromosome
A character specifying the chromosome to analyze (default: all the chromosomes in
seq_res
).- colour_by
A character indicating whether to color the scatter points by "causes" or "classes" (default: "causes").
Examples
# set the seed of the random number generator
set.seed(0)
sim <- SpatialSimulation()
sim$add_mutant(name = "A",
growth_rates = 0.1,
death_rates = 0.0)
sim$place_cell("A", 500, 500)
sim$run_up_to_time(100)
#>
[████████████████████████████████████████] 100% [00m:00s] Saving snapshot
# sampling tissue
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("SampleA", bbox$lower_corner, bbox$upper_corner)
# adding second mutant
sim$add_mutant(name = "B",
growth_rates = 0.3,
death_rates = 0.0)
sim$mutate_progeny(sim$choose_cell_in("A"), "B")
sim$run_up_to_time(300)
#>
[████████████████████████████████████████] 100% [00m:00s] Saving snapshot
# sampling tissue again
bbox <- sim$search_sample(c("B" = ncells), n_w, n_h)
sim$sample_cells("SampleB", bbox$lower_corner, bbox$upper_corner)
forest <- sim$get_samples_forest()
# placing mutations
m_engine <- MutationEngine(setup_code = "demo")
#> Downloading reference genome...
#> Reference genome downloaded
#> Decompressing reference file...done
#> Downloading SBS file...
#> SBS file downloaded
#> Downloading indel file...
#> indel file downloaded
#> Downloading driver mutation file...
#> Driver mutation file downloaded
#> Downloading passenger CNAs file...
#> Passenger CNAs file downloaded
#> Downloading germline mutations...
#> Germline mutations downloaded
#> Building context index...
#>
[█---------------------------------------] 0% [00m:00s] Processing chr. 22
[█████████████████-----------------------] 40% [00m:01s] Processing chr. 22
[█████████████████████████████████-------] 81% [00m:02s] Processing chr. 22
[████████████████████████████████████████] 100% [00m:02s] Context index built
#>
[█---------------------------------------] 0% [00m:00s] Saving context index
[████████████████████████████████████████] 100% [00m:00s] Context index saved
#> done
#> Building repeated sequence index...
#>
[█---------------------------------------] 0% [00m:00s] Processing chr. 22
[█---------------------------------------] 0% [00m:00s] Processing chr. 22
[█---------------------------------------] 0% [00m:03s] Processing chr. 22
[█---------------------------------------] 0% [00m:04s] Processing chr. 22
[█---------------------------------------] 0% [00m:06s] Processing chr. 22
[█---------------------------------------] 0% [00m:07s] Processing chr. 22
[█---------------------------------------] 0% [00m:08s] Processing chr. 22
[█---------------------------------------] 0% [00m:12s] Processing chr. 22
[████████████████████████████████████████] 100% [00m:12s] RS index built
#>
[█---------------------------------------] 0% [00m:00s] Saving RS index
[█---------------------------------------] 0% [00m:01s] Saving RS index
[██████████████████████████--------------] 64% [00m:02s] Saving RS index
done
#>
[████████████████████████████████████████] 100% [00m:02s] RS index saved
#>
[█---------------------------------------] 0% [00m:00s] Loading germline
[████████████████████████████████████████] 100% [00m:00s] Germline loaded
#>
[█---------------------------------------] 0% [00m:00s] Saving germline
[████████████████████████████████████████] 100% [00m:00s] Germline saved
m_engine$add_mutant(mutant_name="A", passenger_rates=c(SNV=5e-8))
#>
[█---------------------------------------] 0% [00m:00s] Retrieving "A" SNVs
[████████████████████████████████████████] 100% [00m:00s] "A" SNVs retrieved
m_engine$add_mutant(mutant_name="B", passenger_rates=c(SNV=5e-9))
#>
[█---------------------------------------] 0% [00m:00s] Retrieving "B" SNVs
[████████████████████████████████████████] 100% [00m:00s] "B" SNVs retrieved
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
# simulating sequencing without the normal sample
seq_results <- simulate_seq(phylo_forest, coverage = 10, write_SAM = F,
with_normal_sample = FALSE)
#>
[█---------------------------------------] 0% [00m:00s] Found 22
[█---------------------------------------] 0% [00m:00s] Reading 22
[█---------------------------------------] 0% [00m:00s] Reading 22
[█---------------------------------------] 0% [00m:01s] Processing chr. 22
[█---------------------------------------] 0% [00m:01s] Processing chr. 22
[█---------------------------------------] 1% [00m:02s] Processing chr. 22
[██--------------------------------------] 3% [00m:03s] Processing chr. 22
[███-------------------------------------] 5% [00m:04s] Processing chr. 22
[███-------------------------------------] 6% [00m:06s] Processing chr. 22
[████------------------------------------] 8% [00m:07s] Processing chr. 22
[█████-----------------------------------] 10% [00m:08s] Processing chr. 22
[█████-----------------------------------] 12% [00m:09s] Processing chr. 22
[██████----------------------------------] 14% [00m:10s] Processing chr. 22
[███████---------------------------------] 15% [00m:11s] Processing chr. 22
[███████---------------------------------] 17% [00m:12s] Processing chr. 22
[████████--------------------------------] 19% [00m:13s] Processing chr. 22
[█████████-------------------------------] 21% [00m:14s] Processing chr. 22
[██████████------------------------------] 23% [00m:15s] Processing chr. 22
[██████████------------------------------] 24% [00m:16s] Processing chr. 22
[███████████-----------------------------] 26% [00m:17s] Processing chr. 22
[████████████----------------------------] 28% [00m:18s] Processing chr. 22
[█████████████---------------------------] 30% [00m:19s] Processing chr. 22
[█████████████---------------------------] 32% [00m:20s] Processing chr. 22
[██████████████--------------------------] 33% [00m:21s] Processing chr. 22
[███████████████-------------------------] 35% [00m:22s] Processing chr. 22
[███████████████-------------------------] 37% [00m:23s] Processing chr. 22
[████████████████------------------------] 39% [00m:24s] Processing chr. 22
[█████████████████-----------------------] 40% [00m:25s] Processing chr. 22
[█████████████████-----------------------] 42% [00m:26s] Processing chr. 22
[██████████████████----------------------] 44% [00m:27s] Processing chr. 22
[███████████████████---------------------] 45% [00m:28s] Processing chr. 22
[███████████████████---------------------] 47% [00m:29s] Processing chr. 22
[████████████████████--------------------] 49% [00m:30s] Processing chr. 22
[█████████████████████-------------------] 51% [00m:31s] Processing chr. 22
[█████████████████████-------------------] 52% [00m:32s] Processing chr. 22
[██████████████████████------------------] 54% [00m:33s] Processing chr. 22
[███████████████████████-----------------] 55% [00m:34s] Processing chr. 22
[███████████████████████-----------------] 57% [00m:35s] Processing chr. 22
[████████████████████████----------------] 58% [00m:36s] Processing chr. 22
[█████████████████████████---------------] 60% [00m:37s] Processing chr. 22
[█████████████████████████---------------] 62% [00m:38s] Processing chr. 22
[██████████████████████████--------------] 64% [00m:39s] Processing chr. 22
[███████████████████████████-------------] 65% [00m:40s] Processing chr. 22
[███████████████████████████-------------] 67% [00m:41s] Processing chr. 22
[████████████████████████████------------] 69% [00m:42s] Processing chr. 22
[█████████████████████████████-----------] 71% [00m:43s] Processing chr. 22
[██████████████████████████████----------] 73% [00m:44s] Processing chr. 22
[██████████████████████████████----------] 74% [00m:45s] Processing chr. 22
[███████████████████████████████---------] 76% [00m:46s] Processing chr. 22
[████████████████████████████████--------] 78% [00m:47s] Processing chr. 22
[█████████████████████████████████-------] 80% [00m:48s] Processing chr. 22
[█████████████████████████████████-------] 81% [00m:49s] Processing chr. 22
[██████████████████████████████████------] 83% [00m:50s] Processing chr. 22
[███████████████████████████████████-----] 85% [00m:51s] Processing chr. 22
[███████████████████████████████████-----] 87% [00m:52s] Processing chr. 22
[████████████████████████████████████----] 88% [00m:53s] Processing chr. 22
[█████████████████████████████████████---] 90% [00m:54s] Processing chr. 22
[█████████████████████████████████████---] 92% [00m:55s] Processing chr. 22
[██████████████████████████████████████--] 94% [00m:56s] Processing chr. 22
[███████████████████████████████████████-] 96% [00m:57s] Processing chr. 22
[███████████████████████████████████████-] 97% [00m:58s] Processing chr. 22
[████████████████████████████████████████] 99% [00m:59s] Processing chr. 22
[████████████████████████████████████████] 100% [01m:00s] Reads simulated
library(dplyr)
# filter germinal mutations
f_seq <- seq_results$mutations %>% filter(classes!="germinal")
# plotting the VAR marginals
plot_VAF_marginals(f_seq)
#> [[1]]
#>
# plotting the VAF marginals and labelling it
plot_VAF_marginals(f_seq, labels = f_seq["causes"])
#> [[1]]
#>
# deleting the mutation engine directory
unlink('demo', recursive = T)