mergeWigs: Merge several different wig files in a unique result file

Description Usage Arguments Details Value Author(s) See Also Examples

Description

This function computes the average for each genomic position in several WIG files (fixed step).

Usage

1
 mergeWigs(files, binSize, outputFolder) 

Arguments

files

A named list of character vectors, each one containing the paths to the wig files that will be merged with other ones, one can specify several elements (as much as expected merge results) that will be treated sequentially

binSize

The size of the bins (steps) in the wig files, must be the same for all files

outputFolder

The folder where the results will be written, created recursively if doesn't exist

Details

For each element of the files list, this function reads all the wigs files specified and compute an average of all wigs for each position of each chromosome. This function only works for fixedStep wigs and is based on the unflexible format defined by readWIG and writeWIG functions. Thus it might not be compliant with all the WIG fixed step specification. The result is directly written to disk as wig in the specified folder.

Value

NULL

Author(s)

Romain Fenouil

See Also

readWIG writeWIG

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Generate artificial wig fixed step files with random counts
exampleFolder <- tempdir(); nbFiles=6; nbChromosomes=4

for(fileIndex in 1:nbFiles)
{
    wigScoresContent <- lapply(as.list(1:nbChromosomes), 
        function(x) {sample(x=1:20, size=1000, replace=TRUE, prob=NULL)})
    names(wigScoresContent)<- paste("chr", 1:nbChromosomes, sep="");
    writeWIG(wigScoresContent, 
                paste("wigFileExample", fileIndex, sep=""),
                folder=exampleFolder, fixedStep=200) 
}

# Build a file list containing wig files to merge together, and a
# reference to the file to be used as input for score subtraction
wigFileList <- paste(exampleFolder, 
                     "/",
                     "wigFileExample",
                     1:nbFiles,
                     ".wig", sep="")

# Merge files together (average the scores at each coordinates),
# producing two WIG files
filesToMerge <- list()
filesToMerge[["MyEXP1"]] <- wigFileList[1:(nbFiles/2)]
filesToMerge[["MyEXP2"]] <- wigFileList[((nbFiles/2)+1):nbFiles]

mergeWigs(files=filesToMerge, binSize=200, outputFolder=exampleFolder)

Pasha documentation built on Jan. 15, 2017, 6:21 p.m.

Related to mergeWigs in Pasha...