Author: Lars Velten

# Computation of phylogenetic trees and clustering of mutations

#### Lars Velten

## Before you begin

    library(mitoClone2)

You should have identified true somatic variants in the mitochondrial (and nuclear) genome. The remaining vignettes of this package document how to get there. Here, we start with count matrices of the alternative and the reference alleles, across a number of sites of interest. Such data is available from two patients (P1, P2) as part of this package. Only P1 is analyzed as part of this vignette but the commented code for P2 should be fully functional.

    load(system.file("data/M_P1.RData", package = "mitoClone2"))
    load(system.file("data/N_P1.RData", package = "mitoClone2"))
    P1 <- mutationCallsFromMatrix(as.matrix(M_P1), as.matrix(N_P1))

A first important step is to decide which mutations to include in the clustering. The default is to use all mutations that are covered in at least 20% of the cells, but this assignment can be changed manually.

## Compute a phylogenetic tree

The next step is to run SCITE or PhISCS to compute the most likely phylogenetic tree. PhISCS is bundled in this package, but the package needs to be run in an environment where gurobi and the `gurobipy` python package are available. For example, you could set up a `conda` environment that contains this package. SCITE does not require any additional licenses but may need to be manually compiled.

    ## this next step takes approx 4.1 minutes to run
    tmpd <- tempdir()
    dir.create(paste0(tmpd, "/p1"))
    P1 <- varCluster(P1, tempfolder = paste0(tmpd, "/p1"), method = "SCITE")
    #> Warning in max(which(x == 1)): no non-missing arguments to max; returning -Inf

This step can take a while to run. It computes a likely phylogenetic tree of all the mutations. In the case of SCITE, multiple equally likely tree can be produced. In it’s current state, this package simply selects the first tree from the list.

## Identify clones and assign cells to clones

In many cases, the order of the leaves on these trees is arbitrary, because mutations systematically co-occur. We therefore cluster the mutations into clones. In detail, we take every every branch on the tree and then shuffle the order of mutations in that branch while re-calculating the likelihood. If swapping nodes leads to small changes in the likelihood, these nodes are then merged into a “clone”. The parameter `min.lik` that controls the merging is set arbitrarily, see below for more information.

    P1 <- clusterMetaclones(P1, min.lik = 1)
    #> Warning in mutcalls@mut2clone[branches[[i]]] <-
    #> as.integer(max(mutcalls@mut2clone) + : number of items to replace is not a
    #> multiple of replacement length

This step also assigns each cell to the most likely clone, and provides an estimate of the likelihood. Refer to `help(mutationCalls)` for more info on how these results are stored.

Finally, the clustering can be plotted.

    plotClones(P1)

## Parameter choice

The parameter `min.lik` that controls the merging is set arbitrarily. In practice, the goal of these analyses is to group mutations into clones for subsequent analyses (such as differential expression analyses) and it may make sense to overwrite the result of `clusterMetaclones` manually; for example, if a subclone defned on a mitochondrial mutation only should be treated as part of a more clearly defined upstream clone for differential expression analysis.

To overwrite the result of `clusterMetaclones`, first retrieve the assignment of mutations to clones:

    m2c <- mitoClone2:::getMut2Clone(P1)
    print(m2c)
    #>   X1282GA   X2537GA   X3335TC   X3350TC   X5492TC X7527GDEL   X8167TC  X11196GA
    #>         2         3         5         5         1         4         5         2
    #>  X11559GA  X14462GA  X16233AG      EAPP     SRSF2     CEBPA      KLF7      root
    #>         4         3         5         4         4         3         2         5

    ## To e.g. treat the mt:2537G>A and mt:14462:G>A mutations as a
    ## subclone distinct from CEBPA, we can assign them a new clonal
    ## identity
    m2c[c("X2537GA", "X14462GA")] <- as.integer(6)

    P1.new <- mitoClone2:::overwriteMetaclones(P1, m2c)
    plotClones(P1.new)

## Session information

    #> R version 4.6.0 Patched (2026-04-24 r89963)
    #> Platform: aarch64-apple-darwin23
    #> Running under: macOS Tahoe 26.3.1
    #>
    #> Matrix products: default
    #> BLAS:   /Library/Frameworks/R.framework/Versions/4.6/Resources/lib/libRblas.0.dylib
    #> LAPACK: /Library/Frameworks/R.framework/Versions/4.6/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1
    #>
    #> locale:
    #> [1] C/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
    #>
    #> time zone: America/New_York
    #> tzcode source: internal
    #>
    #> attached base packages:
    #> [1] stats     graphics  grDevices utils     datasets  methods   base
    #>
    #> other attached packages:
    #> [1] mitoClone2_1.18.0
    #>
    #> loaded via a namespace (and not attached):
    #>  [1] KEGGREST_1.52.0             SummarizedExperiment_1.42.0
    #>  [3] gtable_0.3.6                ggplot2_4.0.3
    #>  [5] rjson_0.2.23                xfun_0.57
    #>  [7] bslib_0.10.0                Biobase_2.72.0
    #>  [9] lattice_0.22-9              vctrs_0.7.3
    #> [11] tools_4.6.0                 bitops_1.0-9
    #> [13] generics_0.1.4              stats4_4.6.0
    #> [15] curl_7.1.0                  parallel_4.6.0
    #> [17] tibble_3.3.1                AnnotationDbi_1.74.0
    #> [19] RSQLite_2.4.6               blob_1.3.0
    #> [21] pkgconfig_2.0.3             pheatmap_1.0.13
    #> [23] Matrix_1.7-5                BSgenome_1.80.0
    #> [25] RColorBrewer_1.1-3          S7_0.2.2
    #> [27] S4Vectors_0.50.0            cigarillo_1.2.0
    #> [29] lifecycle_1.0.5             farver_2.1.2
    #> [31] compiler_4.6.0              Rsamtools_2.28.0
    #> [33] Biostrings_2.80.0           Seqinfo_1.2.0
    #> [35] codetools_0.2-20            deepSNV_1.58.0
    #> [37] htmltools_0.5.9             sass_0.4.10
    #> [39] RCurl_1.98-1.18             yaml_2.3.12
    #> [41] pillar_1.11.1               crayon_1.5.3
    #> [43] jquerylib_0.1.4             BiocParallel_1.46.0
    #> [45] DelayedArray_0.38.0         cachem_1.1.0
    #> [47] abind_1.4-8                 tidyselect_1.2.1
    #> [49] digest_0.6.39               dplyr_1.2.1
    #> [51] restfulr_0.0.16             VariantAnnotation_1.58.0
    #> [53] splines_4.6.0               fastmap_1.2.0
    #> [55] grid_4.6.0                  cli_3.6.6
    #> [57] SparseArray_1.12.0          magrittr_2.0.5
    #> [59] GenomicFeatures_1.64.0      S4Arrays_1.12.0
    #> [61] dichromat_2.0-0.1           XML_3.99-0.23
    #> [63] scales_1.4.0                bit64_4.8.0
    #> [65] rmarkdown_2.31              XVector_0.52.0
    #> [67] httr_1.4.8                  matrixStats_1.5.0
    #> [69] bit_4.6.0                   otel_0.2.0
    #> [71] png_0.1-9                   VGAM_1.1-14
    #> [73] memoise_2.0.1               evaluate_1.0.5
    #> [75] knitr_1.51                  Rhtslib_3.8.0
    #> [77] GenomicRanges_1.64.0        IRanges_2.46.0
    #> [79] BiocIO_1.22.0               rtracklayer_1.72.0
    #> [81] rlang_1.2.0                 glue_1.8.1
    #> [83] DBI_1.3.0                   formatR_1.14
    #> [85] BiocGenerics_0.58.0         jsonlite_2.0.0
    #> [87] R6_2.6.1                    MatrixGenerics_1.24.0
    #> [89] GenomicAlignments_1.48.0