Convenience function for multiplying signal counts in one or more GRanges object by their normalization factors.

applyNFsGRanges(
  dataset.gr,
  NF,
  field = "score",
  ncores = getOption("mc.cores", 2L)
)

Arguments

dataset.gr

A GRanges object with signal data in one or more metadata fields, or a list of such GRanges objects.

NF

One or more normalization factors to apply by multiplication. The number of normalization factors should match the number of datasets in dataset.gr.

field

The metadata field(s) in dataset.gr that contain signal to be normalized.

ncores

The number of cores to use for computations. Multicore only used if there are multiple datasets present.

Value

A GRanges object, or a list of GRanges objects.

See also

Author

Mike DeBerardine

Examples

# Apply NFs to a single GRanges
gr <- GRanges(seqnames = "chr1",
              ranges = IRanges(1:3, 3:5),
              strand = c("+", "+", "-"),
              score = c(2, 3, 4))
gr
#> GRanges object with 3 ranges and 1 metadata column:
#>       seqnames    ranges strand |     score
#>          <Rle> <IRanges>  <Rle> | <numeric>
#>   [1]     chr1       1-3      + |         2
#>   [2]     chr1       2-4      + |         3
#>   [3]     chr1       3-5      - |         4
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths

applyNFsGRanges(gr, NF = 0.5, ncores = 1)
#> GRanges object with 3 ranges and 1 metadata column:
#>       seqnames    ranges strand |     score
#>          <Rle> <IRanges>  <Rle> | <numeric>
#>   [1]     chr1       1-3      + |       1.0
#>   [2]     chr1       2-4      + |       1.5
#>   [3]     chr1       3-5      - |       2.0
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths

# Apply NFs to a list of GRanges
gr2 <- gr
ranges(gr2) <- IRanges(4:6, 5:7)
grl <- list(gr, gr2)
grl
#> [[1]]
#> GRanges object with 3 ranges and 1 metadata column:
#>       seqnames    ranges strand |     score
#>          <Rle> <IRanges>  <Rle> | <numeric>
#>   [1]     chr1       1-3      + |         2
#>   [2]     chr1       2-4      + |         3
#>   [3]     chr1       3-5      - |         4
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths
#> 
#> [[2]]
#> GRanges object with 3 ranges and 1 metadata column:
#>       seqnames    ranges strand |     score
#>          <Rle> <IRanges>  <Rle> | <numeric>
#>   [1]     chr1       4-5      + |         2
#>   [2]     chr1       5-6      + |         3
#>   [3]     chr1       6-7      - |         4
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths
#> 

applyNFsGRanges(grl, NF = c(0.5, 0.75), ncores = 1)
#> [[1]]
#> GRanges object with 3 ranges and 1 metadata column:
#>       seqnames    ranges strand |     score
#>          <Rle> <IRanges>  <Rle> | <numeric>
#>   [1]     chr1       1-3      + |       1.0
#>   [2]     chr1       2-4      + |       1.5
#>   [3]     chr1       3-5      - |       2.0
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths
#> 
#> [[2]]
#> GRanges object with 3 ranges and 1 metadata column:
#>       seqnames    ranges strand |     score
#>          <Rle> <IRanges>  <Rle> | <numeric>
#>   [1]     chr1       4-5      + |      1.50
#>   [2]     chr1       5-6      + |      2.25
#>   [3]     chr1       6-7      - |      3.00
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths
#> 

# Apply NFs to a multiplexed GRanges
gr_multi <- gr
names(mcols(gr_multi)) <- "gr1"
gr_multi$gr2 <- c(3, 5, 7)
gr_multi
#> GRanges object with 3 ranges and 2 metadata columns:
#>       seqnames    ranges strand |       gr1       gr2
#>          <Rle> <IRanges>  <Rle> | <numeric> <numeric>
#>   [1]     chr1       1-3      + |         2         3
#>   [2]     chr1       2-4      + |         3         5
#>   [3]     chr1       3-5      - |         4         7
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths

applyNFsGRanges(gr_multi, NF = c(2, 3), field = c("gr1", "gr2"),
                ncores = 1)
#> GRanges object with 3 ranges and 2 metadata columns:
#>       seqnames    ranges strand |       gr1       gr2
#>          <Rle> <IRanges>  <Rle> | <numeric> <numeric>
#>   [1]     chr1       1-3      + |         4         9
#>   [2]     chr1       2-4      + |         6        15
#>   [3]     chr1       3-5      - |         8        21
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths