Entering edit mode
vanhzh
•
0
@vanhzh-9993
Last seen 5.1 years ago
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
Hi Martin Morgan,
Thank you very much for your help. This is exactly what I want!