Hi there,
Here's a request that would let me skip a step or two once in a while: it's not a big deal, but it would be nice if it were possible. I'd like to be able to add names to my GRanges objects when I construct them, rather than adding them afterwards. It would be convenient sometimes to let me avoid creating temporary objects that I'd rather do without. I think the code below walks you through what I'm trying to do.
thanks for thinking about it!
Janet
##############
library(GenomicRanges)
### constructing a GRanges object and adding names afterwards works well:
myGR <- GRanges(seqnames=c("chr1","chr2"), ranges=IRanges(start=c(100,200), width=100))
names(myGR) <- c("region1","region2")
myGR
### but I can't add names when I construct the object. That gives me a column in values(myGR_2) called "names". Not quite what I wanted:
myGR_2 <- GRanges(seqnames=c("chr1","chr2"), ranges=IRanges(start=c(100,200), width=100), names=c("region1","region2"))
myGR_2
### one reason to want that is because sometimes I want to add to an existing GRanges object, and I'd like to be able to do that without creating extra interim objects. Here's just one example, but you could imagine wrapping the GRanges constructor in various other functions without wanting to add names in a separate step.
### I'd like to be able to do this in one step:
myGR_3 <- c( myGR, GRanges(seqnames=c("chr2","chr2"), ranges=IRanges(start=c(300,400),width=100), names=c("region3","region4")) )
### but instead I have to do it in three steps:
temp <- GRanges(seqnames=c("chr2","chr2"), ranges=IRanges(start=c(300,400),width=100))
names(temp) <- c("region3","region4")
myGR_3 <- c( myGR, temp)
sessionInfo()
#######
R version 3.2.2 (2015-08-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.2 LTS
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats4 parallel stats graphics grDevices utils datasets
[8] methods base
other attached packages:
[1] GenomicRanges_1.21.26 GenomeInfoDb_1.5.15 IRanges_2.3.21
[4] S4Vectors_0.7.18 BiocGenerics_0.15.6
loaded via a namespace (and not attached):
[1] zlibbioc_1.15.0 XVector_0.9.4
turns out it's easy: sorry that wasn't more obvious to me. Thanks!
turns out it's easy: sorry that wasn't more obvious to me. Thanks!