| 1 |
.. _shuffle: |
| 2 |
|
| 3 |
############### |
| 4 |
*shuffle* |
| 5 |
############### |
| 6 |
|
| 7 |
| |
| 8 |
|
| 9 |
.. image:: ../images/tool-glyphs/shuffle-glyph.png |
| 10 |
:width: 600pt |
| 11 |
|
| 12 |
|
| 13 |
`bedtools shuffle` will randomly permute the genomic locations of a feature |
| 14 |
file among a genome defined in a genome file. One can also provide an |
| 15 |
"exclusions" BED/GFF/VCF file that lists regions where you do |
| 16 |
not want the permuted features to be placed. For example, one might want to |
| 17 |
prevent features from being placed in known genome gaps. `shuffle` is useful |
| 18 |
as a *null* basis against which to test the significance of associations |
| 19 |
of one feature with another. |
| 20 |
|
| 21 |
|
| 22 |
.. seealso:: |
| 23 |
|
| 24 |
:doc:`../tools/random` |
| 25 |
:doc:`../tools/jaccard` |
| 26 |
|
| 27 |
|
| 28 |
========================================================================== |
| 29 |
Usage and option summary |
| 30 |
========================================================================== |
| 31 |
**Usage**: |
| 32 |
:: |
| 33 |
|
| 34 |
bedtools shuffle [OPTIONS] -i <BED/GFF/VCF> -g <GENOME> |
| 35 |
|
| 36 |
**(or)**: |
| 37 |
:: |
| 38 |
|
| 39 |
shuffleBed [OPTIONS] -i <BED/GFF/VCF> -g <GENOME> |
| 40 |
|
| 41 |
=========================== =============================================================================================================================================================================================================== |
| 42 |
Option Description |
| 43 |
=========================== =============================================================================================================================================================================================================== |
| 44 |
**-excl** A BED file of coordinates in which features from -i should *not* be placed (e.g., genome gaps). |
| 45 |
**-incl** A BED file of coordinates in which features from -i *should* be placed. |
| 46 |
**-chrom** Keep features in -i on the same chromosome. Solely permute their location on the chromosome. *By default, both the chromosome and position are randomly chosen*. |
| 47 |
**-seed** Supply an integer seed for the shuffling. This will allow feature shuffling experiments to be recreated exactly as the seed for the pseudo-random number generation will be constant. *By default, the seed is chosen automatically*. |
| 48 |
**-f** Maximum overlap (as a fraction of the ``-i`` feature) with an ``-excl`` feature that is tolerated before searching for a new, randomized locus. |
| 49 |
**-chromFirst** Instead of choosing a position randomly among the entire genome (the default), first choose a chrom randomly, and then choose a random start coordinate on that chrom. This leads to features being ~uniformly distributed among the chroms, as opposed to features being distribute as a function of chrom size. |
| 50 |
**-bedpe** Indicate that the A file is in BEDPE format. |
| 51 |
**-maxTries** Max. number of attempts to find a home for a shuffled interval in the presence of -incl or -excl. *Default = 1000.* |
| 52 |
**-noOverlapping** Don't allow shuffled intervals to overlap. |
| 53 |
**-allowBeyondChromEnd** Allow the original the length of the original records to extend beyond the length of the chromosome. |
| 54 |
=========================== =============================================================================================================================================================================================================== |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
========================================================================== |
| 60 |
Default behavior |
| 61 |
========================================================================== |
| 62 |
By default, `bedtools shuffle` will reposition each feature in the input BED |
| 63 |
file on a random chromosome at a random position. The size and strand of each |
| 64 |
feature are preserved. |
| 65 |
|
| 66 |
For example: |
| 67 |
|
| 68 |
.. code-block:: bash |
| 69 |
|
| 70 |
$ cat A.bed |
| 71 |
chr1 0 100 a1 1 + |
| 72 |
chr1 0 1000 a2 2 - |
| 73 |
|
| 74 |
$ cat my.genome |
| 75 |
chr1 10000 |
| 76 |
chr2 8000 |
| 77 |
chr3 5000 |
| 78 |
chr4 2000 |
| 79 |
|
| 80 |
$ bedtools shuffle -i A.bed -g my.genome |
| 81 |
chr4 1498 1598 a1 1 + |
| 82 |
chr3 2156 3156 a2 2 - |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
========================================================================== |
| 89 |
``-chrom`` Requiring that features be shuffled on the same chromosome |
| 90 |
========================================================================== |
| 91 |
The `-chrom` option behaves the same as the default behavior except that |
| 92 |
features are randomly placed on the same chromosome as defined in the BED file. |
| 93 |
|
| 94 |
.. code-block:: bash |
| 95 |
|
| 96 |
$ cat A.bed |
| 97 |
chr1 0 100 a1 1 + |
| 98 |
chr1 0 1000 a2 2 - |
| 99 |
|
| 100 |
$ cat my.genome |
| 101 |
chr1 10000 |
| 102 |
chr2 8000 |
| 103 |
chr3 5000 |
| 104 |
chr4 2000 |
| 105 |
|
| 106 |
$ bedtools shuffle -i A.bed -g my.genome -chrom |
| 107 |
chr1 9560 9660 a1 1 + |
| 108 |
chr1 7258 8258 a2 2 - |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
========================================================================== |
| 114 |
``-excl`` Excluding certain genome regions from ``bedtools shuffle`` |
| 115 |
========================================================================== |
| 116 |
One may want to prevent BED features from being placed in certain regions of |
| 117 |
the genome. For example, one may want to exclude genome gaps from permutation |
| 118 |
experiment. The `excl` option defines a BED file of regions that should be |
| 119 |
excluded. ``bedtools shuffle`` will attempt to permute the locations of all features |
| 120 |
while adhering to the exclusion rules. However it will stop looking for an |
| 121 |
appropriate location if it cannot find a valid spot for a feature |
| 122 |
after 1,000,000 tries. |
| 123 |
|
| 124 |
For example (*note that the exclude file excludes all but 100 base pairs of the chromosome*): |
| 125 |
|
| 126 |
.. code-block:: bash |
| 127 |
|
| 128 |
$ cat A.bed |
| 129 |
chr1 0 100 a1 1 + |
| 130 |
chr1 0 1000 a2 2 - |
| 131 |
|
| 132 |
$ cat my.genome |
| 133 |
chr1 10000 |
| 134 |
|
| 135 |
$ cat exclude.bed |
| 136 |
chr1 100 10000 |
| 137 |
|
| 138 |
$ bedtools shuffle -i A.bed -g my.genome -excl exclude.bed |
| 139 |
chr1 0 100 a1 1 + |
| 140 |
Error, line 2: tried 1000000 potential loci for entry, but could not avoid excluded |
| 141 |
regions. Ignoring entry and moving on. |
| 142 |
|
| 143 |
|
| 144 |
For example (*now the exclusion file only excludes the first 100 bases of the chromosome*): |
| 145 |
|
| 146 |
.. code-block:: bash |
| 147 |
|
| 148 |
$ cat A.bed |
| 149 |
chr1 0 100 a1 1 + |
| 150 |
chr1 0 1000 a2 2 - |
| 151 |
|
| 152 |
$ cat my.genome |
| 153 |
chr1 10000 |
| 154 |
|
| 155 |
$ cat exclude.bed |
| 156 |
chr1 0 100 |
| 157 |
|
| 158 |
$ bedtools shuffle -i A.bed -g my.genome -excl exclude.bed |
| 159 |
chr1 147 247 a1 1 + |
| 160 |
chr1 2441 3441 a2 2 - |
| 161 |
|
| 162 |
|
| 163 |
========================================================================== |
| 164 |
``-seed`` Defining a "seed" for the random replacement. |
| 165 |
========================================================================== |
| 166 |
`bedtools shuffle` uses a pseudo-random number generator to permute the |
| 167 |
locations of BED features. Therefore, each run should produce a different |
| 168 |
result. This can be problematic if one wants to exactly recreate an experiment. |
| 169 |
By using the `seed` option, one can supply a custom integer seed for |
| 170 |
`bedtools shuffle`. In turn, each execution of `bedtools shuffle` with the same |
| 171 |
seed and input files should produce identical results. |
| 172 |
|
| 173 |
For example (*note that the exclude file below excludes all but 100 base pairs |
| 174 |
of the chromosome*): |
| 175 |
|
| 176 |
|
| 177 |
.. code-block:: bash |
| 178 |
|
| 179 |
$ cat A.bed |
| 180 |
chr1 0 100 a1 1 + |
| 181 |
chr1 0 1000 a2 2 - |
| 182 |
|
| 183 |
$ cat my.genome |
| 184 |
chr1 10000 |
| 185 |
|
| 186 |
$ bedtools shuffle -i A.bed -g my.genome -seed 927442958 |
| 187 |
chr1 6177 6277 a1 1 + |
| 188 |
chr1 8119 9119 a2 2 - |
| 189 |
|
| 190 |
$ bedtools shuffle -i A.bed -g my.genome -seed 927442958 |
| 191 |
chr1 6177 6277 a1 1 + |
| 192 |
chr1 8119 9119 a2 2 - |
| 193 |
|
| 194 |
. . . |
| 195 |
|
| 196 |
$ bedtools shuffle -i A.bed -g my.genome -seed 927442958 |
| 197 |
chr1 6177 6277 a1 1 + |
| 198 |
chr1 8119 9119 a2 2 - |
| 199 |
|
| 200 |
========================================================================== |
| 201 |
``-noOverlapping`` Prevent shuffled intervals from overlapping. |
| 202 |
========================================================================== |
| 203 |
There often arise cases where one wants to shuffle intervals throughout |
| 204 |
the genome, yet one wants to prevent the intervals from occupying a single |
| 205 |
common base pair. The ``-noOverlapping`` option allows one to enforce |
| 206 |
no such overlaps. |
| 207 |
|
| 208 |
.. code-block:: bash |
| 209 |
|
| 210 |
$ bedtools shuffle -i A.bed -g my.genome -noOverlapping |
| 211 |
|
| 212 |
|
| 213 |
========================================================================== |
| 214 |
``-allowBeyondChromEnd`` Allow records to extend beyond the chrom. length. |
| 215 |
========================================================================== |
| 216 |
By default, ``shuffle`` requires that an interval's original length must be |
| 217 |
fully-contained within the chromosome. Yet there are cases where you might |
| 218 |
want to allow shuffled intervals to be relocated to a position |
| 219 |
in which the entire original interval cannot fit w/o exceeding |
| 220 |
the end of the chromosome. By using the ``-noOverlapping`` option, |
| 221 |
``shuffle`` will allow intervals to be shuffled to locations that are so close |
| 222 |
to the chromosome end that the full length of the original record cannot |
| 223 |
be contained within the chromosome length. In such cases, the end coordinate |
| 224 |
for the shuffled interval will be set (i.e., truncated) |
| 225 |
to the chromosome's length. |
| 226 |
|
| 227 |
.. code-block:: bash |
| 228 |
|
| 229 |
$ bedtools shuffle -i A.bed -g my.genome -allowBeyondChromEnd |
| 230 |
|
| 231 |
|
| 232 |
|