Question: request: calculate coverage with weight on RangedData object
0
9.6 years ago by
Janet Young730
Fred Hutchinson Cancer Research Center, Seattle, WA, USA
Janet Young730 wrote:
Hi, I'm trying to calculate coverage using weights on a RangedData object (seems to work for simple IRanges objects, but not on RangedData). I've found a workaround, but wanted to request an enhancement to be able to do this directly without the workaround. I think the code below should show you what I'm talking about. thanks very much, Janet Young ------------------------------------------------------------------- Dr. Janet Young (Trask lab) Fred Hutchinson Cancer Research Center 1100 Fairview Avenue N., C3-168, P.O. Box 19024, Seattle, WA 98109-1024, USA. tel: (206) 667 1471 fax: (206) 667 6524 email: jayoung ...at... fhcrc.org http://www.fhcrc.org/labs/trask/ ------------------------------------------------------------------- library(IRanges) ### coverage with weights works for IRanges object x <- IRanges(start=1:5,end=3:7) coverage(x,weight=1:5) ### 'integer' Rle of length 7 with 7 runs ### Lengths: 1 1 1 1 1 1 1 ### Values : 1 3 6 9 12 9 5 ### but is not so well on RangedData y <- RangedData(IRanges(start=c(1:5,1:5),end=c(3:7,3:7)), space=c(rep("chrA",5),rep("chrB",5)), score=c(1:5,1:5) ) coverage(y) ## works, produces SimpleRleList coverage(y,weight=y$score) ## does not work ### Error in weight[[i]] : subscript out of bounds coverage(y,weight=rep(1,10)) ## does not work ### Error in weight[[i]] : subscript out of bounds ### temporary workaround - iterate through spaces mycov <- list() for (thisspace in names(y)) { mycov[[thisspace]] <- coverage(ranges(y[thisspace]) [[1]],weight=y[thisspace]$score) } mycov ### $chrA ### 'integer' Rle of length 7 with 7 runs ### Lengths: 1 1 1 1 1 1 1 ### Values : 1 3 6 9 12 9 5 ### ###$chrB ### 'integer' Rle of length 7 with 7 runs ### Lengths: 1 1 1 1 1 1 1 ### Values : 1 3 6 9 12 9 5 sessionInfo() R version 2.10.1 (2009-12-14) i386-apple-darwin8.11.1 locale: [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] IRanges_1.4.15
coverage cancer iranges • 597 views