Search
Question: subsetting GRanges object based on gene IDs
1
gravatar for Assa Yeroslaviz
20 days ago by
Assa Yeroslaviz1.3k
Munich, Germany
Assa Yeroslaviz1.3k wrote:

Hi, I have a GRanges object e.g.

GRanges object with 6 ranges and 1 metadata column:
           seqnames         ranges strand |     gene_id
              <Rle>      <IRanges>  <Rle> | <character>
  15S_rRNA       MT [ 6546,  8194]      + |    15S_rRNA
  21S_rRNA       MT [58009, 62447]      + |    21S_rRNA
     Q0010       MT [ 3952,  4338]      + |       Q0010
     Q0017       MT [ 4254,  4415]      + |       Q0017
     Q0032       MT [11667, 11957]      + |       Q0032
     Q0045       MT [13818, 26701]      + |       Q0045
  -------
  seqinfo: 17 sequences (1 circular) from an unspecified genome; no seqlengths

Now I would like to extract from it only specific rows. Lets say I want to have the genes  Q0017 and  15S_rRNA.

I have tried to do it iwht the subset command, but it only takes one pattern

subset(genes.mod, gene_id =="Q0017" )

Is there a way to add multiple patterns w.o. doing it multiple times for each gene?

thanks Assa

 

 

ADD COMMENTlink modified 20 days ago • written 20 days ago by Assa Yeroslaviz1.3k
2

Did you consider using %in% instead of ==?

ADD REPLYlink written 20 days ago by Michael Lawrence9.6k

Thanks a lot. this is doing the job perfectly. 

How embarrassing.

ADD REPLYlink written 20 days ago by Assa Yeroslaviz1.3k
1

Hi Assa,

Don't worry about embarrassment.  You asked an excellent question about programming efficiently that's also useful to others reading the support site.

As far as resources go, %in% is not discussed in the GenomicRanges  introduction vignette, though it is mentioned in man page examples and the howto. You might also find the Advanced R book quite useful.

ADD REPLYlink written 20 days ago by Pariksheet Nanda70
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.2.0
Traffic: 104 users visited in the last hour