How to overlap granges objects by gene name
1
0
Entering edit mode
grr4006 • 0
@6e0a7b6f
Last seen 3.3 years ago
United States

I have two granges objects that I want to overlap based on the metadata column gene names - I essentially want to find the ranges that correlate to the same gene names between the two sets. Can anyone help me with this?

Code should be placed in three backticks as shown below


# include your problematic code here with any corresponding output 
# please also include the results of running the following in an R session 

sessionInfo( )
GenomicRanges • 748 views
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 5 hours ago
United States

Rather than asking an open question, it's better to give an example of what you are trying to do so people don't have to parse your words to divine your meaning. I'm guessing you want something like this?

> z <- GRanges(rep("chr1", 4), IRanges(c(1,5,9,21), c(4,8,14,33)), name = LETTERS[1:4])
> zz <- GRanges(rep("chr1",4), IRanges(c(2,6,14,33), c(5,11,21,44)), name = LETTERS[c(1:3,5)])
> z
GRanges object with 4 ranges and 1 metadata column:
      seqnames    ranges strand |        name
         <Rle> <IRanges>  <Rle> | <character>
  [1]     chr1       1-4      * |           A
  [2]     chr1       5-8      * |           B
  [3]     chr1      9-14      * |           C
  [4]     chr1     21-33      * |           D
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths
> zz
GRanges object with 4 ranges and 1 metadata column:
      seqnames    ranges strand |        name
         <Rle> <IRanges>  <Rle> | <character>
  [1]     chr1       2-5      * |           A
  [2]     chr1      6-11      * |           B
  [3]     chr1     14-21      * |           C
  [4]     chr1     33-44      * |           E
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths
> zzz <- c(z, zz)
> zzzz <- splitAsList(zzz, zzz$name)
> zzzz
GRangesList object of length 5:
$A
GRanges object with 2 ranges and 1 metadata column:
      seqnames    ranges strand |        name
         <Rle> <IRanges>  <Rle> | <character>
  [1]     chr1       1-4      * |           A
  [2]     chr1       2-5      * |           A
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

$B
GRanges object with 2 ranges and 1 metadata column:
      seqnames    ranges strand |        name
         <Rle> <IRanges>  <Rle> | <character>
  [1]     chr1       5-8      * |           B
  [2]     chr1      6-11      * |           B
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

$C
GRanges object with 2 ranges and 1 metadata column:
      seqnames    ranges strand |        name
         <Rle> <IRanges>  <Rle> | <character>
  [1]     chr1      9-14      * |           C
  [2]     chr1     14-21      * |           C
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

$D
GRanges object with 1 range and 1 metadata column:
      seqnames    ranges strand |        name
         <Rle> <IRanges>  <Rle> | <character>
  [1]     chr1     21-33      * |           D
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

$E
GRanges object with 1 range and 1 metadata column:
      seqnames    ranges strand |        name
         <Rle> <IRanges>  <Rle> | <character>
  [1]     chr1     33-44      * |           E
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

> reduce(zzzz)
GRangesList object of length 5:
$A
GRanges object with 1 range and 0 metadata columns:
      seqnames    ranges strand
         <Rle> <IRanges>  <Rle>
  [1]     chr1       1-5      *
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

$B
GRanges object with 1 range and 0 metadata columns:
      seqnames    ranges strand
         <Rle> <IRanges>  <Rle>
  [1]     chr1      5-11      *
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

$C
GRanges object with 1 range and 0 metadata columns:
      seqnames    ranges strand
         <Rle> <IRanges>  <Rle>
  [1]     chr1      9-21      *
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

$D
GRanges object with 1 range and 0 metadata columns:
      seqnames    ranges strand
         <Rle> <IRanges>  <Rle>
  [1]     chr1     21-33      *
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

$E
GRanges object with 1 range and 0 metadata columns:
      seqnames    ranges strand
         <Rle> <IRanges>  <Rle>
  [1]     chr1     33-44      *
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

>
ADD COMMENT

Login before adding your answer.

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