Last data update: 2014.03.03

R: Consolidate results for interactions
consolidatePairsR Documentation

Consolidate results for interactions

Description

Consolidate differential testing results for interactions from separate analyses.

Usage

consolidatePairs(indices, result.list, equiweight=TRUE, combine.args=list())

Arguments

indices

a list of index vectors, specifying the cluster ID to which each interaction belongs

result.list

a list of data frames containing the DI test results for each interaction

equiweight

a logical scalar indicating whether equal weighting from each bin size should be enforced

combine.args

a list of parameters to pass to combineTests

Details

Interactions from different analyses can be aggregated together using boxPairs or clusterPairs. For example, test results can be consolidated for bin pairs of differing sizes. This usually produces a indices vector that can be used as an input here. Briefly, each vector in indices should correspond to one analysis, and each entry of that vector should correspond to an analyzed interaction. The vector itself holds cluster IDs, such that interactions within/between analyses with the same ID belong in the same cluster.

For all bin pairs in a cluster, the associated p-values are combined in combineTests using a weighted version of Simes' method. This yields a single combined p-value, representing the evidence against the global null. When equiweight=TRUE, the weight of a p-value of each bin pair is inversely proportional to the number of bin pairs of the same size in that parent bin pair. This ensures that the results are not dominated by numerous smaller bin pairs.

Value

A data frame is returned containing the combined DB results for each cluster.

Author(s)

Aaron Lun

See Also

combineTests, boxPairs, clusterPairs

Examples

# Setting up the objects.
a <- 10
b <- 20
cuts <- GRanges(rep(c("chrA", "chrB"), c(a, b)), IRanges(c(1:a, 1:b), c(1:a, 1:b)))
param <- pairParam(cuts)

all.combos <- combn(length(cuts), 2) # Bin size of 1.
y <- InteractionSet(matrix(0, ncol(all.combos), 1), 
    GInteractions(anchor1=all.combos[2,], anchor2=all.combos[1,], regions=cuts, mode="reverse"),
    colData=DataFrame(lib.size=1000), metadata=List(param=param, width=1))

a5 <- a/5
b5 <- b/5
all.combos2 <- combn(length(cuts)/5, 2) # Bin size of 5.
y2 <- InteractionSet(matrix(0, ncol(all.combos2), 1), 
    GInteractions(anchor1=all.combos2[2,], anchor2=all.combos2[1,], 
	    regions=GRanges(rep(c("chrA", "chrB"), c(a5, b5)), 
		    IRanges(c((1:a5-1)*5+1, (1:b5-1)*5+1), c(1:a5*5, 1:b5*5))), mode="reverse"),
     colData=DataFrame(lib.size=1000), metadata=List(param=param, width=5))

result1 <- data.frame(logFC=rnorm(nrow(y)), PValue=runif(nrow(y)), logCPM=0)
result2 <- data.frame(logFC=rnorm(nrow(y2)), PValue=runif(nrow(y2)), logCPM=0)

# Consolidating.
boxed <- boxPairs(y, y2)
out <- consolidatePairs(boxed$indices, list(result1, result2))
head(out)
out <- consolidatePairs(boxed$indices, list(result1, result2), equiweight=FALSE)
head(out)

# Repeating with three sizes.
a10 <- a/10
b10 <- b/10
all.combos3 <- combn(length(cuts)/10, 2) # Bin size of 10.
y3 <- InteractionSet(matrix(0, ncol(all.combos3), 1), 
    GInteractions(anchor1=all.combos3[2,], anchor2=all.combos3[1,], 
    	regions=GRanges(rep(c("chrA", "chrB"), c(a10, b10)), 
	    	IRanges(c((1:a10-1)*10+1, (1:b10-1)*10+1), c(1:a10*10, 1:b10*10))),
        mode="reverse"),
     colData=DataFrame(lib.size=1000), metadata=List(param=param, width=10))
result3 <- data.frame(logFC=rnorm(nrow(y3)), PValue=runif(nrow(y3)), logCPM=0)

boxed <- boxPairs(y, y2, y3)
out <- consolidatePairs(boxed$indices, list(result1, result2, result3))
head(out)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(diffHic)
Loading required package: GenomicRanges
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

    IQR, mad, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
    get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
    match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
    rbind, rownames, sapply, setdiff, sort, table, tapply, union,
    unique, unsplit

Loading required package: S4Vectors
Loading required package: stats4

Attaching package: 'S4Vectors'

The following objects are masked from 'package:base':

    colMeans, colSums, expand.grid, rowMeans, rowSums

Loading required package: IRanges
Loading required package: GenomeInfoDb
Loading required package: InteractionSet
Loading required package: SummarizedExperiment
Loading required package: Biobase
Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.

> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/diffHic/consolidatePairs.Rd_%03d_medium.png", width=480, height=480)
> ### Name: consolidatePairs
> ### Title: Consolidate results for interactions
> ### Aliases: consolidatePairs
> ### Keywords: testing
> 
> ### ** Examples
> 
> # Setting up the objects.
> a <- 10
> b <- 20
> cuts <- GRanges(rep(c("chrA", "chrB"), c(a, b)), IRanges(c(1:a, 1:b), c(1:a, 1:b)))
> param <- pairParam(cuts)
> 
> all.combos <- combn(length(cuts), 2) # Bin size of 1.
> y <- InteractionSet(matrix(0, ncol(all.combos), 1), 
+     GInteractions(anchor1=all.combos[2,], anchor2=all.combos[1,], regions=cuts, mode="reverse"),
+     colData=DataFrame(lib.size=1000), metadata=List(param=param, width=1))
> 
> a5 <- a/5
> b5 <- b/5
> all.combos2 <- combn(length(cuts)/5, 2) # Bin size of 5.
> y2 <- InteractionSet(matrix(0, ncol(all.combos2), 1), 
+     GInteractions(anchor1=all.combos2[2,], anchor2=all.combos2[1,], 
+ 	    regions=GRanges(rep(c("chrA", "chrB"), c(a5, b5)), 
+ 		    IRanges(c((1:a5-1)*5+1, (1:b5-1)*5+1), c(1:a5*5, 1:b5*5))), mode="reverse"),
+      colData=DataFrame(lib.size=1000), metadata=List(param=param, width=5))
> 
> result1 <- data.frame(logFC=rnorm(nrow(y)), PValue=runif(nrow(y)), logCPM=0)
> result2 <- data.frame(logFC=rnorm(nrow(y2)), PValue=runif(nrow(y2)), logCPM=0)
> 
> # Consolidating.
> boxed <- boxPairs(y, y2)
> out <- consolidatePairs(boxed$indices, list(result1, result2))
> head(out)
  nWindows logFC.up logFC.down    PValue       FDR
1       10        3          4 0.9672481 0.9932585
2       26        7          6 0.1480121 0.9682201
3       10        4          2 0.2345032 0.9682201
4       26        8          6 0.6276596 0.9932585
5       26       11          9 0.7398427 0.9932585
6       10        3          1 0.9932585 0.9932585
> out <- consolidatePairs(boxed$indices, list(result1, result2), equiweight=FALSE)
> head(out)
  nWindows logFC.up logFC.down     PValue       FDR
1       10        3          4 0.96724811 0.9932585
2       26        7          6 0.07696631 0.5918169
3       10        4          2 0.23450322 0.9849135
4       26        8          6 0.81820722 0.9932585
5       26       11          9 0.69895206 0.9932585
6       10        3          1 0.99325853 0.9932585
> 
> # Repeating with three sizes.
> a10 <- a/10
> b10 <- b/10
> all.combos3 <- combn(length(cuts)/10, 2) # Bin size of 10.
> y3 <- InteractionSet(matrix(0, ncol(all.combos3), 1), 
+     GInteractions(anchor1=all.combos3[2,], anchor2=all.combos3[1,], 
+     	regions=GRanges(rep(c("chrA", "chrB"), c(a10, b10)), 
+ 	    	IRanges(c((1:a10-1)*10+1, (1:b10-1)*10+1), c(1:a10*10, 1:b10*10))),
+         mode="reverse"),
+      colData=DataFrame(lib.size=1000), metadata=List(param=param, width=10))
> result3 <- data.frame(logFC=rnorm(nrow(y3)), PValue=runif(nrow(y3)), logCPM=0)
> 
> boxed <- boxPairs(y, y2, y3)
> out <- consolidatePairs(boxed$indices, list(result1, result2, result3))
> head(out)
  nWindows logFC.up logFC.down    PValue       FDR
1       46       14         12 0.2664219 0.8911555
2      105       32         34 0.9079470 0.9079470
3       46       16          6 0.5941037 0.8911555
4      105       37         29 0.4654302 0.8911555
5      105       29         34 0.8768271 0.9079470
6       46       13         17 0.3860763 0.8911555
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>