regionCounts: Get regional counts for given GRanges or GRangesList object

regionCountsR Documentation

Get regional counts for given GRanges or GRangesList object

Description

Convert methylRaw, methylRawDB, methylRawList, methylRawListDB, methylBase or methylBaseDB object into regional counts for a given GRanges or GRangesList object.

Usage

regionCounts(object,regions,cov.bases=0,strand.aware=FALSE,chunk.size,save.db,...)

## S4 method for signature 'methylRaw,GRanges'
regionCounts(
  object,
  regions,
  cov.bases = 0,
  strand.aware = FALSE,
  chunk.size = 1e+06,
  save.db = FALSE,
  ...
)

## S4 method for signature 'methylBase,GRanges'
regionCounts(
  object,
  regions,
  cov.bases = 0,
  strand.aware = FALSE,
  chunk.size = 1e+06,
  save.db = FALSE,
  ...
)

## S4 method for signature 'methylRaw,GRangesList'
regionCounts(
  object,
  regions,
  cov.bases = 0,
  strand.aware = FALSE,
  chunk.size = 1e+06,
  save.db = FALSE,
  ...
)

## S4 method for signature 'methylBase,GRangesList'
regionCounts(
  object,
  regions,
  cov.bases = 0,
  strand.aware = FALSE,
  chunk.size = 1e+06,
  save.db = FALSE,
  ...
)

## S4 method for signature 'methylRawList,GRanges'
regionCounts(
  object,
  regions,
  cov.bases = 0,
  strand.aware = FALSE,
  chunk.size = 1e+06,
  save.db = FALSE,
  ...
)

## S4 method for signature 'methylRawList,GRangesList'
regionCounts(
  object,
  regions,
  cov.bases = 0,
  strand.aware = FALSE,
  chunk.size = 1e+06,
  save.db = FALSE,
  ...
)

## S4 method for signature 'methylRawDB,GRanges'
regionCounts(
  object,
  regions,
  cov.bases = 0,
  strand.aware = FALSE,
  chunk.size = 1e+06,
  save.db = TRUE,
  ...
)

## S4 method for signature 'methylRawDB,GRangesList'
regionCounts(
  object,
  regions,
  cov.bases = 0,
  strand.aware = FALSE,
  chunk.size = 1e+06,
  save.db = TRUE,
  ...
)

## S4 method for signature 'methylRawListDB,GRanges'
regionCounts(
  object,
  regions,
  cov.bases = 0,
  strand.aware = FALSE,
  chunk.size = 1e+06,
  save.db = TRUE,
  ...
)

## S4 method for signature 'methylRawListDB,GRangesList'
regionCounts(
  object,
  regions,
  cov.bases = 0,
  strand.aware = FALSE,
  chunk.size = 1e+06,
  save.db = TRUE,
  ...
)

## S4 method for signature 'methylBaseDB,GRanges'
regionCounts(
  object,
  regions,
  cov.bases = 0,
  strand.aware = FALSE,
  chunk.size = 1e+06,
  save.db = TRUE,
  ...
)

## S4 method for signature 'methylBaseDB,GRangesList'
regionCounts(
  object,
  regions,
  cov.bases = 0,
  strand.aware = FALSE,
  chunk.size = 1e+06,
  save.db = TRUE,
  ...
)

Arguments

object

a methylRaw, methylRawDB, methylRawList, methylRawListDB, methylBase or methylBaseDB object

NOTE: The given regions (Granges/GrangesList object) will be orderd based on chromosome and position before searching for overlaps, so the resulting methylKit object might have a different ording than expected. See details section for the reasoning of this choice and ways to still get custom ordering of regions.

regions

a GRanges or GRangesList object. Make sure that the GRanges objects are unique in chr,start,end and strand columns.You can make them unique by using unique() function.

cov.bases

number minimum bases covered per region (Default:0). Only regions with base coverage above this threshold are returned.

strand.aware

if set to TRUE only CpGs that match the strand of the region will be summarized. (default:FALSE)

chunk.size

Number of rows to be taken as a chunk for processing the methylDB objects (default: 1e6)

save.db

A Logical to decide whether the resulting object should be saved as flat file database or not, default: explained in Details sections

...

optional Arguments used when save.db is TRUE

suffix A character string to append to the name of the output flat file database, only used if save.db is true, default actions: append “_regions” to current filename if database already exists or generate new file with filename “sampleID_regions” or “methylBase_filtered” dependent on input object

dbdir The directory where flat file database(s) should be stored, defaults to getwd(), working directory for newly stored databases and to same directory for already existing database

dbtype The type of the flat file database, currently only option is "tabix" (only used for newly stored databases)

Value

a new methylRaw,methylBase or methylRawList object. If strand.aware is set to FALSE (default). Even though the resulting object will have the strand information of regions it will still contain methylation information from both strands.

Details

The given regions (Granges/GrangesList object) will be orderd based on chromosome and position before searching for overlaps, so the resulting methylKit object might have a different ording than expected. We are doing this is to ensure that resulting output is consistent for in-memory and database based objects, as database based objects always have to be sorted to enable tabix indexing and providing fast random access.

If you to still want get a custom ordering of the output regions you can access the single regions in any object providing your indices to the select or extract functions.

The parameter chunk.size is only used when working with methylRawDB, methylBaseDB or methylRawListDB objects, as they are read in chunk by chunk to enable processing large-sized objects which are stored as flat file database. Per default the chunk.size is set to 1M rows, which should work for most systems. If you encounter memory problems or have a high amount of memory available feel free to adjust the chunk.size.

The parameter save.db is per default TRUE for methylDB objects as methylRawDB, methylBaseDB or methylRawListDB, while being per default FALSE for methylRaw, methylBase or methylRawList. If you wish to save the result of an in-memory-calculation as flat file database or if the size of the database allows the calculation in-memory, then you might want to change the value of this parameter.

Examples

data(methylKit)

# get the windows of interest as a GRanges object, this can be any set 
# of genomic locations
library(GenomicRanges)
my.win=GRanges(seqnames="chr21",
ranges=IRanges(start=seq(from=9764513,by=10000,length.out=20),width=5000) )

# getting counts per region
regional.methylRaw=regionCounts(object=methylRawList.obj, regions=my.win, 
cov.bases=0,strand.aware=FALSE)


al2na/methylKit documentation built on Feb. 1, 2024, 4:42 p.m.