On Wed, Jul 11, 2012 at 8:09 AM, Michael Muratet
<mmuratet@hudsonalpha.org>wrote:

> Greetings
>
> I would like to select elements from a GRanges object by testing values in
> the metadata columns. This seems to work OK:
>
> x.gr[which(elementMetadata(x.**gr <http://x.gr>)$fdr<0.05)]
>
> So does this, although there's nothing in the documentation about the []
> operator accepting logical values:
>
> fosl2.th17.gr[elementMetadata(**fosl2.th17.gr <http://fosl2.th17.gr>
> )$fdr<0.05]
>
> The problem arises when I try to select from a GRanges object where the
> metadata columns have NAs:
>
> > tss.annot.gr[na.omit(**elementMetadata(tss.annot.gr)$**GENE>0),"GENE"]
> GRanges with 4028 ranges and 1 elementMetadata col:
>          seqnames                 ranges strand   |   GENE
>             <Rle>              <IRanges>  <Rle>   |    <numeric>
>      [1]     chr1   [ 3659579,  3662079]      -   |         <NA>
>      [2]     chr1   [ 4847394,  4849894]      +   |            0
>      [3]     chr1   [10025979, 10028479]      -   |         <NA>
>      [4]     chr1   [17085879, 17088379]      -   |         <NA>
>      [5]     chr1   [21067298, 21069798]      -   |         <NA>
>      [6]     chr1   [21949662, 21952162]      -   |            0
>      [7]     chr1   [23388014, 23390514]      -   |         <NA>
>      [8]     chr1   [23768264, 23770764]      +   |         <NA>
>      [9]     chr1   [23927128, 23929628]      -   |         <NA>
>      ...      ...                    ...    ... ...          ...
>   [4020]     chr2 [126607180, 126609680]      -   |            0
>   [4021]     chr2 [127345106, 127347606]      -   |            0
>   [4022]     chr2 [129195132, 129197632]      +   | -1.223140339
>   [4023]     chr2 [129194856, 129197356]      -   | -1.628782357
>   [4024]     chr2 [129360338, 129362838]      -   | -1.475535653
>   [4025]     chr2 [129837609, 129840109]      +   |            0
>   [4026]     chr2 [129948520, 129951020]      +   |            0
>   [4027]     chr2 [140213446, 140215946]      -   |            0
>   [4028]     chr2 [148267271, 148269771]      -   | -1.564551101
>
> The values returned violate the condition. It won't work at all without
> na.omit.
>
> I can coerce the GRanges object to a data.frame, do the selection and
> create a new GRanges object, but I'm hoping there is a way to do it
> directly.
>
> Am I using the syntax correctly? Is there something peculiar about a
> DataFrame vs a data.frame that's getting in the way?
>
>
It sounds like you are not very familiar with how R works. The logical
subsetting works by selecting every element "i" for which v[i] is TRUE. If
you call na.omit(), you're changing the length/geometry of the vector by
dropping elements and losing the parallel correspondence between the
logical vector and the granges.  If you had an integer vector, then
dropping elements is just fine. But as Kasper points out, you don't need to
call na.omit on a which result, because it only reports indexes that are
TRUE.

I just wanted to make sure that you understood the reasons behind the
behavior. Apologies if it was already obvious.

Thanks
>
> Mike
>
>
>
> Michael Muratet, Ph.D.
> Senior Scientist
> HudsonAlpha Institute for Biotechnology
> mmuratet@hudsonalpha.org
> (256) 327-0473 (p)
> (256) 327-0966 (f)
>
> Room 4005
> 601 Genome Way
> Huntsville, Alabama 35806
>
> ______________________________**_________________
> Bioconductor mailing list
> Bioconductor@r-project.org
> https://stat.ethz.ch/mailman/**listinfo/bioconductor<https://stat.ethz.ch/mailman/listinfo/bioconductor>
> Search the archives: http://news.gmane.org/gmane.**
> science.biology.informatics.**conductor<http://news.gmane.org/gmane.science.biology.informatics.conductor>
>

	[[alternative HTML version deleted]]

