I have the GRanges object data_GR
, from which I would like to extract all the regions specific to a chromosome(eg: chr21
). How could I extract it without knowing the regions of interest?
set.seed(123)
data_bed = circlize::generateRandomBed(nr = 1000, nc = 0)
data_GR = makeGRangesFromDataFrame(data_bed)
GRanges object with 1005 ranges and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
[1] chr1 7634457-9204434 *
[2] chr1 9853594-10435028 *
[3] chr1 10862809-12716970 *
[4] chr1 13814692-18272526 *
[5] chr1 19243285-20683999 *
... ... ... ...
[1001] chrY 46296843-48478084 *
[1002] chrY 48551532-51056391 *
[1003] chrY 52266848-53042784 *
[1004] chrY 57968441-58556744 *
[1005] chrY 58660263-59131689 *
-------
seqinfo: 24 sequences from an unspecified genome; no seqlengths
Is it possible to extract all the regions present between a range?
904 chr21 182543 2542946
905 chr21 5976730 7429360
906 chr21 14592916 14657056
907 chr21 19808058 21397649
908 chr21 21820886 22077901
909 chr21 22561006 23005888
910 chr21 25473663 26160273
911 chr21 26693456 28326067
912 chr21 30501245 34710361
913 chr21 35698126 36052399
914 chr21 36701826 38995722
915 chr21 40122532 40673153
916 chr21 41211634 41248211
917 chr21 41644225 43391767
918 chr21 44023336 44630830
919 chr21 47539670 48127414
For example, the below regions which exist in the range {20000000, 30000000}
908 chr21 21820886 22077901
909 chr21 22561006 23005888
910 chr21 25473663 26160273
911 chr21 26693456 28326067