Learn R Programming

diffHic (version 1.4.2)

savePairs: Save Hi-C interactions

Description

Save a dataframe of interactions into a directory structure for rapid chromosomal access.

Usage

savePairs(x, file, param)

Arguments

x
a sorted dataframe with integer fields anchor1.id and anchor2.id for each interaction
file
a character string specifying the path for the output index file
param
a pairParam object containing read extraction parameters

Value

An index file is produced at the specified file location, containing the interaction data. A NULL value is invisibly returned.

Details

This function facilitates the input of processed Hi-C data from other sources into the current pipeline. Each entry in x$anchor1.id and x$anchor2.id refers to the index of param$fragments to denote the interacting regions. The x object will be resorted by anchor1.id, then anchor2.id. If necessary, anchor1 and anchor2 indices will be switched such that the former is never less than the latter.

The coordinates of the restriction fragment boundaries in param$fragments should correspond to the reference genome being used. In most cases, these can be generated using the cutGenome function from any given BSgenome object. Values of param$discard and param$restrict will not be used here and can be ignored.

Any additional fields in x will also be saved to file. Users are recommended to put in anchor1.pos, anchor1.len, anchor2.pos and anchor2.len fields. This will allow removal of reads in param$discard during counting (e.g., with squareCounts). It will also allow proper calculation of statistics with getPairData, and quality control with prunePairs. See the output of preparePairs for more details on the specification of the fields.

See Also

preparePairs, cutGenome

Examples

Run this code
hic.file <- system.file("exdata", "hic_sort.bam", package="diffHic")
cuts <-readRDS(system.file("exdata", "cuts.rds", package="diffHic"))
param <- pairParam(cuts)

n <- 1000
all.a <- as.integer(runif(n, 1L, length(cuts)))
all.t <- as.integer(runif(n, 1L, length(cuts)))
x <- data.frame(anchor1.id=all.a, anchor2.id=all.t,
	anchor1.pos=runif(1:100), anchor1.len=10, 
	anchor2.pos=runif(1:100), anchor2.len=-10)

fout <- "temp2.h5"
savePairs(x, fout, param)
require(rhdf5)
head(h5read(fout, "chrA/chrA"))


Run the code above in your browser using DataLab