[BioC] IRanges merging query

Hervé Pagès hpages at fhcrc.org
Fri Nov 12 21:42:20 CET 2010


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



More information about the Bioconductor mailing list