You are on page 1of 1

We can save the output as a new bedfile by redirection (the > sign).

bedtools intersect -a cpg.bed -b refseq_exons.bed >cpg_exon_intersect.bed

If you now do a ls, you will see an cpg_exon_intersect.bed file. This you can read
with, for instance, less

Reporting the original feature in each file.

The -wa (write A) and -wb (write B) options allow one to see the original records
from the A and B files that overlapped. As such, instead of not only showing
you where the intersections occurred, it shows you what intersected.

Let’s try both:

bedtools intersect -a cpg.bed -b refseq_exons.bed -wa | head -5


chr1 155188536 155192004 CpG:_361
chr1 155188536 155192004 CpG:_361
chr1 155188536 155192004 CpG:_361
chr1 155188536 155192004 CpG:_361
chr1 2226773 2229734 CpG:_366

Here, we get whole CpG islands that has at least one overlap to an exon. Again,
we get 4 of the same, because it overlaps 4 different exons.

bedtools intersect -a cpg.bed -b refseq_exons.bed -v | head -5


chr1 47708822 47710847 CpG:_164
chr1 144179071 144179313 CpG:_20
chr1 368792 370063 CpG:_99
chr1 381172 382185 CpG:_84
chr1 597839 598734 CpG:_94

Doing it with –v givens CpG islands that overlap nothing at all.


What happens if you do –wb? What are the columns we get out?
chr1 155188536 155188616 CpG:_361 chr1 155188162 155188616 NM_001204286.1_exon_5_0_chr1_155188163_r 0 -
chr1 155188536 155188616 CpG:_361 chr1 155188162 155188616 NM_001204285.1_exon_5_0_chr1_155188163_r 0 -
chr1 155191907 155192004 CpG:_361 chr1 155191907 155192310 NM_001204286.1_exon_6_0_chr1_155191908_r 0 -
chr1 155191907 155192004 CpG:_361 chr1 155191907 155192283 NM_001204285.1_exon_6_0_chr1_155191908_r 0 -
chr1 2228694 2229734 CpG:_366 chr1 2228694 2229735 NM_003036.3_exon_0_0_chr1_2228695_f 0 +

You might also like