Use this function to order regioins prior to calling peak_matrix() or tile_matrix().
Arguments
- ranges
- Genomic regions given as GRanges, data.frame, or list. See - help("genomic-ranges-like")for details on format and coordinate systems. Required attributes:- chr,- start,- end: genomic position
 
- chr_levels
- Ordering of chromosome names 
- sort_by_end
- If TRUE (defualt), sort by (chr, end, start). Else sort by (chr, start, end) 
Value
Numeric vector analagous to the order function. Provides an index
selection that will reorder the input ranges to be sorted by chr, end, start
Examples
## Prep data
ranges <- tibble::tibble(
  chr = "chr1",
  start = seq(10, 260, 50),
  end = start + seq(310, 0, -60),
  cell_id = paste0("cell1")
) %>% as("GRanges")
ranges
#> GRanges object with 6 ranges and 1 metadata column:
#>       seqnames    ranges strand |     cell_id
#>          <Rle> <IRanges>  <Rle> | <character>
#>   [1]     chr1    10-320      * |       cell1
#>   [2]     chr1    60-310      * |       cell1
#>   [3]     chr1   110-300      * |       cell1
#>   [4]     chr1   160-290      * |       cell1
#>   [5]     chr1   210-280      * |       cell1
#>   [6]     chr1   260-270      * |       cell1
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths
## Get end-sorted ordering
order_ranges(ranges, levels(GenomicRanges::seqnames(ranges)))
#> [1] 6 5 4 3 2 1
