Read absolute copy number profile for preparing CNV signature analysis. See detail part of sig_tally() to see how to handle sex to get correct summary.

read_copynumber(
  input,
  pattern = NULL,
  ignore_case = FALSE,
  seg_cols = c("Chromosome", "Start.bp", "End.bp", "modal_cn"),
  samp_col = "sample",
  add_loh = FALSE,
  loh_min_len = 10000,
  loh_min_frac = 0.05,
  join_adj_seg = TRUE,
  skip_annotation = FALSE,
  use_all = add_loh,
  min_segnum = 0L,
  max_copynumber = 20L,
  genome_build = c("hg19", "hg38", "T2T", "mm10", "mm9", "ce11"),
  genome_measure = c("called", "wg"),
  complement = FALSE,
  ...
)

Arguments

input

a data.frame or a file or a directory contains copy number profile.

pattern

an optional regular expression used to select part of files if input is a directory, more detail please see list.files() function.

ignore_case

logical. Should pattern-matching be case-insensitive?

seg_cols

four strings used to specify chromosome, start position, end position and copy number value in input, respectively. Default use names from ABSOLUTE calling result.

samp_col

a character used to specify the sample column name. If input is a directory and cannot find samp_col, sample names will use file names (set this parameter to NULL is recommended in this case).

add_loh

if TRUE, add LOH labels to segments. NOTE a column 'minor_cn' must exist to indicate minor allele copy number value. Sex chromosome will not be labeled.

loh_min_len

The length cut-off for labeling a segment as 'LOH'. Default is 10Kb.

loh_min_frac

When join_adj_seg set to TRUE, only the length fraction of LOH region is larger than this value will be labeled as 'LOH'. Default is 30%.

join_adj_seg

if TRUE (default), join adjacent segments with same copy number value. This is helpful for precisely count the number of breakpoint. When set use_all=TRUE, the mean function will be applied to extra numeric columns and unique string columns will be pasted by comma for joined records.

skip_annotation

if TRUE, skip annotation step, it may affect some analysis and visualization functionality, but speed up reading data.

use_all

default is FALSE. If True, use all columns from raw input.

min_segnum

minimal number of copy number segments within a sample.

max_copynumber

bigger copy number within a sample will be reset to this value.

genome_build

genome build version, should be 'hg19', 'hg38', 'mm9' or 'mm10'.

genome_measure

default is 'called', can be 'wg' or 'called'. Set 'called' will use called segments size to compute total size for CNA burden calculation, this option is useful for WES and target sequencing. Set 'wg' will use autosome size from genome build, this option is useful for WGS, SNP etc..

complement

if TRUE, complement chromosome (except 'Y') does not show in input data with normal copy 2.

...

other parameters pass to data.table::fread()

Value

a CopyNumber object.

See also

read_maf for reading mutation data to MAF object.

Author

Shixiang Wang w_shixiang@163.com

Examples

# Load toy dataset of absolute copynumber profile
load(system.file("extdata", "toy_segTab.RData",
  package = "sigminer", mustWork = TRUE
))

# \donttest{
cn <- read_copynumber(segTabs,
  seg_cols = c("chromosome", "start", "end", "segVal"),
  genome_build = "hg19", complement = FALSE
)
#>  [2024-03-13 10:46:40.615923]: Started.
#>  [2024-03-13 10:46:40.617606]: Genome build  : hg19.
#>  [2024-03-13 10:46:40.618965]: Genome measure: called.
#>  [2024-03-13 10:46:40.623153]: Chromosome size database for build obtained.
#>  [2024-03-13 10:46:40.624629]: Reading input.
#>  [2024-03-13 10:46:40.626049]: A data frame as input detected.
#>  [2024-03-13 10:46:40.627542]: Column names checked.
#>  [2024-03-13 10:46:40.629049]: Column order set.
#>  [2024-03-13 10:46:40.631985]: Chromosomes unified.
#>  [2024-03-13 10:46:40.635806]: Data imported.
#>  [2024-03-13 10:46:40.637217]: Segments info:
#>  [2024-03-13 10:46:40.638582]:     Keep - 467
#>  [2024-03-13 10:46:40.639965]:     Drop - 0
#>  [2024-03-13 10:46:40.641627]: Segments sorted.
#>  [2024-03-13 10:46:40.642978]: Joining adjacent segments with same copy number value. Be patient...
#>  [2024-03-13 10:46:40.728295]: 400 segments left after joining.
#>  [2024-03-13 10:46:40.730196]: Segmental table cleaned.
#>  [2024-03-13 10:46:40.731591]: Annotating.
#>  [2024-03-13 10:46:40.744683]: Annotation done.
#>  [2024-03-13 10:46:40.746104]: Summarizing per sample.
#>  [2024-03-13 10:46:40.756001]: Summarized.
#>  [2024-03-13 10:46:40.757412]: Generating CopyNumber object.
#>  [2024-03-13 10:46:40.758999]: Generated.
#>  [2024-03-13 10:46:40.760376]: Validating object.
#>  [2024-03-13 10:46:40.761738]: Done.
#>  [2024-03-13 10:46:40.763145]: 0.147 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       33        6        5        1         4
#>  2: TCGA-19-2621-01B-01D-0911-01       33        8        5        3         5
#>  3: TCGA-B6-A0X5-01A-21D-A107-01       28        8        4        4         2
#>  4: TCGA-A8-A07S-01A-11D-A036-01       38       11        2        9         4
#>  5: TCGA-26-6174-01A-21D-1842-01       43       13        8        5         8
#>  6: TCGA-CV-7432-01A-11D-2128-01       40       16        7        9         9
#>  7: TCGA-06-0644-01A-02D-0310-01       46       19        5       14         8
#>  8: TCGA-A5-A0G2-01A-11D-A042-01       39       21        5       16        10
#>  9: TCGA-99-7458-01A-11D-2035-01       48       26       10       16        13
#> 10: TCGA-05-4417-01A-22D-1854-01       52       37       33        4        17
#>     cna_burden
#>          <num>
#>  1:      0.000
#>  2:      0.099
#>  3:      0.087
#>  4:      0.112
#>  5:      0.119
#>  6:      0.198
#>  7:      0.165
#>  8:      0.393
#>  9:      0.318
#> 10:      0.654
cn_subset <- subset(cn, sample == "TCGA-DF-A2KN-01A-11D-A17U-01")

# Add LOH
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
)
#>  [2024-03-13 10:46:40.778973]: Started.
#>  [2024-03-13 10:46:40.780502]: Genome build  : hg19.
#>  [2024-03-13 10:46:40.781865]: Genome measure: wg.
#>  [2024-03-13 10:46:40.78319]: When add_loh is TRUE, use_all is forced to TRUE.
#> Please drop columns you don't want to keep before reading.
#>  [2024-03-13 10:46:40.786907]: Chromosome size database for build obtained.
#>  [2024-03-13 10:46:40.788351]: Reading input.
#>  [2024-03-13 10:46:40.789747]: A data frame as input detected.
#>  [2024-03-13 10:46:40.791192]: Column names checked.
#>  [2024-03-13 10:46:40.792676]: Column order set.
#>  [2024-03-13 10:46:40.79571]: Chromosomes unified.
#>  [2024-03-13 10:46:40.808891]: Value 2 (normal copy) filled to uncalled chromosomes.
#>  [2024-03-13 10:46:40.812646]: Data imported.
#>  [2024-03-13 10:46:40.814126]: Segments info:
#>  [2024-03-13 10:46:40.815526]:     Keep - 477
#>  [2024-03-13 10:46:40.816952]:     Drop - 0
#>  [2024-03-13 10:46:40.818662]: Segments sorted.
#>  [2024-03-13 10:46:40.820101]: Adding LOH labels...
#>  [2024-03-13 10:46:40.822013]: Joining adjacent segments with same copy number value. Be patient...
#>  [2024-03-13 10:46:40.931891]: 410 segments left after joining.
#>  [2024-03-13 10:46:40.933873]: Segmental table cleaned.
#>  [2024-03-13 10:46:40.935365]: Annotating.
#>  [2024-03-13 10:46:40.949005]: Annotation done.
#>  [2024-03-13 10:46:40.9505]: Summarizing per sample.
#>  [2024-03-13 10:46:40.963472]: Summarized.
#>  [2024-03-13 10:46:40.965031]: Generating CopyNumber object.
#>  [2024-03-13 10:46:40.966737]: Generated.
#>  [2024-03-13 10:46:40.968155]: Validating object.
#>  [2024-03-13 10:46:40.96953]: Done.
#>  [2024-03-13 10:46:40.970948]: 0.192 secs elapsed.
# Use tally method "S" (Steele et al.)
tally_s <- sig_tally(cn, method = "S")
#>  [2024-03-13 10:46:40.973325]: Started.
#>  [2024-03-13 10:46:40.977145]: 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!
#>  [2024-03-13 10:46:40.990102]: Matrix generated.
#>  [2024-03-13 10:46:40.991696]: 0.018 secs elapsed.

tab_file <- system.file("extdata", "metastatic_tumor.segtab.txt",
  package = "sigminer", mustWork = TRUE
)
cn2 <- read_copynumber(tab_file)
#>  [2024-03-13 10:46:40.994992]: Started.
#>  [2024-03-13 10:46:40.996476]: Genome build  : hg19.
#>  [2024-03-13 10:46:40.997838]: Genome measure: called.
#>  [2024-03-13 10:46:41.009108]: Chromosome size database for build obtained.
#>  [2024-03-13 10:46:41.010733]: Reading input.
#>  [2024-03-13 10:46:41.012132]: A file as input detected.
#>  [2024-03-13 10:46:41.014337]: Column names checked.
#>  [2024-03-13 10:46:41.015902]: Column order set.
#>  [2024-03-13 10:46:41.018509]: Chromosomes unified.
#>  [2024-03-13 10:46:41.022197]: Data imported.
#>  [2024-03-13 10:46:41.023641]: Segments info:
#>  [2024-03-13 10:46:41.024997]:     Keep - 201
#>  [2024-03-13 10:46:41.026328]:     Drop - 0
#>  [2024-03-13 10:46:41.028004]: Segments sorted.
#>  [2024-03-13 10:46:41.02934]: Joining adjacent segments with same copy number value. Be patient...
#>  [2024-03-13 10:46:41.045211]: 180 segments left after joining.
#>  [2024-03-13 10:46:41.046876]: Segmental table cleaned.
#>  [2024-03-13 10:46:41.048282]: Annotating.
#>  [2024-03-13 10:46:41.061738]: Annotation done.
#>  [2024-03-13 10:46:41.063629]: Summarizing per sample.
#>  [2024-03-13 10:46:41.074651]: Summarized.
#>  [2024-03-13 10:46:41.076296]: Generating CopyNumber object.
#>  [2024-03-13 10:46:41.078102]: Generated.
#>  [2024-03-13 10:46:41.079652]: Validating object.
#>  [2024-03-13 10:46:41.081135]: Done.
#>  [2024-03-13 10:46:41.082609]: 0.088 secs elapsed.
cn2
#> An object of class CopyNumber 
#> =============================
#>              sample n_of_seg n_of_cnv n_of_amp n_of_del n_of_vchr cna_burden
#>              <char>    <int>    <int>    <int>    <int>     <int>      <num>
#> 1: metastatic_tumor      180      110       92       18        21      0.361
# }