Entering edit mode
Hi there
I am looking for a way to reorder a GRanges object using its metadata.
Here is a sample of my GRanges object:
GRanges with 1122060 ranges and 4 metadata columns:
seqnames ranges strand |
ID TSS
<rle> <iranges> <rle> |
<character> <integer>
[1] chr1 [66993729, 66993928] + |
chr1:66998729-66999824 chr1:66999824-66999824 + 1
[2] chr1 [66993929, 66994128] + |
chr1:66998729-66999824 chr1:66999824-66999824 + 1
[3] chr1 [66994129, 66994328] + |
chr1:66998729-66999824 chr1:66999824-66999824 + 1
[4] chr1 [66994329, 66994528] + |
chr1:66998729-66999824 chr1:66999824-66999824 + 1
[5] chr1 [66994529, 66994728] + |
chr1:66998729-66999824 chr1:66999824-66999824 + 1
... ... ... ... ...
... ...
[1122056] chr22 [51226318, 51226517] + |
chr22:51221773-51222156 chr22:51222156-51222156 + 29143
[1122057] chr22 [51226518, 51226717] + |
chr22:51221773-51222156 chr22:51222156-51222156 + 29143
[1122058] chr22 [51226718, 51226917] + |
chr22:51221773-51222156 chr22:51222156-51222156 + 29143
[1122059] chr22 [51226918, 51227117] + |
chr22:51221773-51222156 chr22:51222156-51222156 + 29143
[1122060] chr22 [51227118, 51227317] + |
chr22:51221773-51222156 chr22:51222156-51222156 + 29143
I want to order it so the ranges will be sorted first by the ID
metadata,then by start (ranges with the same value for this metadata
are all subsets of a larger range, so they are on the same
chromosome).
I have implemented that coercing the GRanges into a data frame,
ordering its row and then coercing back to GRanges:
grdf<-as.data.frame(CPGIs)
grdf<-grdf[order(grdf$ID,grdf$start),]
CPGIs<-GRanges(seqnames=grdf$seqnames, ranges=IRanges(grdf$start,
grdf$end),strand=grdf$strand, ID=grdf$ID, TSS=grdf$TSS,
HGNC_symbol=grdf$HGNC_symbol, refseq_symbol=grdf$refseq_symbol)
Which works, but is somewhat cumbersome. Is there a way to reorder the
Granges object without resorting to a data frame?
Thanks in advance
Dolev Rahat
[[alternative HTML version deleted]]