[BioC] subsetting IntegerList by list names

Martin Morgan mtmorgan at fhcrc.org
Wed Nov 16 19:02:07 CET 2011


On 11/16/2011 09:25 AM, Steve Lianoglou wrote:
> Hi,
>
> On Wed, Nov 16, 2011 at 12:09 PM, Martin Morgan<mtmorgan at fhcrc.org>  wrote:
>> On 11/16/2011 03:47 AM, Manuela Hummel wrote:
>>>
>>> Hi,
>>>
>>> I realized that subsetting an IntegerList object (and probably other
>>> IRanges list objects) by the list names plus replacing list element values
>>> behaves unexpectedly (at least for me) when the list is not sorted by its
>>> element's names.
>>>
>>> Here a short example:
>>>
>>>> IL<- IntegerList(chr2=5, chr1=10)
>>>
>>>> IL
>>>
>>> CompressedIntegerList of length 2
>>> [["chr2"]] 5
>>> [["chr1"]] 10
>>>
>>> Now I want to subset based on the list names:
>>>
>>>> chrs<- c("chr1", "chr2")
>>>
>>>> IL[chrs]
>>>
>>> CompressedIntegerList of length 2
>>> [["chr1"]] 10
>>> [["chr2"]] 5
>>>
>>> This gives me the elements in the expected order.
>>>
>>> However, if I now want to replace the values of both elements, using the
>>> subsetting as before, the order of the list and the new element values is
>>> "mixed":
>>>
>>>> IL[chrs]<- list(100, 50)
>>>
>>>> IL
>>>
>>> CompressedNumericList of length 2
>>> [["chr2"]] 100
>>> [["chr1"]] 50
>>>
>>> I would have expected the value 100 for element "chr1" and 50 for element
>>> "chr2".
>>>
>>> In this way at least it works with usual lists:
>>>
>>>> L<- list(chr2=5, chr1=10)
>>>> L
>>>
>>> $chr2
>>> [1] 5
>>>
>>> $chr1
>>> [1] 10
>>>
>>>> L[chrs]<- list(100, 50)
>>>> L
>>>
>>> $chr2
>>> [1] 50
>>>
>>> $chr1
>>> [1] 100
>>
>> Hi Manuela -- I think this is consistent with R ?
>>
>>> x = list(chr2=5, chr1=10)
>>> chrs=c("chr1", "chr2")
>>> x[chrs] = list(100, 50)
>>> x
>> $chr2
>> [1] 50
>>
>> $chr1
>> [1] 100
>
> Maybe I'm missing it too, but it doesn't look like this is what the
> SimpleList is doing ... it seems like SimpleList is assigning by order
> and not name:
>
> R>  IL<- IntegerList(chr2=5, chr1=10)
> R>  L<- list(chr2=5, chr1=10)
> R>  all(sapply(IL, identity) == sapply(L, identity))
> [1] TRUE
>
>
> R>  chrs<- c('chr1', 'chr2')
> R>  IL[chrs]<- list(100, 200)
> R>  L[chrs]<- list(100, 200)
> R>  all(sapply(IL, identity) == sapply(L, identity))
> [1] FALSE
>
> R>  IL[['chr2']]
> [1] 100
>
> R>  L[['chr2']]
> [1] 200
>
> Right?
> I mean ... wrong? .. right?

oops, I mis-spoke and don't have an immediate answer. Martin

>
> -steve
>


-- 
Computational Biology
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109

Location: M1-B861
Telephone: 206 667-2793



More information about the Bioconductor mailing list