7. Advanced usage

7.1. Mask all regions in a genome except for targeted capture regions.

Step 1. Add 500 bp up and downstream of each probe

bedtools slop -i probes.bed -b 500 > probes.500bp.bed

Step 2. Get a BED file of all regions not covered by the probes (+500 bp up/down)

bedtools complement -i probes.500bp.bed -g hg18.genome > probes.500bp.complement.bed

Step 3. Create a masked genome where all bases are masked except for the probes +500bp

bedtools maskfasta -in hg18.fa -bed probes.500bp.complement.bed -fo \
> hg18.probecomplement.masked.fa

7.2. Screening for novel SNPs.

Find all SNPs that are not in dbSnp and not in the latest 1000 genomes calls

bedtools intersect -a snp.calls.bed -b dbSnp.bed -v | \
bedtools intersect -a - -b 1KG.bed -v | \
> snp.calls.novel.bed

7.3. Computing the coverage of features that align entirely within an interval.

By default, bedtools coverage counts any feature in A that overlaps B by >= 1 bp. If you want to require that a feature align entirely within B for it to be counted, you can first use intersectBed with the “-f 1.0” option.

bedtools intersect -a features.bed -b windows.bed -f 1.0 | \
bedtools coverage -a - -b windows.bed \
> windows.bed.coverage

7.4. Computing the coverage of BAM alignments on exons.

One can combine samtools with bedtools to compute coverage directly from the BAM data by using bamtobed.

bedtools bamtobed -i reads.bam | \
bedtools coverage -a - -b exons.bed \
> exons.bed.coverage

Take it a step further and require that coverage be from properly-paired reads.

samtools view -uf 0x2 reads.bam | \
coverageBed -abam - -b exons.bed \
> exons.bed.proper.coverage

7.5. Computing coverage separately for each strand.

Use grep to only look at forward strand features (i.e. those that end in “+”).

bedtools bamtobed -i reads.bam | \
grep \+$  | \
bedtools coverage -a - -b genes.bed \
> genes.bed.forward.coverage

Use grep to only look at reverse strand features (i.e. those that end in “-”).

bedtools bamtobed -i reads.bam | \
grep \-$ | \
bedtools coverage -a - -b genes.bed \
> genes.bed.reverse.coverage
comments powered by Disqus

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 7. Advanced usage 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.