Question: How to set a negative coverage to ZERO
0
gravatar for vanhzh
3.5 years ago by
vanhzh0
vanhzh0 wrote:

Dear all, 

I try to subtract one coverage from another and set the negative value in the result coverage object to 0 so that the coverage at each position would be a non-negative value.  I want all the negative values in <cov.gr2> object to be zero in this dummy example.

Thanks very much for your help!

Zhenhua Hu

library(GenomicRanges)
gr1 <- GRanges(seqnames = Rle(c("chr1", "chr2"), c(2,2)), ranges = IRanges(start = c(3,6,1,9), width = c(100, 200, 10, 40)))

cov.gr1 <- coverage(gr1)
cov.gr2 <-cov.gr1 * 0.5 - cov.gr1
cov.gr2
> cov.gr2
RleList of length 2
$chr1
numeric-Rle of length 205 with 4 runs
  Lengths:    2    3   97  103
  Values :    0 -0.5   -1 -0.5

$chr2
numeric-Rle of length 48 with 3 runs
  Lengths:    8    2   38
  Values : -0.5   -1 -0.5
coverage genomicranges • 670 views
ADD COMMENTlink modified 3.5 years ago by Martin Morgan ♦♦ 23k • written 3.5 years ago by vanhzh0
Answer: How to set a negative coverage to ZERO
0
gravatar for Martin Morgan
3.5 years ago by
Martin Morgan ♦♦ 23k
United States
Martin Morgan ♦♦ 23k wrote:

Subset and replace as you might a regular vector

cov.gr2[cov.gr2 < 0] = 0
ADD COMMENTlink written 3.5 years ago by Martin Morgan ♦♦ 23k

Hi Martin Morgan,

Thank you very much for your help. This is exactly what I want!

ADD REPLYlink written 3.5 years ago by vanhzh0
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 147 users visited in the last hour