Skip to contents

Returns 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.

Usage

genomicOrder(chrom, start, end = NULL)

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().

Details

Shared by every pecotmr writer and by the pipeline wrappers that merge per-region tables, so one definition of "genomic order" covers both.

Examples

genomicOrder(c("chr10", "chr2", "chrX", "chr2"), c(5, 90, 1, 10))
#> [1] 4 2 1 3