Any way to combine two GRangesList easily ?
2
0
Entering edit mode
@jurat-shahidin-9488
Last seen 4.7 years ago
Chicago, IL, USA

Dear all :

I have list of GRanges objects, and I intend to combine them to get new GRangesList respectively. I tried several possible way to make this happen, but none of them addressed my issue. Can anyone point me how to accomplish this task easily? How to combine GRangesList ? Any idea ? Thanks a lot

mini example :

myList_old <- GRangesList(
  foo = GRanges( seqnames=Rle("chr1", 3),ranges=IRanges(c(2,7,16), c(5,14,20)),
                  rangeName=c("a1", "a2", "a3"), score=c(4, 6,9)),
  bleh = GRanges(seqnames=Rle("chr1", 3),ranges=IRanges(c(4,13,26), c(11,17,28)),
                  rangeName=c("b1", "b2", "b3"), score=c(11, 7, 8))
)

myList_new <- GRangesList(
  foo = GRanges( seqnames=Rle("chr2", 3),ranges=IRanges(c(32,51,78), c(45,67,83)),
                 rangeName=c("a9", "a12", "a19"), score=c(34, 46,29)),
  bleh = GRanges(seqnames=Rle("chr3", 3),ranges=IRanges(c(53,83,106), c(71,97,128)),
                 rangeName=c("b51", "b72", "b93"), score=c(31, 17, 28))
)

my desired output would be  :

myFinal_grs <- GRangesList(
  foo = GRanges( seqnames=Rle(c("chr1", "chr2"), c(3,3)),ranges=IRanges(c(2,7,16,32,51,78), c(5,14,20,45,67,83)),
                 rangeName=c("a1", "a2", "a3","a9","a12","a19"), score=c(4, 6,9,34,46,29)),
  bleh = GRanges(seqnames=Rle(c("chr1","chr3"), c(3,3)),ranges=IRanges(c(4,13,26,53,83,106), c(71,97,128)),
                 rangeName=c("b1", "b2", "b3","b51","b72","b93"), score=c(11, 7, 8,31,17,28))
)

I intend to combine GRanges object from above list. Is there any way to get this done easily? 

Best regards:

Jurat

 

genomicranges grangeslist r • 1.7k views
ADD COMMENT
2
Entering edit mode
@michael-lawrence-3846
Last seen 3.0 years ago
United States
pc(myList_old, myList_new)

 

ADD COMMENT
0
Entering edit mode

Thanks your quick respond. Your solution also raised warning message. Should I suppress this warning? why this warning happen? 

ADD REPLY
0
Entering edit mode

Just make sure the seqlevels are the same between the two objects.

ADD REPLY
0
Entering edit mode
@jurat-shahidin-9488
Last seen 4.7 years ago
Chicago, IL, USA

I think I can try like this:

suppressWarnings(mapply(c, myList_old, myList_new))
ADD COMMENT

Login before adding your answer.

Traffic: 508 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