
1. Input data and required pre-processing
Source:vignettes/1-input-data-and-required-pre-processing.Rmd
1-input-data-and-required-pre-processing.RmdIntroduction
Understanding when and how genetic resistance to therapy emerges is a central problem in cancer genomics. With the increasing adoption of high-throughput sequencing in clinical practice, it is often possible to identify the driver event responsible for disease relapse. However, even when longitudinal data are available, their resolution is frequently too low to determine whether the resistant clone was already present before treatment onset, and was subsequently selected, or whether it emerged after treatment began. Resolving this question has direct clinical implications: patients harbouring a pre-existing resistant clone may not benefit from a given therapy, and since many treatments are themselves mutagenic, it is also important to identify cases where the treatment itself may have accelerated the emergence of resistance.
TOSCA is an R package that leverages longitudinal whole-genome sequencing (WGS) data combined with clinical information to infer, in real time, the timing of origin of clonal expansions associated with therapy resistance. TOSCA employs a Bayesian model in which mutation accumulation is described as a Poisson process, and infers the timing of events associated with changes in process intensity, along with tumour dynamic parameters such as growth rate and mutation rate under therapy.
The required inputs are:
- Clinical information: dates of longitudinal sample collection and dates of therapy administration (for therapies associated with known mutational signatures).
- Mutation information: the number of mutations private to the resistant clone, stratified by mutational signature and karyotype.
In this vignette, we walk through a complete analysis of longitudinal WGS data from a single patient with acute myeloid leukaemia (AML) who developed resistance to immunotherapy. This example is drawn from the TOSCA reference paper and illustrates how the package can be used to identify and interpret clinically relevant genomic events in a real-world setting.
New to TOSCA? The Overview vignette introduces the core idea and a glossary of terms used throughout this series.
Clinical background: patient UPN06
UPN06 is drawn from a cohort of 11 AML patients who relapsed after allogeneic haematopoietic stem cell transplantation (allo-HSCT) — a transplant of donor immune cells intended to eliminate residual leukaemia by recognising it as foreign. In the haploidentical setting used here, the donor shares only one parental HLA haplotype with the patient, so post-transplant immunity against leukaemia is skewed towards the mismatched haplotype. A well-established escape route from this immune pressure is copy-neutral loss of heterozygosity (CNLOH) of the HLA locus (chromosome 6p): the leukaemic clone deletes the mismatched HLA copy and duplicates the matched one, becoming invisible to the donor’s mismatch-directed immune response while keeping a normal (diploid, “copy-neutral”) genome.
UPN06’s specific course was: diagnosis, six cycles of cytarabine (a chemotherapy also capable of inducing tumour-cell dormancy), haploidentical allo-HSCT, and — about one month after transplant — a course of ganciclovir to control cytomegalovirus (CMV) reactivation, a common complication of transplant-induced immunosuppression. Relapse with HLA CNLOH was detected 828 days after transplant. Two clonal AML driver mutations (IDH1 p.R13, NPM1 p.W28) were identified from longitudinal WGS and are shared by both the pre-transplant and relapse samples.
The clinical question TOSCA is used to answer here: did the HLA-CNLOH clone already exist before transplant and simply get selected by immune pressure (pre-existing), or did it arise afterwards (de novo — and if so, ganciclovir, itself mutagenic, is a plausible contributor worth flagging)? We’ll come back to what TOSCA concludes once the model is fit, in vignette 4.
Data pre-processing
We begin by loading the data required for inference:
Sample collection dates
The first input records the dates of sample collection in
YYYY-mm-dd format. The date of birth is optional.
UPN06$Input$Samples
#> Name Date
#> 1 Birth 1954-01-01
#> 2 Pre-Transplant 2014-03-21
#> 3 Relapse 2016-08-11Therapy records
The second input records all therapies that are either associated
with a known mutational signature or that can induce a dormant state in
cancer cells — for instance, cytarabine in AML. Start and end dates must
follow the same YYYY-mm-dd format as sample dates. Each
therapy must be classified as one of:
- Mutagenic: associated with a known SBS signature.
- Chemotherapy inducing dormancy: capable of inducing a dormant state in cancer cells (e.g. cytarabine in AML).
UPN06$Input$Therapies
#> Name Class Start End
#> 1 Cytarabine Chemotherapy inducing dormancy 2012-02-01 2013-12-01
#> 2 Ganciclovir Mutagenic 2014-05-19 2014-06-25Clonal mutations
Before listing what this input contains, it helps to see where its mutations actually sit. TOSCA times events on a single phylogenetic branch: the one connecting the Early Common Ancestor (ECA) — the cell that acquired the first mutation private to this branch — to the Most Recent Common Ancestor (MRCA) of the relapse sample. Everything TOSCA infers (the timing of the resistant clone, the growth rate, the mutation rates) concerns this branch and the mutations that accumulated along it.

The ECA→MRCA branch (highlighted), with the therapy window acting
as an evolutionary bottleneck. Mutation counts along this branch — split
by mutational process, shown as the two rows below the phylogeny — are
what the Mutations table below encodes as counts rather
than a full phylogeny. Figure adapted from the TOSCA manuscript (in
preparation).
The third input contains mutations located on this branch. Constructing it requires two upstream analyses to have been completed:
- Clonal deconvolution to reconstruct the bulk phylogeny and assign mutations to branches (e.g. MOBSTER).
- Signature deconvolution to attribute mutations on each branch to SBS signatures (e.g. SigProfiler, SparseSignatures, BASCULE).
TOSCA requires the private mutations of each longitudinal sample, stratified by signature. Specifically:
- Clock-like primary: diploid private mutations of the first sample attributed to clock-like signatures (SBS1 and SBS5).
- Clock-like relapse: diploid private mutations of the second sample attributed to clock-like signatures.
- Treatment-associated relapse: diploid private mutations of the second sample attributed to the therapy-associated signature (named after the drug).
-
CNA-associated mutations (optional, for resistances
mediated by a CNA event):
- Alpha: mutations present in double copy on the CNA.
- Beta: mutations present in single copy on the CNA.
UPN06$Input$Mutations
#> Name Length Karyotype Type Value
#> 1 m_clock_primary 2780524307 1:1 clock-like primary 0
#> 2 m_clock 2780524307 1:1 clock-like relapse 841
#> 3 m_cyt 2780524307 1:1 Cytarabine 0
#> 4 m_gcv 2780524307 1:1 Ganciclovir 1347
#> 5 alpha 47911693 2:0 alpha 20
#> 6 beta 47911693 2:0 beta 1Parameters
Once all inputs are prepared, the TOSCA object is initialised with a single call. All subsequent analyses operate on this object.
x <- TOSCA::init(
samples = UPN06$Input$Samples,
therapies = UPN06$Input$Therapies,
mutations = UPN06$Input$Mutations,
parameters = UPN06$Input$Parameters,
sample_name = "UPN06"
)
#> Warning in check_genomic_input(mutations): Non-standard mutation type(s):
#> Cytarabine , Ganciclovir. If therapy-associated, ensure the name matches the
#> corresponding entry in the Therapies dataframe. Valid reserved types:
#> clock-like primary , clock-like relapse , alpha , beta , driver
x
#> ──
#>
#> ** TOSCA ** Sample: UPN06 ────────────────────────────────────────────────
#>
#> ── Clinical History (~ 2 years, 4 months and 24 days)
#> ── Pre-Transplant (2014-03-21) --> Cytarabine (669 days) --> Ganciclovir (37 day
#>
#> ── Timed events: 1 CNAs with dormancy without Drivers altering the mutation rate
#>
#> ── Inference results
#> [1] "Fit not available"The warning above is expected. TOSCA flags any mutation type name
that does not match the reserved keywords
(clock-like primary, clock-like relapse,
alpha, beta, driver) to guard
against accidental mismatches between the Mutations and
Therapies dataframes. Here, Cytarabine and
Ganciclovir are intentional: they correspond to
therapy-associated mutational processes and their names match exactly
the entries in UPN06$Input$Therapies, which is all that is
required for the inference to proceed correctly.
The inference results slot is empty until the model is fit, as shown in the next section.