Concatenate a list of genomic ranges
1
0
Entering edit mode
g.k • 0
@gk-13275
Last seen 6.0 years ago

Hello, I have a list having granges as follows:

$File1.bed

GRanges object with 3 ranges and 2 metadata columns:

      seqnames    ranges strand |        name     score

         <Rle> <IRanges>  <Rle> | <character> <numeric>

  [1]    chr1   [ 4,  6]      + |         TF1         0

  [2]     chr1  [ 9,  9]      + |         TF1         0

  [3]     chr1  [11, 12]      - |         TF1         0

  -------

  seqinfo: 2 sequences from an unspecified genome; no seqlengths

$File1.bed

GRanges object with 3 ranges and 2 metadata columns:

      seqnames    ranges strand |        name     score

         <Rle> <IRanges>  <Rle> | <character> <numeric>

  [1]    chr2   [ 5, 60]      + |         TF4         0

  [2]     chr1  [21, 90]      + |         TF4         0

  [3]     chr2  [23, 30]      - |         TF4         0

  -------

  seqinfo: 3 sequences from an unspecified genome; no seqlengths

I would like to make these lists one list, to concatenate them into one.

I tried doing 

do.call("c",list)

but it would not work, however when I do the following it works:

c(list[[1]],list[[2]])

I am looking for a command that can concatenate them without me having to right it manually.

This is the final result I am looking for:

GRanges object with 6 ranges and 2 metadata columns:
      seqnames    ranges strand |        name     score
         <Rle> <IRanges>  <Rle> | <character> <numeric>
  [1]    chr1   [ 4,  6]      + |         TF1         0
  [2]     chr1  [ 9,  9]      + |         TF1         0
  [3]     chr1  [11, 12]      - |         TF1         0
  [4]    chr1   [ 4,  6]      + |         TF4         0
  [5]     chr1  [ 9,  9]      + |         TF4         0
  [6]     chr1  [11, 12]      - |         TF4         0
  -------
  seqinfo: 2 sequences from an unspecified genome; no seqlengths

Any thoughts?

 

r granges genomicranges • 4.6k views
ADD COMMENT
2
Entering edit mode
@james-w-macdonald-5106
Last seen 8 hours ago
United States

You can use do.call if you convert to a GRangesList first.

> glst <- list(GRanges(paste0("chr", 1:5), IRanges(1:5, 7:11)),GRanges(paste0("chr", 5:1), IRanges(1:5, 7:11)), GRanges(paste0("chr", c(2,3,4,1,5)), IRanges(1:5, 7:11)))
> glst
[[1]]
GRanges object with 5 ranges and 0 metadata columns:
      seqnames    ranges strand
         <Rle> <IRanges>  <Rle>
  [1]     chr1       1-7      *
  [2]     chr2       2-8      *
  [3]     chr3       3-9      *
  [4]     chr4      4-10      *
  [5]     chr5      5-11      *
  -------
  seqinfo: 5 sequences from an unspecified genome; no seqlengths

[[2]]
GRanges object with 5 ranges and 0 metadata columns:
      seqnames    ranges strand
         <Rle> <IRanges>  <Rle>
  [1]     chr5       1-7      *
  [2]     chr4       2-8      *
  [3]     chr3       3-9      *
  [4]     chr2      4-10      *
  [5]     chr1      5-11      *
  -------
  seqinfo: 5 sequences from an unspecified genome; no seqlengths

[[3]]
GRanges object with 5 ranges and 0 metadata columns:
      seqnames    ranges strand
         <Rle> <IRanges>  <Rle>
  [1]     chr2       1-7      *
  [2]     chr3       2-8      *
  [3]     chr4       3-9      *
  [4]     chr1      4-10      *
  [5]     chr5      5-11      *
  -------
  seqinfo: 5 sequences from an unspecified genome; no seqlengths

> do.call(c, as(glst, "GRangesList"))
GRanges object with 15 ranges and 0 metadata columns:
       seqnames    ranges strand
          <Rle> <IRanges>  <Rle>
   [1]     chr1       1-7      *
   [2]     chr2       2-8      *
   [3]     chr3       3-9      *
   [4]     chr4      4-10      *
   [5]     chr5      5-11      *
   ...      ...       ...    ...
  [11]     chr2       1-7      *
  [12]     chr3       2-8      *
  [13]     chr4       3-9      *
  [14]     chr1      4-10      *
  [15]     chr5      5-11      *
  -------
  seqinfo: 5 sequences from an unspecified genome; no seqlengths
>
ADD COMMENT
0
Entering edit mode

Or just use unlist.

> unlist(as(glst, "GRangesList"))
GRanges object with 15 ranges and 0 metadata columns:
       seqnames    ranges strand
          <Rle> <IRanges>  <Rle>
   [1]     chr1       1-7      *
   [2]     chr2       2-8      *
   [3]     chr3       3-9      *
   [4]     chr4      4-10      *
   [5]     chr5      5-11      *
   ...      ...       ...    ...
  [11]     chr2       1-7      *
  [12]     chr3       2-8      *
  [13]     chr4       3-9      *
  [14]     chr1      4-10      *
  [15]     chr5      5-11      *
  -------
  seqinfo: 5 sequences from an unspecified genome; no seqlengths

 

ADD REPLY

Login before adding your answer.

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