HenrikBengtsson / TopDom

R package: TopDom - An efficient and Deterministic Method for identifying Topological Domains in Genomes
https://cran.r-project.org/package=TopDom
20 stars 5 forks source link

Add countsByRegion(data, region) to extract count data for a given region #6

Closed HenrikBengtsson closed 6 years ago

HenrikBengtsson commented 6 years ago

Add a countsByRegion(data, region, margin) for TopDomData object that extracts the count data matrix for a given region plus a given margin. There region can be a TD row.

Coceptually, it should look something like:

countsByRegion.TopDomData <- function(data, region, margin = 0) {
   bins <- with(data$bins, which(chr == region$chr & from.coord >= region$from.coord - margin & to.coord <= region$to.coord + margin))
   data$counts[bins, bins, drop = FALSE]
}