[BioC] Adding names to a IRanges object
Patrick Aboyoun
paboyoun at fhcrc.org
Fri Jan 23 17:32:22 CET 2009
Daniel,
IRanges objects do support names and they can be added using the
"names<-" replacement function.
> suppressMessages(library(IRanges))
> myranges <- IRanges(start = c(1,3,5,7), end = c(2,4,8,9))
> names(myranges) <- c("a", "b", "c", "d")
> myranges
IRanges object:
start end width names
1 1 2 2 a
2 3 4 2 b
3 5 8 4 c
4 7 9 3 d
> myranges[c("c", "a", "d", "b")]
IRanges object:
start end width names
1 5 8 4 c
2 1 2 2 a
3 7 9 3 d
4 3 4 2 b
> sessionInfo()
R version 2.9.0 Under development (unstable) (2009-01-19 r47650)
i386-apple-darwin9.6.0
locale:
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.1.34
loaded via a namespace (and not attached):
[1] grid_2.9.0 lattice_0.17-20 Matrix_0.999375-18
Daniel Brewer wrote:
> Hello,
>
> Is there any way to add rownames to an IRanges object? What I am trying
> to do is try and make it easy to reference back to the original table
> that created the IRanges object after an overlap.
>
> Hs1plus <- with(HsapiensAnnot[HsapiensAnnot$seqname == "1" &
> HsapiensAnnot$strand == "+",], IRanges(start, end))
>
> yoda1plus <- with(yip[yip$seqname == "chr1" & yip$strand == "+",],
> IRanges(start, end))
> yoda1plus <- yoda1plus[order(start(yoda1plus)),]
>
> seqoverlap <- overlap(Hs1plus,yoda1plus,multiple=F)
>
> At the moment to get information about the overlaps I have to do
> something like:
> HsapiensAnnot[HsapiensAnnot$start == start(Hs1plus[seqoverlap[1],]) &
> HsapiensAnnot$seqname=="1",]
>
> but I am sure that there is a better way and this can't deal with the
> NAs that might be in seqoverlap
>
> Thanks
>
> Dan
>
More information about the Bioconductor
mailing list