grSummaryPerBin: Genomic bins

View source: R/bioinfo_sequences.R

grSummaryPerBinR Documentation

Genomic bins

Description

Summarize a given metric per GRanges over genomic bins.

Usage

grSummaryPerBin(
  gr,
  colname = NULL,
  binwidth = 200,
  which.summary = "sum",
  plot.it = FALSE,
  ...
)

Arguments

gr

GRanges object

colname

character specifying a given column in mcols(gr); if NULL, the number of ranges per bin will be counted

binwidth

fixed width of each bin

which.summary

names of the summaryzing function (one or several among c("sum", "mean", "min", "max"))

plot.it

if TRUE, a karyogram will be plotted

...

other arguments passed to autoplot, such as main

Value

invisible GRanges containing the bins with the summary

Author(s)

Timothee Flutre

Examples

## Not run: ## dummy data
set.seed(1)
C <- 2
P <- C * 10^3
df <- data.frame(CHR=c(rep("chr1", 10^3), rep("chr2", 10^3)),
                 SNP=paste0("snp", 1:P),
                 POS=NA,
                 N=abs(rnorm(P)))
df$POS[df$CHR == "chr1"] <- sort(sample.int(10^5, 10^3))
df$POS[df$CHR == "chr2"] <- sort(sample.int(10^5, 10^3))
head(df)
str(df)

library(GenomicRanges)
df.gr <- GRanges(seqnames=df$CHR, ranges=IRanges(start=df$POS, width=1),
                 metric=df$N,
                 seqlengths=c(chr1=10^5, chr2=10^5))
df.gr

(bins <- grSummaryPerBin(gr=df.gr, colname=NULL, binwidth=200))
(bins <- grSummaryPerBin(gr=df.gr, colname="metric", binwidth=200,
                         which.summary="sum"))
(bins <- grSummaryPerBin(gr=df.gr, colname="metric", binwidth=200,
                         which.summary="sum", which.plot="sum", plot.it=TRUE))

## End(Not run)

timflutre/rutilstimflutre documentation built on Feb. 7, 2024, 8:17 a.m.