Order rows by genomic position, with chromosomes sorted naturally
Source:R/resultWriters.R
genomicOrder.RdReturns the permutation that puts rows in genomic order: chromosomes 1..22 numerically, then the non-numeric contigs (X, Y, MT, ...) alphabetically after all of them, and positions numerically within a chromosome. A plain character sort puts chr10 before chr2, which is why published tables need this.
Arguments
- chrom
Chromosome labels. A leading
"chr"is optional and is ignored for ordering, so"chr2"and"2"sort alike.- start
Start positions; coerced to numeric, non-numeric entries sort last within their chromosome.
- end
Optional second position key, used only to break ties on
start(a half-open BED's end column). Ignored when it is not numeric, so a table whose third column is not a position (an allele, say) can pass it harmlessly.
Value
An integer permutation, as from order().