| 1 |
############### |
| 2 |
Advanced usage |
| 3 |
############### |
| 4 |
|
| 5 |
|
| 6 |
========================================================================== |
| 7 |
Mask all regions in a genome except for targeted capture regions. |
| 8 |
========================================================================== |
| 9 |
|
| 10 |
Step 1. Add 500 bp up and downstream of each probe |
| 11 |
|
| 12 |
.. code-block:: bash |
| 13 |
|
| 14 |
bedtools slop -i probes.bed -g hg18.genome -b 500 > probes.500bp.bed |
| 15 |
|
| 16 |
NB genome is two column chromosome size list - i.e. https://genome.ucsc.edu/goldenpath/help/hg18.chrom.sizes |
| 17 |
|
| 18 |
Step 2. Get a BED file of all regions not covered by the probes (+500 bp up/down) |
| 19 |
|
| 20 |
|
| 21 |
.. code-block:: bash |
| 22 |
|
| 23 |
bedtools complement -i probes.500bp.bed -g hg18.genome > probes.500bp.complement.bed |
| 24 |
|
| 25 |
|
| 26 |
Step 3. Create a masked genome where all bases are masked except for the probes +500bp |
| 27 |
|
| 28 |
.. code-block:: bash |
| 29 |
|
| 30 |
bedtools maskfasta -fi hg18.fa -bed probes.500bp.complement.bed \ |
| 31 |
-fo hg18.probecomplement.masked.fa |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
========================================================================== |
| 36 |
Screening for novel SNPs. |
| 37 |
========================================================================== |
| 38 |
Find all SNPs that are not in dbSnp and not in the latest 1000 genomes calls |
| 39 |
|
| 40 |
.. code-block:: bash |
| 41 |
|
| 42 |
bedtools intersect -a snp.calls.bed -b dbSnp.bed -v | \ |
| 43 |
bedtools intersect -a - -b 1KG.bed -v | \ |
| 44 |
> snp.calls.novel.bed |
| 45 |
|
| 46 |
|
| 47 |
========================================================================== |
| 48 |
Computing the coverage of features that align entirely within an interval. |
| 49 |
========================================================================== |
| 50 |
|
| 51 |
By default, bedtools ``coverage`` counts any feature in A that overlaps B |
| 52 |
by >= 1 bp. If you want to require that a feature align entirely within B for |
| 53 |
it to be counted, you can first use intersectBed with the "-f 1.0" option. |
| 54 |
|
| 55 |
.. code-block:: bash |
| 56 |
|
| 57 |
bedtools intersect -a features.bed -b windows.bed -f 1.0 | \ |
| 58 |
bedtools coverage -a windows.bed -b - \ |
| 59 |
> windows.bed.coverage |
| 60 |
|
| 61 |
|
| 62 |
========================================================================== |
| 63 |
Computing the coverage of BAM alignments on exons. |
| 64 |
========================================================================== |
| 65 |
One can combine ``samtools`` with ``bedtools`` to compute coverage directly |
| 66 |
from the BAM data by using ``bamtobed``. |
| 67 |
|
| 68 |
.. code-block:: bash |
| 69 |
|
| 70 |
bedtools bamtobed -i reads.bam | \ |
| 71 |
bedtools coverage -a exons.bed -b - \ |
| 72 |
> exons.bed.coverage |
| 73 |
|
| 74 |
|
| 75 |
Take it a step further and require that coverage be from properly-paired reads. |
| 76 |
|
| 77 |
.. code-block:: bash |
| 78 |
|
| 79 |
samtools view -uf 0x2 reads.bam | \ |
| 80 |
coverageBed -abam - -b exons.bed \ |
| 81 |
> exons.bed.proper.coverage |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
========================================================================== |
| 86 |
Computing coverage separately for each strand. |
| 87 |
========================================================================== |
| 88 |
Use grep to only look at forward strand features (i.e. those that end in "+"). |
| 89 |
|
| 90 |
.. code-block:: bash |
| 91 |
|
| 92 |
bedtools bamtobed -i reads.bam | \ |
| 93 |
grep \+$ | \ |
| 94 |
bedtools coverage -a - -b genes.bed \ |
| 95 |
> genes.bed.forward.coverage |
| 96 |
|
| 97 |
Use grep to only look at reverse strand features (i.e. those that end in "-"). |
| 98 |
|
| 99 |
.. code-block:: bash |
| 100 |
|
| 101 |
bedtools bamtobed -i reads.bam | \ |
| 102 |
grep \-$ | \ |
| 103 |
bedtools coverage -a - -b genes.bed \ |
| 104 |
> genes.bed.reverse.coverage |
| 105 |
|