vignettes/cnsignature.Rmd
cnsignature.RmdExploring copy number signatures with recently developed approach have been described at The repertoire of copy number alteration signatures in human cancer.
A more general introduction please read Extract, Analyze and Visualize Mutational Signatures with Sigminer.
library(sigminer)
#> Registered S3 method overwritten by 'sigminer':
#> method from
#> print.bytes Rcpp
#> sigminer version 2.3.3
#> - Star me at https://github.com/ShixiangWang/sigminer
#> - Run hello() to see usage and citation.For this analysis, data with six columns are required.
load(system.file("extdata", "toy_segTab.RData",
package = "sigminer", mustWork = TRUE
))
set.seed(1234)
segTabs$minor_cn <- sample(c(0, 1), size = nrow(segTabs), replace = TRUE)
cn <- read_copynumber(segTabs,
seg_cols = c("chromosome", "start", "end", "segVal"),
genome_measure = "wg", complement = TRUE, add_loh = TRUE
)
#> ℹ [2026-10-15 07:30:09.967581]: Started.
#> ℹ [2026-10-15 07:30:09.978803]: Genome build : hg19.
#> ℹ [2026-10-15 07:30:09.987098]: Genome measure: wg.
#> ℹ [2026-10-15 07:30:09.988798]: When add_loh is TRUE, use_all is forced to TRUE.
#> Please drop columns you don't want to keep before reading.
#> ✔ [2026-10-15 07:30:10.001081]: Chromosome size database for build obtained.
#> ℹ [2026-10-15 07:30:10.002929]: Reading input.
#> ✔ [2026-10-15 07:30:10.004702]: A data frame as input detected.
#> ✔ [2026-10-15 07:30:10.006746]: Column names checked.
#> ✔ [2026-10-15 07:30:10.008919]: Column order set.
#> ✔ [2026-10-15 07:30:10.017236]: Chromosomes unified.
#> ✔ [2026-10-15 07:30:10.040232]: Value 2 (normal copy) filled to uncalled chromosomes.
#> ✔ [2026-10-15 07:30:10.046217]: Data imported.
#> ℹ [2026-10-15 07:30:10.048151]: Segments info:
#> ℹ [2026-10-15 07:30:10.049912]: Keep - 477
#> ℹ [2026-10-15 07:30:10.051671]: Drop - 0
#> ✔ [2026-10-15 07:30:10.054228]: Segments sorted.
#> ℹ [2026-10-15 07:30:10.056]: Adding LOH labels...
#> ℹ [2026-10-15 07:30:10.059026]: Joining adjacent segments with same copy number value. Be patient...
#> ✔ [2026-10-15 07:30:10.270606]: 410 segments left after joining.
#> ✔ [2026-10-15 07:30:10.272871]: Segmental table cleaned.
#> ℹ [2026-10-15 07:30:10.274536]: Annotating.
#> ✔ [2026-10-15 07:30:10.291356]: Annotation done.
#> ℹ [2026-10-15 07:30:10.293092]: Summarizing per sample.
#> ✔ [2026-10-15 07:30:10.314581]: Summarized.
#> ℹ [2026-10-15 07:30:10.316304]: Generating CopyNumber object.
#> ✔ [2026-10-15 07:30:10.318678]: Generated.
#> ℹ [2026-10-15 07:30:10.320418]: Validating object.
#> ✔ [2026-10-15 07:30:10.32219]: Done.
#> ℹ [2026-10-15 07:30:10.324151]: 0.357 secs elapsed.
cn
#> An object of class CopyNumber
#> =============================
#> sample n_of_seg n_of_cnv n_of_amp n_of_del n_of_vchr
#> <char> <int> <int> <int> <int> <int>
#> 1: TCGA-DF-A2KN-01A-11D-A17U-01 34 6 5 1 4
#> 2: TCGA-19-2621-01B-01D-0911-01 34 8 5 3 5
#> 3: TCGA-B6-A0X5-01A-21D-A107-01 29 8 4 4 2
#> 4: TCGA-A8-A07S-01A-11D-A036-01 39 11 2 9 4
#> 5: TCGA-26-6174-01A-21D-1842-01 44 13 8 5 8
#> 6: TCGA-CV-7432-01A-11D-2128-01 41 16 7 9 9
#> 7: TCGA-06-0644-01A-02D-0310-01 47 19 5 14 8
#> 8: TCGA-A5-A0G2-01A-11D-A042-01 40 21 5 16 10
#> 9: TCGA-99-7458-01A-11D-2035-01 49 26 10 16 13
#> 10: TCGA-05-4417-01A-22D-1854-01 53 37 33 4 17
#> n_loh cna_burden
#> <int> <num>
#> 1: 15 0.000
#> 2: 20 0.095
#> 3: 18 0.083
#> 4: 21 0.106
#> 5: 24 0.113
#> 6: 24 0.188
#> 7: 33 0.158
#> 8: 23 0.375
#> 9: 33 0.304
#> 10: 29 0.617
cn@data
#> chromosome start end segVal sample
#> <char> <num> <num> <int> <char>
#> 1: chr1 3218923 116319008 2 TCGA-05-4417-01A-22D-1854-01
#> 2: chr1 116324707 120523902 1 TCGA-05-4417-01A-22D-1854-01
#> 3: chr1 149879545 247812431 4 TCGA-05-4417-01A-22D-1854-01
#> 4: chr10 423671 135224372 3 TCGA-05-4417-01A-22D-1854-01
#> 5: chr11 458784 19461653 3 TCGA-05-4417-01A-22D-1854-01
#> ---
#> 406: chr6 1016984 170898549 2 TCGA-DF-A2KN-01A-11D-A17U-01
#> 407: chr7 746917 158385118 2 TCGA-DF-A2KN-01A-11D-A17U-01
#> 408: chr8 617885 145225107 2 TCGA-DF-A2KN-01A-11D-A17U-01
#> 409: chr9 790234 140938075 2 TCGA-DF-A2KN-01A-11D-A17U-01
#> 410: chrX 1 155270560 2 TCGA-DF-A2KN-01A-11D-A17U-01
#> minor_cn loh .loh_frac
#> <num> <lgcl> <num>
#> 1: 1.0000000 FALSE NA
#> 2: 0.0000000 TRUE NA
#> 3: 0.5000000 TRUE 0.1175943
#> 4: 1.0000000 FALSE NA
#> 5: 1.0000000 FALSE NA
#> ---
#> 406: 0.3333333 TRUE 0.9979494
#> 407: 1.0000000 FALSE NA
#> 408: 1.0000000 FALSE NA
#> 409: 0.5000000 TRUE 0.8328715
#> 410: NA FALSE NAIf you want to try other type of copy number signatures, change the method argument.
tally_s <- sig_tally(cn, method = "S")
#> ℹ [2026-10-15 07:30:10.4605]: Started.
#> ℹ [2026-10-15 07:30:10.469496]: When you use method 'S', please make sure you have set 'join_adj_seg' to FALSE and 'add_loh' to TRUE in 'read_copynumber() in the previous step!
#> ✔ [2026-10-15 07:30:10.485608]: Matrix generated.
#> ℹ [2026-10-15 07:30:10.487417]: 0.027 secs elapsed.
str(tally_s$all_matrices, max.level = 1)
#> List of 2
#> $ CN_40: int [1:10, 1:40] 0 0 0 0 0 0 0 0 0 0 ...
#> ..- attr(*, "dimnames")=List of 2
#> $ CN_48: int [1:10, 1:48] 0 0 0 0 0 0 0 0 0 0 ...
#> ..- attr(*, "dimnames")=List of 2
sig_denovo = sig_auto_extract(tally_s$all_matrices$CN_48)
#> Select Run 3, which K = 2 as best solution.
head(sig_denovo$Signature)
#> Sig1 Sig2
#> 0:homdel:0-100Kb 0.000000 0.000000e+00
#> 0:homdel:100Kb-1Mb 0.000000 0.000000e+00
#> 0:homdel:>1Mb 0.000000 0.000000e+00
#> 1:LOH:0-100Kb 3.609460 3.819129e-242
#> 1:LOH:100Kb-1Mb 6.316554 2.814800e-127
#> 1:LOH:1Mb-10Mb 13.535473 2.784288e-190This directly calculates the contribution of 19 reference signatures.
act_refit = sig_fit(t(tally_s$all_matrices$CN_48), sig_index = "ALL", sig_db = "CNS_TCGA")
#> ℹ [2026-10-15 07:30:11.472258]: Started.
#> ✔ [2026-10-15 07:30:11.474208]: Signature index detected.
#> ℹ [2026-10-15 07:30:11.475865]: Checking signature database in package.
#> ℹ [2026-10-15 07:30:11.478379]: Checking signature index.
#> ℹ [2026-10-15 07:30:11.480053]: Valid index for db 'CNS_TCGA':
#> CN1 CN2 CN3 CN4 CN5 CN6 CN7 CN8 CN9 CN10 CN11 CN12 CN13 CN14 CN15 CN16 CN17 CN18 CN19
#> ✔ [2026-10-15 07:30:11.481779]: Database and index checked.
#> ✔ [2026-10-15 07:30:11.483694]: Signature normalized.
#> ℹ [2026-10-15 07:30:11.485346]: Checking row number for catalog matrix and signature matrix.
#> ✔ [2026-10-15 07:30:11.487005]: Checked.
#> ℹ [2026-10-15 07:30:11.4888]: Checking rownames for catalog matrix and signature matrix.
#> ✔ [2026-10-15 07:30:11.490609]: Checked.
#> ✔ [2026-10-15 07:30:11.492236]: Method 'QP' detected.
#> ✔ [2026-10-15 07:30:11.49628]: Corresponding function generated.
#> ℹ [2026-10-15 07:30:11.498028]: Calling function.
#> ℹ [2026-10-15 07:30:11.500141]: Fitting sample: TCGA-05-4417-01A-22D-1854-01
#> ℹ [2026-10-15 07:30:11.502121]: Fitting sample: TCGA-06-0644-01A-02D-0310-01
#> ℹ [2026-10-15 07:30:11.503916]: Fitting sample: TCGA-19-2621-01B-01D-0911-01
#> ℹ [2026-10-15 07:30:11.505664]: Fitting sample: TCGA-26-6174-01A-21D-1842-01
#> ℹ [2026-10-15 07:30:11.507394]: Fitting sample: TCGA-99-7458-01A-11D-2035-01
#> ℹ [2026-10-15 07:30:11.509164]: Fitting sample: TCGA-A5-A0G2-01A-11D-A042-01
#> ℹ [2026-10-15 07:30:11.510952]: Fitting sample: TCGA-A8-A07S-01A-11D-A036-01
#> ℹ [2026-10-15 07:30:11.512708]: Fitting sample: TCGA-B6-A0X5-01A-21D-A107-01
#> ℹ [2026-10-15 07:30:11.51442]: Fitting sample: TCGA-CV-7432-01A-11D-2128-01
#> ℹ [2026-10-15 07:30:11.516174]: Fitting sample: TCGA-DF-A2KN-01A-11D-A17U-01
#> ✔ [2026-10-15 07:30:11.517939]: Done.
#> ℹ [2026-10-15 07:30:11.5196]: Generating output signature exposures.
#> ✔ [2026-10-15 07:30:11.52188]: Done.
#> ℹ [2026-10-15 07:30:11.523659]: 0.051 secs elapsed.We can use some threshold to keep really contributed signautres.
For de novo signatures:
show_sig_profile(sig_denovo, mode = "copynumber", method = "S", style = "cosmic")
#> Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
#> ℹ Please use tidy evaluation idioms with `aes()`.
#> ℹ See also `vignette("ggplot2-in-packages")` for more information.
#> ℹ The deprecated feature was likely used in the sigminer package.
#> Please report the issue at <https://github.com/ShixiangWang/sigminer/issues>.
#> This warning is displayed once per session.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
#> generated.
#> Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
#> ℹ Please use the `linewidth` argument instead.
#> ℹ The deprecated feature was likely used in the sigminer package.
#> Please report the issue at <https://github.com/ShixiangWang/sigminer/issues>.
#> This warning is displayed once per session.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
#> generated.
Show the activity/exposure.
show_sig_exposure(sig_denovo)
For reference signatures, you can just select what you want:
show_sig_profile(
get_sig_db("CNS_TCGA")$db[, rownames(act_refit2)],
style = "cosmic",
mode = "copynumber", method = "S", check_sig_names = FALSE)
Similarly for showing activity.
show_sig_exposure(act_refit2)
NOTE that this case shows relatively large difference with different approaches, so you need to pick based on your data size/quality and double-check the results. In general, for small-size data set, the refitting approach is recommended.
To assign the de-novo signatures to reference signatures, we use cosine similarity.
get_sig_similarity(sig_denovo, sig_db = "CNS_TCGA")
#> -Comparing against COSMIC signatures
#> ------------------------------------
#> --Found Sig1 most similar to CN1
#> Aetiology: See https://cancer.sanger.ac.uk/signatures/cn/ [similarity: 0.706]
#> --Found Sig2 most similar to CN2
#> Aetiology: See https://cancer.sanger.ac.uk/signatures/cn/ [similarity: 0.771]
#> ------------------------------------
#> Return result invisiblely.