Runs a CNV pipeline on each sample: counts fragments in fixed-size genomic windows, normalises for GC and mappability (HMMcopy), segments, and stores per-window copy-number in the qseaSet. Supports parallel execution. The GC and mappability tracks must match the genome of the qseaSet: mesa ships them for hg38 (genome-wide) and for hg19 chr22.

addHMMcopyCNV(
  qs,
  inputColumn = "input_file",
  windowSize = 1e+06,
  fragmentLength = NULL,
  plotDir = NULL,
  parallel = getMesaParallel(),
  maxInsertSize = 1000,
  minInsertSize = 50,
  minReferenceLength = 30,
  minMapQual = 30,
  properPairsOnly = FALSE,
  hmmCopyGC = NULL,
  hmmCopyMap = NULL
)

Arguments

qs

qseaSet. Input object whose samples will receive CNV tracks.

inputColumn

character(1). Column in the sample table containing BAM paths (e.g. "input_file"). Default: "input_file".

windowSize

integer(1). CNV bin size in bp, which must be the bin size of hmmCopyGC and hmmCopyMap. The hg38 tracks come in 50000, 500000 and 1000000. Default: 1000000.

fragmentLength

integer(1) or NULL. Length to extend unpaired R1 reads; if NULL, estimate from proper pairs. Default: NULL.

plotDir

character(1) or NULL. Directory to write per-sample PDF diagnostics; if NULL, no plots are saved. Default: NULL.

parallel

logical(1). Use the registered BiocParallel backend when TRUE; otherwise run serially. Default: getMesaParallel().

maxInsertSize

integer(1). Maximum insert size to accept for proper pairs (bp). Default: 1000.

minInsertSize

integer(1). Minimum insert size to accept for proper pairs (bp). Default: 50.

minReferenceLength

integer(1). Minimum aligned reference span for unpaired R1 (bp). Default: 30.

minMapQual

integer(1). Minimum MAPQ; for pairs, either end meeting the cutoff is accepted. Default: 30.

properPairsOnly

logical(1). If TRUE, ignore unpaired R1; if FALSE, combine proper pairs with high-quality R1. Default: FALSE.

hmmCopyGC

GRanges or NULL. Precomputed GC content track binned at windowSize. Default: NULL.

hmmCopyMap

GRanges or NULL. Precomputed mappability track binned at windowSize. Default: NULL.

Value

The input qseaSet with CNV information attached, including:

  • per-window CNV tracks accessible via downstream CNV accessors,

  • library/sample tables updated with relevant CNV/coverage summaries,

  • (optionally) per-sample diagnostic PDFs if plotDir is provided.

Details

Coverage is obtained (pairs + optional R1) over tiled windows, corrected with HMMcopy (HMMcopy::correctReadcount() followed by HMMcopy::HMMsegment()), and merged back into the qseaSet. You must supply GC/mappability tracks binned at the same windowSize (or use package-provided defaults where applicable). When parallel = TRUE, computation uses the currently registered backend (see BiocParallel::register()).

See also

runHMMcopy(), plotCNVheatmap(), getBamCoveragePairedAndUnpairedR1() (internal low-level worker), HMMcopy::correctReadcount(), HMMcopy::HMMsegment(), BiocParallel::register()

Other CNV: plotCNVheatmap(), removeCNV(), runHMMCopy()

Examples

# A single-end MeDIP-seq input BAM on chr22 (hg19), from MEDIPSData, with
# the GC and mappability tracks for hg19 chr22 that ship with mesa
if (requireNamespace("MEDIPSData", quietly = TRUE) &&
    requireNamespace("BSgenome.Hsapiens.UCSC.hg19", quietly = TRUE)) {
    bam <- system.file("extdata", "hESCs.Input.chr22.bam",
        package = "MEDIPSData")

    qs <- data.frame(sample_name = "hESC", file_name = bam,
        input_file = bam, group = "Input") %>%
        qsea::createQseaSet("BSgenome.Hsapiens.UCSC.hg19",
            chr.select = "chr22", window_size = 5000)

    qs <- addHMMcopyCNV(qs,
        windowSize = 1e5,
        fragmentLength = 300,
        hmmCopyGC = gc_hg19_chr22_100kb,
        hmmCopyMap = map_hg19_chr22_100kb,
        parallel = FALSE
    )

    # The copy-number state of each 100 kb window
    qsea::getCNV(qs)
}
#> ==== Creating qsea set ====
#> restricting analysis on chr22
#> Dividing selected chromosomes of BSgenome.Hsapiens.UCSC.hg19 in 5000nt windows
#> Reading hESCs.Input.chr22.bam, with minimum mapping quality 30.
#> No samtools fixmate MQ (mate quality) tags on the bam file, using R1 MAPQ only.
#> Using high quality R1 unpaired reads as well as pairs
#> Setting unpaired fragment lengths to 300.
#> GRanges object with 513 ranges and 1 metadata column:
#>         seqnames            ranges strand |      hESC
#>            <Rle>         <IRanges>  <Rle> | <numeric>
#>     [1]    chr22          1-100000      * |     -0.01
#>     [2]    chr22     100001-200000      * |     -0.01
#>     [3]    chr22     200001-300000      * |     -0.01
#>     [4]    chr22     300001-400000      * |     -0.01
#>     [5]    chr22     400001-500000      * |     -0.01
#>     ...      ...               ...    ... .       ...
#>   [509]    chr22 50800001-50900000      * |     -0.01
#>   [510]    chr22 50900001-51000000      * |     -0.01
#>   [511]    chr22 51000001-51100000      * |     -0.01
#>   [512]    chr22 51100001-51200000      * |     -0.01
#>   [513]    chr22 51200001-51300000      * |     -0.01
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths