Adding names to a IRanges object
2
0
Entering edit mode
Daniel Brewer ★ 1.9k
@daniel-brewer-1791
Last seen 10.3 years ago
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 -- ************************************************************** Daniel Brewer, Ph.D. Institute of Cancer Research Molecular Carcinogenesis Email: daniel.brewer at icr.ac.uk ************************************************************** The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company Limited by Guarantee, Registered in England under Company No. 534147 with its Registered Office at 123 Old Brompton Road, London SW7 3RP. This e-mail message is confidential and for use by the a...{{dropped:2}}
Cancer IRanges Cancer IRanges • 1.0k views
ADD COMMENT
0
Entering edit mode
Patrick Aboyoun ★ 1.6k
@patrick-aboyoun-6734
Last seen 10.3 years ago
United States
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 >
ADD COMMENT
0
Entering edit mode
@michael-lawrence-2759
Last seen 10.3 years ago
On Fri, Jan 23, 2009 at 2:30 AM, Daniel Brewer <daniel.brewer@icr.ac.uk>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 > Patrick answered the names question, but I'd also like to suggest using RangedData here. It looks like you're getting your data from a GFF file. With rtracklayer, you could import() this directly into a RangedData. This would make things a fair bit easier: yoda1plus <- ranges(yip[strand(yip) == "+",]) ans <- HsapiensAnnot[strand(HsapiensAnnot) == "+",][yoda1plus] 'ans' would contain the RangedData with the annotations on the positive strand, that overlap with the IRanges yoda1plus, across all chromosomes. Couple of caveats: - the chromosomes should be named the same between the two datasets (eg of the form chr1). - the ranges in yip should have been sorted - requires development versions of IRanges and rtracklayer Michael > Thanks > > Dan > -- > ************************************************************** > Daniel Brewer, Ph.D. > > Institute of Cancer Research > Molecular Carcinogenesis > Email: daniel.brewer@icr.ac.uk > ************************************************************** > > The Institute of Cancer Research: Royal Cancer Hospital, a charitable > Company Limited by Guarantee, Registered in England under Company No. 534147 > with its Registered Office at 123 Old Brompton Road, London SW7 3RP. > > This e-mail message is confidential and for use by the...{{dropped:13}}
ADD COMMENT

Login before adding your answer.

Traffic: 605 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6