reconstruct {methylKit} | R Documentation

## Reconstruct methylBase or methylBaseDB object based on a new methylation percentage matrix

### Description

The function reconstructs a new methylBase object from an input methylBase object and percent methylation matrix. Basically, it uses the read coverages in the input methylBase object and deduces new number of methylated Cs and unmethylated Cs based on the input percent methylation matrix. It is ideally to be used to reconstruct methylBase objects after batch correction on percent methylation values. The percent methylation matrix rows must match methylBase object rows in order ,and in addition column order (the order of samples) in input methylBase must match the order in percent methylation matrix.

### Usage

    reconstruct(methMat, mBase, chunk.size = 1e+06, save.db = FALSE, ...)

    ## S4 method for signature 'ANY,methylBase'
    reconstruct(methMat, mBase,
      chunk.size = 1e+06, save.db = FALSE, ...)

    ## S4 method for signature 'ANY,methylBaseDB'
    reconstruct(methMat, mBase,
      chunk.size = 1e+06, save.db = TRUE, ...)

### Arguments

`methMat` | percent methylation matrix, row order and order of the samples same as the methylBase object
`mBase` | `methylBase` or `methylBaseDB` object to be reconstructed
`chunk.size` | Number of rows to be taken as a chunk for processing the `methylBaseDB` 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 “_reconstructed” to current filename if database already exists or generate new file with filename “methylBase_reconstructed” `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

new `methylBase` or `methylBase` object where methylation percentage matches input `methMat` and coverages matches input `mBase`

### Details

The parameter `chunk.size` is only used when working with `methylBaseDB` 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 `methylBaseDB`, while being per default FALSE for `methylBase`. 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.

### Note

Batch effect correction (if any batch effect exists) is a tricky issue. We provide some simple ways to deal with it (see `assocComp` and `removeComp` ), But if you can find other ways to correct for batch effects and want to create a methylBase object with the corrected percent methylation values, you can use this function.

### Author(s)

Altuna Akalin

### Examples

    data(methylKit)

    # get percent methylation
    mat=percMethylation(methylBase.obj)

    # do some changes in the matrix
    # this is just a toy example
    # ideally you want to correct the matrix
    # for batch effects
    mat[mat==100]=80

    # reconstruct the methylBase from the corrected matrix
    newobj=reconstruct(mat,methylBase.obj)

[Package methylKit version 1.12.0 Index]