IRanges merging query
1
0
Entering edit mode
@vishal-thapar-3427
Last seen 9.6 years ago
Hi All, I have a question about how to merge / have a union of 2 RangeData objects Say I have a rangeData1 head(rangeData1) RangedData with 6 rows and 0 value columns across 25 spaces space ranges | <character> <iranges> | 1 chr1 [ 101, 283] | 2 chr1 [ 704, 710] | 3 chr1 [ 310, 450] | 4 chr2 [ 582, 635] | 5 chr3 [ 422, 548] | 6 chr4 [ 40, 128] | and another head(rangeData2) RangedData with 6 rows and 0 value columns across 25 spaces space ranges | <character> <iranges> | 1 chr1 [ 90, 200] | 2 chr1 [ 600, 650] | 3 chr1 [ 306, 384] | 4 chr2 [ 650, 690] | 5 chr3 [ 315, 697] | 6 chr5 [ 140, 228] | Would it be possible to merge these two so that I get something like this: RangeData3 RangedData with 7 rows and 0 value columns across 25 spaces space ranges | <character> <iranges> | 1 chr1 [ 90, 283] | 2 chr1 [ 600, 710] | 3 chr1 [ 306, 450] | 4 chr2 [ 582, 690] | 5 chr3 [ 315, 697] | 6 chr4 [ 40, 128] | 7 chr5 [ 140, 228] | Thanks for the help! Sincerely, Vishal [[alternative HTML version deleted]]
• 2.0k views
ADD COMMENT
0
Entering edit mode
@kasper-daniel-hansen-2979
Last seen 10 months ago
United States
ir1, ir2 are your IRanges do reduce(c(ir1, ir2)) Kasper On Fri, Nov 12, 2010 at 2:49 PM, Vishal Thapar <vishalthapar at="" gmail.com=""> wrote: > Hi All, > > I have a question about how to merge / have a union of 2 RangeData objects > Say I have a rangeData1 > head(rangeData1) > RangedData with 6 rows and 0 value columns across 25 spaces > ? ? ? ?space ? ? ? ? ? ? ranges | > ?<character> ? ? ? ? ?<iranges> | > 1 ? ? ? ? ? chr1 [ ? ?101, ? ? 283] | > 2 ? ? ? ? ? chr1 [ ? ?704, ? ? 710] | > 3 ? ? ? ? ? chr1 [ ? ?310, ? ? 450] | > 4 ? ? ? ? ? chr2 [ ? ?582, ? ? 635] | > 5 ? ? ? ? ? chr3 [ ? ?422, ? ? 548] | > 6 ? ? ? ? ? chr4 [ ? ? ?40, ?128] | > > and another > > head(rangeData2) > RangedData with 6 rows and 0 value columns across 25 spaces > ? ? ? ?space ? ? ? ? ? ? ranges | > ?<character> ? ? ? ? ?<iranges> | > 1 ? ? ? ? ? chr1 [ ? ?90, ? ? 200] | > 2 ? ? ? ? ? chr1 [ ? ?600, ?650] | > 3 ? ? ? ? ? chr1 [ ? ?306, ?384] | > 4 ? ? ? ? ? chr2 [ ? ?650, ? 690] | > 5 ? ? ? ? ? chr3 [ ? ?315, ? 697] | > 6 ? ? ? ? ? chr5 [ ? ?140, ? 228] | > > Would it be possible to merge these two so that I get something like this: > RangeData3 > RangedData with 7 rows and 0 value columns across 25 spaces > ? ? ? ?space ? ? ? ? ? ? ranges | > ?<character> ? ? ? ? ?<iranges> | > 1 ? ? ? ? ? chr1 [ ? ?90, ? ? 283] | > 2 ? ? ? ? ? chr1 [ ? ?600, ?710] | > 3 ? ? ? ? ? chr1 [ ? ?306, ?450] | > 4 ? ? ? ? ? chr2 [ ? ?582, ? 690] | > 5 ? ? ? ? ? chr3 [ ? ?315, ? 697] | > 6 ? ? ? ? ? chr4 [ ? ? ?40, ?128] | > 7 ? ? ? ? ? chr5 [ ? ?140, ? 228] | > > > Thanks for the help! > > Sincerely, > > Vishal > > ? ? ? ?[[alternative HTML version deleted]] > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >
ADD COMMENT
0
Entering edit mode
Hi Kasper, Thank you for replying back. I had tried this earlier, but what I get is not what I expected. I sort of wanted to "merge" the ranges for each "chr" value. So I want to ranges in Chr1 to be merged separately from Chr2 and so on. What I Get is: > abc.chr=c("chr1","chr1","chr1","chr2","chr3","chr4") > abc.start=c(101,704,310,582,422,40) > abc.end = c(283,710,450,635,548,128) > > def.chr=c("chr1","chr1","chr1","chr2","chr3","chr5") > def.start=c(90,600,306,650,315,140) > def.end=c(200,650,384,690,697,228) > > I1 <- IRanges(start = abc.start, end = abc.end, names=abc.chr) > I2<- IRanges(start = def.start, end = def.end, names=def.chr) > > I1 IRanges of length 6 start end width names [1] 101 283 183 chr1 [2] 704 710 7 chr1 [3] 310 450 141 chr1 [4] 582 635 54 chr2 [5] 422 548 127 chr3 [6] 40 128 89 chr4 > I2 IRanges of length 6 start end width names [1] 90 200 111 chr1 [2] 600 650 51 chr1 [3] 306 384 79 chr1 [4] 650 690 41 chr2 [5] 315 697 383 chr3 [6] 140 228 89 chr5 > > xyz<- reduce(c(I1,I2)) > xyz IRanges of length 3 start end width [1] 40 283 244 [2] 306 697 392 [3] 704 710 7 What I would like is : xyz IRanges of length 7 start end width names [1] 90 283 194 chr1 [2] 600 710 111 chr1 [3] 306 450 145 chr1 [4] 582 690 108 chr2 [5] 315 697 383 chr3 [6] 40 128 89 chr4 [7] 140 228 89 chr5 This doesn't take the "names" into account while reducing / merging. Is there a way to have that taken into account while merging? Thanks again for your help. -vishal On Fri, Nov 12, 2010 at 2:55 PM, Kasper Daniel Hansen < kasperdanielhansen@gmail.com> wrote: > ir1, ir2 are your IRanges > > do > reduce(c(ir1, ir2)) > > Kasper > > On Fri, Nov 12, 2010 at 2:49 PM, Vishal Thapar <vishalthapar@gmail.com> > wrote: > > Hi All, > > > > I have a question about how to merge / have a union of 2 RangeData > objects > > Say I have a rangeData1 > > head(rangeData1) > > RangedData with 6 rows and 0 value columns across 25 spaces > > space ranges | > > <character> <iranges> | > > 1 chr1 [ 101, 283] | > > 2 chr1 [ 704, 710] | > > 3 chr1 [ 310, 450] | > > 4 chr2 [ 582, 635] | > > 5 chr3 [ 422, 548] | > > 6 chr4 [ 40, 128] | > > > > and another > > > > head(rangeData2) > > RangedData with 6 rows and 0 value columns across 25 spaces > > space ranges | > > <character> <iranges> | > > 1 chr1 [ 90, 200] | > > 2 chr1 [ 600, 650] | > > 3 chr1 [ 306, 384] | > > 4 chr2 [ 650, 690] | > > 5 chr3 [ 315, 697] | > > 6 chr5 [ 140, 228] | > > > > Would it be possible to merge these two so that I get something like > this: > > RangeData3 > > RangedData with 7 rows and 0 value columns across 25 spaces > > space ranges | > > <character> <iranges> | > > 1 chr1 [ 90, 283] | > > 2 chr1 [ 600, 710] | > > 3 chr1 [ 306, 450] | > > 4 chr2 [ 582, 690] | > > 5 chr3 [ 315, 697] | > > 6 chr4 [ 40, 128] | > > 7 chr5 [ 140, 228] | > > > > > > Thanks for the help! > > > > Sincerely, > > > > Vishal > > > > [[alternative HTML version deleted]] > > > > _______________________________________________ > > Bioconductor mailing list > > Bioconductor@stat.math.ethz.ch > > https://stat.ethz.ch/mailman/listinfo/bioconductor > > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor > > > [[alternative HTML version deleted]]
ADD REPLY
0
Entering edit mode
Hi Vishal, I think you want to do pairwise union. You can use punion() for this. Cheers, H. On 11/12/2010 12:18 PM, Vishal Thapar wrote: > Hi Kasper, > > Thank you for replying back. I had tried this earlier, but what I get is not > what I expected. I sort of wanted to "merge" the ranges for each "chr" > value. So I want to ranges in Chr1 to be merged separately from Chr2 and so > on. What I Get is: > >> abc.chr=c("chr1","chr1","chr1","chr2","chr3","chr4") >> abc.start=c(101,704,310,582,422,40) >> abc.end = c(283,710,450,635,548,128) >> >> def.chr=c("chr1","chr1","chr1","chr2","chr3","chr5") >> def.start=c(90,600,306,650,315,140) >> def.end=c(200,650,384,690,697,228) >> >> I1<- IRanges(start = abc.start, end = abc.end, names=abc.chr) >> I2<- IRanges(start = def.start, end = def.end, names=def.chr) >> >> I1 > IRanges of length 6 > start end width names > [1] 101 283 183 chr1 > [2] 704 710 7 chr1 > [3] 310 450 141 chr1 > [4] 582 635 54 chr2 > [5] 422 548 127 chr3 > [6] 40 128 89 chr4 >> I2 > IRanges of length 6 > start end width names > [1] 90 200 111 chr1 > [2] 600 650 51 chr1 > [3] 306 384 79 chr1 > [4] 650 690 41 chr2 > [5] 315 697 383 chr3 > [6] 140 228 89 chr5 >> >> xyz<- reduce(c(I1,I2)) >> xyz > IRanges of length 3 > start end width > [1] 40 283 244 > [2] 306 697 392 > [3] 704 710 7 > > > What I would like is : > xyz > IRanges of length 7 > start end width names > [1] 90 283 194 chr1 > [2] 600 710 111 chr1 > [3] 306 450 145 chr1 > [4] 582 690 108 chr2 > [5] 315 697 383 chr3 > [6] 40 128 89 chr4 > [7] 140 228 89 chr5 > > > This doesn't take the "names" into account while reducing / merging. Is > there a way to have that taken into account while merging? > > Thanks again for your help. > > -vishal > > On Fri, Nov 12, 2010 at 2:55 PM, Kasper Daniel Hansen< > kasperdanielhansen at gmail.com> wrote: > >> ir1, ir2 are your IRanges >> >> do >> reduce(c(ir1, ir2)) >> >> Kasper >> >> On Fri, Nov 12, 2010 at 2:49 PM, Vishal Thapar<vishalthapar at="" gmail.com=""> >> wrote: >>> Hi All, >>> >>> I have a question about how to merge / have a union of 2 RangeData >> objects >>> Say I have a rangeData1 >>> head(rangeData1) >>> RangedData with 6 rows and 0 value columns across 25 spaces >>> space ranges | >>> <character> <iranges> | >>> 1 chr1 [ 101, 283] | >>> 2 chr1 [ 704, 710] | >>> 3 chr1 [ 310, 450] | >>> 4 chr2 [ 582, 635] | >>> 5 chr3 [ 422, 548] | >>> 6 chr4 [ 40, 128] | >>> >>> and another >>> >>> head(rangeData2) >>> RangedData with 6 rows and 0 value columns across 25 spaces >>> space ranges | >>> <character> <iranges> | >>> 1 chr1 [ 90, 200] | >>> 2 chr1 [ 600, 650] | >>> 3 chr1 [ 306, 384] | >>> 4 chr2 [ 650, 690] | >>> 5 chr3 [ 315, 697] | >>> 6 chr5 [ 140, 228] | >>> >>> Would it be possible to merge these two so that I get something like >> this: >>> RangeData3 >>> RangedData with 7 rows and 0 value columns across 25 spaces >>> space ranges | >>> <character> <iranges> | >>> 1 chr1 [ 90, 283] | >>> 2 chr1 [ 600, 710] | >>> 3 chr1 [ 306, 450] | >>> 4 chr2 [ 582, 690] | >>> 5 chr3 [ 315, 697] | >>> 6 chr4 [ 40, 128] | >>> 7 chr5 [ 140, 228] | >>> >>> >>> Thanks for the help! >>> >>> Sincerely, >>> >>> Vishal >>> >>> [[alternative HTML version deleted]] >>> >>> _______________________________________________ >>> Bioconductor mailing list >>> Bioconductor at stat.math.ethz.ch >>> https://stat.ethz.ch/mailman/listinfo/bioconductor >>> Search the archives: >> http://news.gmane.org/gmane.science.biology.informatics.conductor >>> >> > > [[alternative HTML version deleted]] > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor -- Hervé Pagès Program in Computational Biology Division of Public Health Sciences Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N, M2-B876 P.O. Box 19024 Seattle, WA 98109-1024 E-mail: hpages at fhcrc.org Phone: (206) 667-5791 Fax: (206) 667-1319
ADD REPLY
0
Entering edit mode
Thanks Herve'. That comes the closest to the answer but it still misses the values for which there is no pair on one of the sets. This is what I get: > punion(I1,I2) Error in .local(x, y, ...) : some pair of ranges have a gap within the 2 members of the pair. Use 'fill.gap=TRUE' to enforce their union by filling the gap. > > punion(I1,I2, fill.gap=TRUE) IRanges of length 6 start end width names [1] 90 283 194 chr1 [2] 600 710 111 chr1 [3] 306 450 145 chr1 [4] 582 690 109 chr2 [5] 315 697 383 chr3 [6] 40 228 189 chr4 The last one is still missing. Any suggestions? -v 2010/11/12 Hervé Pagès <hpages@fhcrc.org> > Hi Vishal, > > I think you want to do pairwise union. You can use punion() for this. > > Cheers, > H. > > > > On 11/12/2010 12:18 PM, Vishal Thapar wrote: > >> Hi Kasper, >> >> Thank you for replying back. I had tried this earlier, but what I get is >> not >> what I expected. I sort of wanted to "merge" the ranges for each "chr" >> value. So I want to ranges in Chr1 to be merged separately from Chr2 and >> so >> on. What I Get is: >> >> abc.chr=c("chr1","chr1","chr1","chr2","chr3","chr4") >>> abc.start=c(101,704,310,582,422,40) >>> abc.end = c(283,710,450,635,548,128) >>> >>> def.chr=c("chr1","chr1","chr1","chr2","chr3","chr5") >>> def.start=c(90,600,306,650,315,140) >>> def.end=c(200,650,384,690,697,228) >>> >>> I1<- IRanges(start = abc.start, end = abc.end, names=abc.chr) >>> I2<- IRanges(start = def.start, end = def.end, names=def.chr) >>> >>> I1 >>> >> IRanges of length 6 >> start end width names >> [1] 101 283 183 chr1 >> [2] 704 710 7 chr1 >> [3] 310 450 141 chr1 >> [4] 582 635 54 chr2 >> [5] 422 548 127 chr3 >> [6] 40 128 89 chr4 >> >>> I2 >>> >> IRanges of length 6 >> start end width names >> [1] 90 200 111 chr1 >> [2] 600 650 51 chr1 >> [3] 306 384 79 chr1 >> [4] 650 690 41 chr2 >> [5] 315 697 383 chr3 >> [6] 140 228 89 chr5 >> >>> >>> xyz<- reduce(c(I1,I2)) >>> xyz >>> >> IRanges of length 3 >> start end width >> [1] 40 283 244 >> [2] 306 697 392 >> [3] 704 710 7 >> >> >> What I would like is : >> xyz >> IRanges of length 7 >> start end width names >> [1] 90 283 194 chr1 >> [2] 600 710 111 chr1 >> [3] 306 450 145 chr1 >> [4] 582 690 108 chr2 >> [5] 315 697 383 chr3 >> [6] 40 128 89 chr4 >> [7] 140 228 89 chr5 >> >> >> This doesn't take the "names" into account while reducing / merging. Is >> there a way to have that taken into account while merging? >> >> Thanks again for your help. >> >> -vishal >> >> On Fri, Nov 12, 2010 at 2:55 PM, Kasper Daniel Hansen< >> kasperdanielhansen@gmail.com> wrote: >> >> ir1, ir2 are your IRanges >>> >>> do >>> reduce(c(ir1, ir2)) >>> >>> Kasper >>> >>> On Fri, Nov 12, 2010 at 2:49 PM, Vishal Thapar<vishalthapar@gmail.com> >>> wrote: >>> >>>> Hi All, >>>> >>>> I have a question about how to merge / have a union of 2 RangeData >>>> >>> objects >>> >>>> Say I have a rangeData1 >>>> head(rangeData1) >>>> RangedData with 6 rows and 0 value columns across 25 spaces >>>> space ranges | >>>> <character> <iranges> | >>>> 1 chr1 [ 101, 283] | >>>> 2 chr1 [ 704, 710] | >>>> 3 chr1 [ 310, 450] | >>>> 4 chr2 [ 582, 635] | >>>> 5 chr3 [ 422, 548] | >>>> 6 chr4 [ 40, 128] | >>>> >>>> and another >>>> >>>> head(rangeData2) >>>> RangedData with 6 rows and 0 value columns across 25 spaces >>>> space ranges | >>>> <character> <iranges> | >>>> 1 chr1 [ 90, 200] | >>>> 2 chr1 [ 600, 650] | >>>> 3 chr1 [ 306, 384] | >>>> 4 chr2 [ 650, 690] | >>>> 5 chr3 [ 315, 697] | >>>> 6 chr5 [ 140, 228] | >>>> >>>> Would it be possible to merge these two so that I get something like >>>> >>> this: >>> >>>> RangeData3 >>>> RangedData with 7 rows and 0 value columns across 25 spaces >>>> space ranges | >>>> <character> <iranges> | >>>> 1 chr1 [ 90, 283] | >>>> 2 chr1 [ 600, 710] | >>>> 3 chr1 [ 306, 450] | >>>> 4 chr2 [ 582, 690] | >>>> 5 chr3 [ 315, 697] | >>>> 6 chr4 [ 40, 128] | >>>> 7 chr5 [ 140, 228] | >>>> >>>> >>>> Thanks for the help! >>>> >>>> Sincerely, >>>> >>>> Vishal >>>> >>>> [[alternative HTML version deleted]] >>>> >>>> _______________________________________________ >>>> Bioconductor mailing list >>>> Bioconductor@stat.math.ethz.ch >>>> https://stat.ethz.ch/mailman/listinfo/bioconductor >>>> Search the archives: >>>> >>> http://news.gmane.org/gmane.science.biology.informatics.conductor >>> >>>> >>>> >>> >> [[alternative HTML version deleted]] >> >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor@stat.math.ethz.ch >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: >> http://news.gmane.org/gmane.science.biology.informatics.conductor >> > > > -- > Hervé Pagès > > Program in Computational Biology > Division of Public Health Sciences > Fred Hutchinson Cancer Research Center > 1100 Fairview Ave. N, M2-B876 > P.O. Box 19024 > Seattle, WA 98109-1024 > > E-mail: hpages@fhcrc.org > Phone: (206) 667-5791 > Fax: (206) 667-1319 > -- *Vishal Thapar, Ph.D.* *Scientific informatics Analyst Cold Spring Harbor Lab Quick Bldg, Lowe Lab 1 Bungtown Road Cold Spring Harbor, NY - 11724* [[alternative HTML version deleted]]
ADD REPLY
0
Entering edit mode
On Fri, Nov 12, 2010 at 12:18 PM, Vishal Thapar <vishalthapar@gmail.com>wrote: > Hi Kasper, > > Thank you for replying back. I had tried this earlier, but what I get is > not > what I expected. I sort of wanted to "merge" the ranges for each "chr" > value. So I want to ranges in Chr1 to be merged separately from Chr2 and so > on. What I Get is: > > > abc.chr=c("chr1","chr1","chr1","chr2","chr3","chr4") > > abc.start=c(101,704,310,582,422,40) > > abc.end = c(283,710,450,635,548,128) > > > > def.chr=c("chr1","chr1","chr1","chr2","chr3","chr5") > > def.start=c(90,600,306,650,315,140) > > def.end=c(200,650,384,690,697,228) > > > > I1 <- IRanges(start = abc.start, end = abc.end, names=abc.chr) > > I2<- IRanges(start = def.start, end = def.end, names=def.chr) > > > > I1 > IRanges of length 6 > start end width names > [1] 101 283 183 chr1 > [2] 704 710 7 chr1 > [3] 310 450 141 chr1 > [4] 582 635 54 chr2 > [5] 422 548 127 chr3 > [6] 40 128 89 chr4 > > I2 > IRanges of length 6 > start end width names > [1] 90 200 111 chr1 > [2] 600 650 51 chr1 > [3] 306 384 79 chr1 > [4] 650 690 41 chr2 > [5] 315 697 383 chr3 > [6] 140 228 89 chr5 > > > > xyz<- reduce(c(I1,I2)) > > xyz > IRanges of length 3 > start end width > [1] 40 283 244 > [2] 306 697 392 > [3] 704 710 7 > > > What I would like is : > xyz > IRanges of length 7 > start end width names > [1] 90 283 194 chr1 > [2] 600 710 111 chr1 > [3] 306 450 145 chr1 > [4] 582 690 108 chr2 > [5] 315 697 383 chr3 > [6] 40 128 89 chr4 > [7] 140 228 89 chr5 > > > This doesn't take the "names" into account while reducing / merging. Is > there a way to have that taken into account while merging? > > Yes, RangedData takes that into account. So you could do reduce(rbind(rangedData1, rangedData2)) To get out a RangedData of your merged ranges. Btw, Kasper's code works for GRanges but not IRanges. > Thanks again for your help. > > -vishal > > On Fri, Nov 12, 2010 at 2:55 PM, Kasper Daniel Hansen < > kasperdanielhansen@gmail.com> wrote: > > > ir1, ir2 are your IRanges > > > > do > > reduce(c(ir1, ir2)) > > > > Kasper > > > > On Fri, Nov 12, 2010 at 2:49 PM, Vishal Thapar <vishalthapar@gmail.com> > > wrote: > > > Hi All, > > > > > > I have a question about how to merge / have a union of 2 RangeData > > objects > > > Say I have a rangeData1 > > > head(rangeData1) > > > RangedData with 6 rows and 0 value columns across 25 spaces > > > space ranges | > > > <character> <iranges> | > > > 1 chr1 [ 101, 283] | > > > 2 chr1 [ 704, 710] | > > > 3 chr1 [ 310, 450] | > > > 4 chr2 [ 582, 635] | > > > 5 chr3 [ 422, 548] | > > > 6 chr4 [ 40, 128] | > > > > > > and another > > > > > > head(rangeData2) > > > RangedData with 6 rows and 0 value columns across 25 spaces > > > space ranges | > > > <character> <iranges> | > > > 1 chr1 [ 90, 200] | > > > 2 chr1 [ 600, 650] | > > > 3 chr1 [ 306, 384] | > > > 4 chr2 [ 650, 690] | > > > 5 chr3 [ 315, 697] | > > > 6 chr5 [ 140, 228] | > > > > > > Would it be possible to merge these two so that I get something like > > this: > > > RangeData3 > > > RangedData with 7 rows and 0 value columns across 25 spaces > > > space ranges | > > > <character> <iranges> | > > > 1 chr1 [ 90, 283] | > > > 2 chr1 [ 600, 710] | > > > 3 chr1 [ 306, 450] | > > > 4 chr2 [ 582, 690] | > > > 5 chr3 [ 315, 697] | > > > 6 chr4 [ 40, 128] | > > > 7 chr5 [ 140, 228] | > > > > > > > > > Thanks for the help! > > > > > > Sincerely, > > > > > > Vishal > > > > > > [[alternative HTML version deleted]] > > > > > > _______________________________________________ > > > Bioconductor mailing list > > > Bioconductor@stat.math.ethz.ch > > > https://stat.ethz.ch/mailman/listinfo/bioconductor > > > Search the archives: > > http://news.gmane.org/gmane.science.biology.informatics.conductor > > > > > > > [[alternative HTML version deleted]] > > _______________________________________________ > Bioconductor mailing list > Bioconductor@stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor > [[alternative HTML version deleted]]
ADD REPLY
0
Entering edit mode
Thanks so much! It works great! -vishal On Fri, Nov 12, 2010 at 4:53 PM, Michael Lawrence <lawrence.michael@gene.com> wrote: > > > On Fri, Nov 12, 2010 at 12:18 PM, Vishal Thapar <vishalthapar@gmail.com>wrote: > >> Hi Kasper, >> >> Thank you for replying back. I had tried this earlier, but what I get is >> not >> what I expected. I sort of wanted to "merge" the ranges for each "chr" >> value. So I want to ranges in Chr1 to be merged separately from Chr2 and >> so >> on. What I Get is: >> >> > abc.chr=c("chr1","chr1","chr1","chr2","chr3","chr4") >> > abc.start=c(101,704,310,582,422,40) >> > abc.end = c(283,710,450,635,548,128) >> > >> > def.chr=c("chr1","chr1","chr1","chr2","chr3","chr5") >> > def.start=c(90,600,306,650,315,140) >> > def.end=c(200,650,384,690,697,228) >> > >> > I1 <- IRanges(start = abc.start, end = abc.end, names=abc.chr) >> > I2<- IRanges(start = def.start, end = def.end, names=def.chr) >> > >> > I1 >> IRanges of length 6 >> start end width names >> [1] 101 283 183 chr1 >> [2] 704 710 7 chr1 >> [3] 310 450 141 chr1 >> [4] 582 635 54 chr2 >> [5] 422 548 127 chr3 >> [6] 40 128 89 chr4 >> > I2 >> IRanges of length 6 >> start end width names >> [1] 90 200 111 chr1 >> [2] 600 650 51 chr1 >> [3] 306 384 79 chr1 >> [4] 650 690 41 chr2 >> [5] 315 697 383 chr3 >> [6] 140 228 89 chr5 >> > >> > xyz<- reduce(c(I1,I2)) >> > xyz >> IRanges of length 3 >> start end width >> [1] 40 283 244 >> [2] 306 697 392 >> [3] 704 710 7 >> >> >> What I would like is : >> xyz >> IRanges of length 7 >> start end width names >> [1] 90 283 194 chr1 >> [2] 600 710 111 chr1 >> [3] 306 450 145 chr1 >> [4] 582 690 108 chr2 >> [5] 315 697 383 chr3 >> [6] 40 128 89 chr4 >> [7] 140 228 89 chr5 >> >> >> This doesn't take the "names" into account while reducing / merging. Is >> there a way to have that taken into account while merging? >> >> > Yes, RangedData takes that into account. So you could do > > reduce(rbind(rangedData1, rangedData2)) > > To get out a RangedData of your merged ranges. > > Btw, Kasper's code works for GRanges but not IRanges. > > >> Thanks again for your help. >> >> -vishal >> >> On Fri, Nov 12, 2010 at 2:55 PM, Kasper Daniel Hansen < >> kasperdanielhansen@gmail.com> wrote: >> >> > ir1, ir2 are your IRanges >> > >> > do >> > reduce(c(ir1, ir2)) >> > >> > Kasper >> > >> > On Fri, Nov 12, 2010 at 2:49 PM, Vishal Thapar <vishalthapar@gmail.com> >> > wrote: >> > > Hi All, >> > > >> > > I have a question about how to merge / have a union of 2 RangeData >> > objects >> > > Say I have a rangeData1 >> > > head(rangeData1) >> > > RangedData with 6 rows and 0 value columns across 25 spaces >> > > space ranges | >> > > <character> <iranges> | >> > > 1 chr1 [ 101, 283] | >> > > 2 chr1 [ 704, 710] | >> > > 3 chr1 [ 310, 450] | >> > > 4 chr2 [ 582, 635] | >> > > 5 chr3 [ 422, 548] | >> > > 6 chr4 [ 40, 128] | >> > > >> > > and another >> > > >> > > head(rangeData2) >> > > RangedData with 6 rows and 0 value columns across 25 spaces >> > > space ranges | >> > > <character> <iranges> | >> > > 1 chr1 [ 90, 200] | >> > > 2 chr1 [ 600, 650] | >> > > 3 chr1 [ 306, 384] | >> > > 4 chr2 [ 650, 690] | >> > > 5 chr3 [ 315, 697] | >> > > 6 chr5 [ 140, 228] | >> > > >> > > Would it be possible to merge these two so that I get something like >> > this: >> > > RangeData3 >> > > RangedData with 7 rows and 0 value columns across 25 spaces >> > > space ranges | >> > > <character> <iranges> | >> > > 1 chr1 [ 90, 283] | >> > > 2 chr1 [ 600, 710] | >> > > 3 chr1 [ 306, 450] | >> > > 4 chr2 [ 582, 690] | >> > > 5 chr3 [ 315, 697] | >> > > 6 chr4 [ 40, 128] | >> > > 7 chr5 [ 140, 228] | >> > > >> > > >> > > Thanks for the help! >> > > >> > > Sincerely, >> > > >> > > Vishal >> > > >> > > [[alternative HTML version deleted]] >> > > >> > > _______________________________________________ >> > > Bioconductor mailing list >> > > Bioconductor@stat.math.ethz.ch >> > > https://stat.ethz.ch/mailman/listinfo/bioconductor >> > > Search the archives: >> > http://news.gmane.org/gmane.science.biology.informatics.conductor >> > > >> > >> >> [[alternative HTML version deleted]] >> >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor@stat.math.ethz.ch >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: >> http://news.gmane.org/gmane.science.biology.informatics.conductor >> > > -- *Vishal Thapar, Ph.D.* *Scientific informatics Analyst Cold Spring Harbor Lab Quick Bldg, Lowe Lab 1 Bungtown Road Cold Spring Harbor, NY - 11724* [[alternative HTML version deleted]]
ADD REPLY

Login before adding your answer.

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