5.1.33. sort

### Navigation

- index
- next |
- previous |
- bedtools v2.18.0 »
- 5. The BEDTools suite »

# 5.1.33. sort

sortBed sorts a feature file by chromosome and other criteria.

## 5.1.33.1. Usage and option summary

Usage:

    sortBed [OPTIONS] -i <BED/GFF/VCF>

Option | Description
--- | ---
-sizeA | Sort by feature size in ascending order.
-sizeD | Sort by feature size in descending order.
-chrThenSizeA | Sort by chromosome, then by feature size (asc).
-chrThenSizeD | Sort by chromosome, then by feature size (desc).
-chrThenScoreA | Sort by chromosome, then by score (asc).
-chrThenScoreD | Sort by chromosome, then by score (desc).

## 5.1.33.2. Default behavior

By default, sortBed 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

## 5.1.33.3. Optional sorting behavior

sortBed will also sorts 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 sortBed is merely a convenience utility, as the UNIX sort utility 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

comments powered by Disqus

### Navigation

- index
- next |
- previous |
- bedtools v2.18.0 »
- 5. The BEDTools suite »

### Edit and improve this document!

This file can be edited directly through the Web. Anyone can update and fix errors in this document with few clicks -- no downloads needed.

1. Go to 5.1.33. sort on GitHub.
2. Edit files using GitHub's text editor in your web browser (see the 'Edit' tab on the top right of the file)
3. Fill in the Commit message text box at the bottom of the page describing why you made the changes. Press the Propose file change button next to it when done.
4. Then click Send a pull request.
5. Your changes are now queued for review under the project's Pull requests tab on GitHub!

For an introduction to the documentation format please see the reST primer.