applyGRonGR: Apply a function on a data from gr2 with windows provided by...

Description Usage Arguments Value Examples

View source: R/grangesUtils.R

Description

Apply a function to summarise data from multiple metadata columns of GRanges in gr2 that fall within GRanges provided by gr1

Usage

1
applyGRonGR(gr1, gr2, applyTo, fun, ...)

Arguments

gr1

A GenomicRanges object with windows of interest

gr2

A GenomicRanges object with data of interest

applyTo

Vector with names of columns in gr2 on which to apply the function

fun

Function to apply (e.g. sum, mean, paste0)

Value

GRanges from gr1 with summed values of metadata columns from gr2

Examples

1
2
3
4
5
6
7
# single gr
gr1 <- GenomicRanges::GRanges("chr1", IRanges::IRanges(c(1,3,7), c(5,6,10),names=paste0("win", letters[1:3])), score=4:6)
gr2 <- GenomicRanges::GRanges("chr1", IRanges::IRanges(c(1, 3, 8), c(1, 3, 8),names=paste0("dataID:", letters[1:3])), score=c(10,20,30))
applyGRonGR(gr1,gr2,applyTo="score",fun=sum)
gr1 <- GenomicRanges::GRanges("chr1", IRanges::IRanges(c(1,3,7), c(5,6,10),names=paste0("win", letters[1:3])), score=4:6, other=1:3)
gr2 <- GenomicRanges::GRanges("chr1", IRanges::IRanges(c(1, 3, 8), c(1, 3, 8),names=paste0("dataID:", letters[1:3])), score=c(10,20,30), other=c(100,NA,300))
applyGRonGR(gr1,gr2,c("score","other"),fun=sum,na.rm=T)

CellFateNucOrg/nanodsmf documentation built on July 23, 2020, 4:57 p.m.