[Bioc-sig-seq] GRanges, ordering and subsetting

Ivan Gregoretti ivangreg at gmail.com
Thu Jul 8 17:48:49 CEST 2010


Can anybody show an example of how to sort GRanges by score?

Lets say I have this GRanges instance

library(GenomicRanges)

gr <- GRanges(seqnames = Rle(c("chr1", "chr2", "chr1", "chr3"), c(1,
3, 2, 4)), ranges = IRanges(1:10, end = 7:16, names = head(letters,
10)), strand = Rle(strand(c("-", "+", "*", "+", "-")), c(1, 2, 2, 3,
2)), score = 1:10, GC = seq(1, 0, length = 10))

gr
GRanges with 10 ranges and 2 elementMetadata values
  seqnames    ranges strand |     score        GC
     <Rle> <IRanges>  <Rle> | <integer> <numeric>
a     chr1  [ 1,  7]      - |         1 1.0000000
b     chr2  [ 2,  8]      + |         2 0.8888889
c     chr2  [ 3,  9]      + |         3 0.7777778
d     chr2  [ 4, 10]      * |         4 0.6666667
e     chr1  [ 5, 11]      * |         5 0.5555556
f     chr1  [ 6, 12]      + |         6 0.4444444
g     chr3  [ 7, 13]      + |         7 0.3333333
h     chr3  [ 8, 14]      + |         8 0.2222222
i     chr3  [ 9, 15]      - |         9 0.1111111
j     chr3  [10, 16]      - |        10 0.0000000

seqlengths
 chr1 chr2 chr3
   NA   NA   NA

How do I re-order the rows in descending score values?
How do I subset the top 3 score ranges?

Thank you,

Ivan



Ivan Gregoretti, PhD
National Institute of Diabetes and Digestive and Kidney Diseases
National Institutes of Health
5 Memorial Dr, Building 5, Room 205.
Bethesda, MD 20892. USA.
Phone: 1-301-496-1016 and 1-301-496-1592
Fax: 1-301-496-9878



More information about the Bioc-sig-sequencing mailing list