subsetting IntegerList by list names
2
0
Entering edit mode
@manuela-hummel-4963
Last seen 9.7 years ago
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 Thanks a lot for your comments Manuela > sessionInfo() R version 2.14.0 (2011-10-31) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=Spanish_Spain.1252 LC_CTYPE=Spanish_Spain.1252 [3] LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C [5] LC_TIME=Spanish_Spain.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] IRanges_1.12.1 loaded via a namespace (and not attached): [1] tools_2.14.0 Manuela Hummel Core Facilities - Microarrays Unit Center for Genomic Regulation (CRG) Dr. Aiguader 88, 4th floor, Office 439.01 08003 Barcelona Phone: +34 93 316 0373 e-mail: manuela.hummel at crg.eu ?
• 1.1k views
ADD COMMENT
0
Entering edit mode
@martin-morgan-1513
Last seen 29 days ago
United States
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 Martin > > > Thanks a lot for your comments > Manuela > > > >> sessionInfo() > > R version 2.14.0 (2011-10-31) > Platform: i386-pc-mingw32/i386 (32-bit) > > locale: > [1] LC_COLLATE=Spanish_Spain.1252 LC_CTYPE=Spanish_Spain.1252 > [3] LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C > [5] LC_TIME=Spanish_Spain.1252 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > other attached packages: > [1] IRanges_1.12.1 > > loaded via a namespace (and not attached): > [1] tools_2.14.0 > > > > > Manuela Hummel > Core Facilities - Microarrays Unit > Center for Genomic Regulation (CRG) > Dr. Aiguader 88, 4th floor, Office 439.01 > 08003 Barcelona > Phone: +34 93 316 0373 > e-mail: manuela.hummel at crg.eu > > > _______________________________________________ > Bioconductor mailing list > Bioconductor at r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor -- Computational Biology Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: M1-B861 Telephone: 206 667-2793
ADD COMMENT
0
Entering edit mode
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? -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology ?| Memorial Sloan-Kettering Cancer Center ?| Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact
ADD REPLY
0
Entering edit mode
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
ADD REPLY
0
Entering edit mode
Greetings, I haven't worked with IRanges, and I'm still getting used to the R syntax, so I'm not sure, but I think the problem is that IntegerList returns a list of a single element consisting of (...) whereas list returns a list of however elements you gave as arguments. So depending on how you compare them you will get different answers. Here's a brief example: > av = strsplit("atomicvector",'') > av [[1]] [1] "a" "t" "o" "m" "i" "c" "v" "e" "c" "t" "o" "r" > class(av) [1] "list" > lv = unlist(strsplit("atomicvector",'')) > lv [1] "a" "t" "o" "m" "i" "c" "v" "e" "c" "t" "o" "r" > all(sapply(av,identity) == sapply(lv,identity)) [1] TRUE ### so far they look the same, but > av[1] [[1]] [1] "a" "t" "o" "m" "i" "c" "v" "e" "c" "t" "o" "r" > lv[1] [1] "a" they are not the same. > lv %in% av [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE > av %in% lv [1] FALSE Tom MMI DNA Services Core Facility<http: www.ohsu.edu="" xd="" research="" research-cores="" dna-analysis=""/> 503-494-2442 kellert at ohsu.edu<http: ohsu.edu=""> Office: 6588 RJH (CROET/BasicScience) OHSU Shared Resources<http: www.ohsu.edu="" xd="" research="" research-="" cores="" index.cfm=""> On Nov 16, 2011, at 9:25 AM, Steve Lianoglou wrote: Hi, On Wed, Nov 16, 2011 at 12:09 PM, Martin Morgan <mtmorgan@fhcrc.org<mailto:mtmorgan@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? -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact _______________________________________________ Bioconductor mailing list Bioconductor@r-project.org<mailto:bioconductor@r-project.org> 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
@herve-pages-1542
Last seen 4 hours ago
Seattle, WA, United States
Hi Manuela, Well, thanks for uncovering that one! Looks like this bug has been around for a while and I wonder how it could have been sitting and hiding in the dark for so long... Anyway, I've just applied a fix to IRanges in release (1.12.2) and devel (1.13.7). I also extended the unit tests so this will never ever happen again ;-) The new versions of IRanges should become available in the next 24-36 hours via biocLite(). Thanks again and please be sure to let us know if you find other problems. Cheers, H. On 11-11-16 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 > > > Thanks a lot for your comments > Manuela > > > >> sessionInfo() > > R version 2.14.0 (2011-10-31) > Platform: i386-pc-mingw32/i386 (32-bit) > > locale: > [1] LC_COLLATE=Spanish_Spain.1252 LC_CTYPE=Spanish_Spain.1252 > [3] LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C > [5] LC_TIME=Spanish_Spain.1252 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > other attached packages: > [1] IRanges_1.12.1 > > loaded via a namespace (and not attached): > [1] tools_2.14.0 > > > > > Manuela Hummel > Core Facilities - Microarrays Unit > Center for Genomic Regulation (CRG) > Dr. Aiguader 88, 4th floor, Office 439.01 > 08003 Barcelona > Phone: +34 93 316 0373 > e-mail: manuela.hummel at crg.eu > > > _______________________________________________ > Bioconductor mailing list > Bioconductor at r-project.org > 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, M1-B514 P.O. Box 19024 Seattle, WA 98109-1024 E-mail: hpages at fhcrc.org Phone: (206) 667-5791 Fax: (206) 667-1319
ADD COMMENT

Login before adding your answer.

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