[BioC] Selecting elements in GRanges object by element metadata

Michael Muratet mmuratet at hudsonalpha.org
Wed Jul 11 17:09:01 CEST 2012


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)$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)$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?

Thanks

Mike



Michael Muratet, Ph.D.
Senior Scientist
HudsonAlpha Institute for Biotechnology
mmuratet at hudsonalpha.org
(256) 327-0473 (p)
(256) 327-0966 (f)

Room 4005
601 Genome Way
Huntsville, Alabama 35806



More information about the Bioconductor mailing list