Learn R Programming

Pasha (version 0.99.21)

readWIG and writeWIG: Read and Write genomic WIG (fixed step) files

Description

Functions dedicated for reading and writing WIG fixed step from their named list representation in R.

Usage

readWIG(fileName) writeWIG(wigData, fileName, folder=NULL, fixedStep=50, addExtension=TRUE)

Arguments

fileName
Path to the file on which to write the results or from which to read the data
wigData
A named list of numeric vectors representing each chromosome (or track) piled data scores to be written
folder
Eventual folder path (for writeWIG) that will be concatenated to the filename (can be NULL if the user prefers to specify the full path in fileName)
fixedStep
Size of the bins used for the representation of piled data in the named list (the function can not detect it since this information is not carried by wigData)
addExtension
Single logical. Specify if the extension string "wig" should be added to the filename if 'fileName' argument does not end with it (case is ignored for search).

Value

readWIG returns a named list of numeric vectors (each track in the wig gives a new list element), each numeric value correspond to a bin in the corresponding track.

Details

IMPORTANT : These functions can only handle fixed step WIGs with a limited format. They assume a very UNflexible format with two lines of description for each track and can't be used in other contexts. Binsize specified in the file is IGNORED while reading the file and the user is assumed to know it.

See Also

mergeWigs

Examples

Run this code
## Define an artificial wig list
generateWigScores <- function(scores=1:20, lengthTrack=1000)
{
    return(sample(scores, lengthTrack, replace=TRUE))
}

myWig <- list("chr1"=generateWigScores(), "chr2"=generateWigScores())

# Write a wig file that can be read in genome browsers
writeWIG(myWig, "myWigFixedSteps", folder=tempdir(), fixedStep=200)

# Read the file generated
myWigFromFile <- readWIG(file.path(tempdir(), "myWigFixedSteps.wig"))

# Check that scores are equal for all chromosomes
if(!all(mapply(all.equal,myWig,myWigFromFile))) stop ("Error, the original 
generated data look different from what has been read");

Run the code above in your browser using DataLab