Search
Question: Concatenate a list of genomic ranges
0
gravatar for g.k
12 weeks ago by
g.k0
g.k0 wrote:

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?

 

ADD COMMENTlink modified 12 weeks ago by James W. MacDonald48k • written 12 weeks ago by g.k0
2
gravatar for James W. MacDonald
12 weeks ago by
United States
James W. MacDonald48k wrote:

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 COMMENTlink written 12 weeks ago by James W. MacDonald48k

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 REPLYlink written 12 weeks ago by James W. MacDonald48k
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: 196 users visited in the last hour