Category

Genomic Interval Manipulation


Usage

bedtools sort [OPTIONS] -i <bed/gff/vcf>


Manual

This tool is part of the bedtools suite, and it's also known as sortBed.

Required arguments

  • -i bed/gff/vcf: Input file in BED, GFF, or VCF format.

Options

  • -sizeA: Sort by feature size in ascending order.
  • -sizeD: Sort by feature size in descending order.
  • -chrThenSizeA: Sort by chrom (asc), then feature size (asc).
  • -chrThenSizeD: Sort by chrom (asc), then feature size (desc).
  • -chrThenScoreA: Sort by chrom (asc), then score (asc).
  • -chrThenScoreD: Sort by chrom (asc), then score (desc).
  • -g names.txt: Sort according to the chromosomes declared in "genome.txt".
  • -faidx names.txt: Sort according to the chromosomes declared in "names.txt".
  • -header: Print the header from the input file prior to results.

Examples

By default, bedtools sort sorts a BED file by chromosome and then by start position in ascending order.

For example:

$ cat A.bed
chr1 800 1000
chr1 80  180
chr1 1   10
chr1 750 10000

$ sortBed -i A.bed
chr1 1   10
chr1 80  180
chr1 750 10000
chr1 800 1000

bedtools sort can also sort a BED file by chromosome and then by other criteria. For example, to sort by chromosome and then by feature size (in descending order):

$ cat A.bed
chr1 800 1000
chr1 80  180
chr1 1   10
chr1 750 10000

$ sortBed -i A.bed -sizeD
chr1 750 10000
chr1 800 1000
chr1 80  180
chr1 1   10

Disclaimer: it should be noted that bedtools sort is merely a convenience utility, as the UNIX sort utility or bedSort will sort BED files more quickly while using less memory. For example, UNIX sort will sort a BED file by chromosome then by start position in the following manner:

$ sort -k 1,1 -k2,2n a.bed
chr1 1   10
chr1 80  180
chr1 750 10000
chr1 800 1000

File formats this tool works with
BEDGFFGTFVCF

Share your experience or ask a question