This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Placing random non-overlaping segments across genome [GenomicRanges]

I am trying to make a script that will place non-overlapping genomic ranges across the genome.

Say for example I have a genomic ranges object like this:

GRanges object with 301 ranges and 0 metadata columns:
        seqnames              ranges strand
           <Rle>           <IRanges>  <Rle>
    [1]        1     4170526-4575820      *
    [2]        1   37967685-38149272      *
    [3]        1   48355039-48669750      *
    [4]        1 105099715-105482195      *
    [5]        1 125516774-126315385      *
    ...      ...                 ...    ...
  [297]       22   42501405-43058117      *
  [298]       22   45336458-45457711      *
  [299]       22   47534379-47788622      *
  [300]       22   47818121-47906157      *
  [301]       22   49589077-50320800      *
  -------
  seqinfo: 22 sequences from an unspecified genome; no seqlengths

These are all non-overlapping segments.

Is there a way to place randomly the same number and size of segments across the genome avoiding overlap? I.e. keeping the structure of the original genomic ranges object?

I am using a for loop and if statements, but the code is rather slow and messy.

Thanks.

r genomicranges

1 answer

The regioneR library has a few handy functions for this. randomzieRegions will take a GRanges object, and shuffle the ranges around the genome. This sounds closest to what you want to do. createRandomRegions will generate a set of random regions given certain parameters.

Thank you, I will check this package. Yes, the first functions looks very close to what I want to do!

Log in to answer this question.