| 1 |
.. _sort: |
| 2 |
|
| 3 |
############### |
| 4 |
*sort* |
| 5 |
############### |
| 6 |
The ``bedtools sort`` tool sorts a feature file by chromosome and other criteria. |
| 7 |
|
| 8 |
========================================================================== |
| 9 |
Usage and option summary |
| 10 |
========================================================================== |
| 11 |
**Usage**: |
| 12 |
:: |
| 13 |
|
| 14 |
bedtools sort [OPTIONS] -i <BED/GFF/VCF> |
| 15 |
|
| 16 |
**(or)**: |
| 17 |
:: |
| 18 |
|
| 19 |
sortBed [OPTIONS] -i <BED/GFF/VCF> |
| 20 |
|
| 21 |
=========================== =============================================================================================================================================================================================================== |
| 22 |
Option Description |
| 23 |
=========================== =============================================================================================================================================================================================================== |
| 24 |
**-sizeA** Sort by feature size in ascending order. |
| 25 |
**-sizeD** Sort by feature size in descending order. |
| 26 |
**-chrThenSizeA** Sort by chromosome (asc), then by feature size (asc). |
| 27 |
**-chrThenSizeD** Sort by chromosome (asc), then by feature size (desc). |
| 28 |
**-chrThenScoreA** Sort by chromosome (asc), then by score (asc). |
| 29 |
**-chrThenScoreD** Sort by chromosome (asc), then by score (desc). |
| 30 |
**-g** Define sort order by order of tab-delimited file with chromosome names in the first column. |
| 31 |
**-faidx** Define sort order by order of tab-delimited file with chromosome names in the first column. Sort by specified chromosome order. |
| 32 |
=========================== =============================================================================================================================================================================================================== |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
========================================================================== |
| 37 |
Default behavior |
| 38 |
========================================================================== |
| 39 |
By default, ``bedtools sort`` sorts a BED file by chromosome and then by start position in ascending order. |
| 40 |
|
| 41 |
For example: |
| 42 |
|
| 43 |
:: |
| 44 |
|
| 45 |
cat A.bed |
| 46 |
chr1 800 1000 |
| 47 |
chr1 80 180 |
| 48 |
chr1 1 10 |
| 49 |
chr1 750 10000 |
| 50 |
|
| 51 |
sortBed -i A.bed |
| 52 |
chr1 1 10 |
| 53 |
chr1 80 180 |
| 54 |
chr1 750 10000 |
| 55 |
chr1 800 1000 |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
========================================================================== |
| 61 |
Optional sorting behavior |
| 62 |
========================================================================== |
| 63 |
``bedtools sort`` will also sort a BED file by chromosome and then by other criteria. |
| 64 |
|
| 65 |
For example, to sort by chromosome and then by feature size (in descending order): |
| 66 |
|
| 67 |
:: |
| 68 |
|
| 69 |
cat A.bed |
| 70 |
chr1 800 1000 |
| 71 |
chr1 80 180 |
| 72 |
chr1 1 10 |
| 73 |
chr1 750 10000 |
| 74 |
|
| 75 |
sortBed -i A.bed -sizeD |
| 76 |
chr1 750 10000 |
| 77 |
chr1 800 1000 |
| 78 |
chr1 80 180 |
| 79 |
chr1 1 10 |
| 80 |
|
| 81 |
|
| 82 |
**Disclaimer:** it should be noted that ``bedtools sort`` is merely a convenience utility, as the UNIX sort utility |
| 83 |
will sort BED files more quickly while using less memory. For example, UNIX sort will sort a BED file |
| 84 |
by chromosome then by start position in the following manner: |
| 85 |
|
| 86 |
:: |
| 87 |
|
| 88 |
sort -k 1,1 -k2,2n a.bed |
| 89 |
chr1 1 10 |
| 90 |
chr1 80 180 |
| 91 |
chr1 750 10000 |
| 92 |
chr1 800 1000 |