Skip to contents

Run CBS algorithm using DNAcopy on a per-chromosome basis on read depth profile. This allows for parallel computation of the segmentation, rapidly reducing run time. There should be no NAs in the columns or 0s in the signal column.

Note, this function was designed to be run as part of the get_fragcounter_segmentation() workflow. Also, see chrompar() for executing in parallel.

Usage

get_cbs_per_chromosome(
  chrom_for_cbs,
  chromosome_names,
  signal,
  position,
  sample_id
)

Arguments

chrom_for_cbs

The chromosome to run CBS algorithm on

chromosome_names

A vector of chromosome strings, equivalent to the seqnames column. Must contain at least the chrom_for_cbs

signal

A vector of read depth signal to be used as input. These values will be logged before use in CBS

position

A vector of the genomic position of the signal measurement, equivalent to the start column

sample_id

A string used to populate the ID column in the data.table

Value

data.table of CBS segmentation values per chromosome

Examples

# For this example, there are no NAs or zeros in the `signal`
# Check for these and may need to filter them out
read_depth_demo_hg38
#> GRanges object with 20002 ranges and 8 metadata columns:
#>           seqnames            ranges strand | background.log
#>              <Rle>         <IRanges>  <Rle> |      <numeric>
#>       [1]    chr19          23000000      * |       0.127594
#>       [2]    chr19 23000001-23000200      * |      -0.311801
#>       [3]    chr19 23000201-23000400      * |      -0.280075
#>       [4]    chr19 23000401-23000600      * |      -0.261436
#>       [5]    chr19 23000601-23000800      * |      -0.261440
#>       ...      ...               ...    ... .            ...
#>   [19998]    chr21 24999001-24999200      * |     -0.3118023
#>   [19999]    chr21 24999201-24999400      * |     -0.2614352
#>   [20000]    chr21 24999401-24999600      * |     -0.3118012
#>   [20001]    chr21 24999601-24999800      * |      0.1297325
#>   [20002]    chr21 24999801-25000000      * |      0.0268664
#>           foreground.log input.read.counts median.chr foreground
#>                <numeric>         <numeric>  <numeric>  <numeric>
#>       [1]     -0.0394919          1.155556   0.961278   0.961278
#>       [2]     -0.0394919          0.386038   0.961278   0.961278
#>       [3]      0.2346718          0.955857   0.961278   1.264494
#>       [4]     -0.0394919          1.447640   0.961278   0.961278
#>       [5]     -0.0394919          0.927922   0.961278   0.961278
#>       ...            ...               ...        ...        ...
#>   [19998]     -0.0559702          0.896007   0.945567   0.945567
#>   [19999]     -0.0559702          1.567746   0.945567   0.945567
#>   [20000]     -0.0559702          0.883972   0.945567   0.945567
#>   [20001]     -0.0559702          0.938086   0.945567   0.945567
#>   [20002]     -0.0559702          1.217163   0.945567   0.945567
#>           background  log.reads germline.status
#>            <numeric>  <numeric>       <logical>
#>       [1]   1.136092  0.1445814            TRUE
#>       [2]   0.732127 -0.9518190            TRUE
#>       [3]   0.755727 -0.0451467           FALSE
#>       [4]   0.769945  0.3699345            TRUE
#>       [5]   0.769942 -0.0748075            TRUE
#>       ...        ...        ...             ...
#>   [19998]   0.732126 -0.1098068            TRUE
#>   [19999]   0.769946  0.4496388            TRUE
#>   [20000]   0.732127 -0.1233302            TRUE
#>   [20001]   1.138524 -0.0639141            TRUE
#>   [20002]   1.027231  0.1965224            TRUE
#>   -------
#>   seqinfo: 24 sequences from GRCh38 genome

# Example of what the input looks like for
# chromosome_names
# head(as.character(GenomicRanges::seqnames(read_depth_demo_hg38)))
# signal
# head(as.double(GenomicRanges::values(read_depth_demo_hg38)[, "reads.corrected"]))
# position
# head(GenomicRanges::start(read_depth_demo_hg38))