Getting CpG island shores

CpG islands shores are defined as the 2Kb regions that flank CpG islands. While you might think that you could use a simple awk one-liner to create it from a BED file containing CpG islands, we actually have to ensure that the flanks do not overlap CpG islands and overlapping shores are combined into a single region. The following sequence of bedtools commands does the trick.

flankBed -i islands.hg19.bed -g hg19.chrom.sizes -b 2000 > tmp1.bed
subtractBed -a tmp1.bed -b islands.hg19.bed | sort -k1,1 -k2,2n > tmp2.bed
mergeBed -i tmp2.bed > tmp3.bed
awk 'BEGIN{OFS="\t"}{print $1, $2, $3, "Shore_" NR, ".", "."}' \
    tmp3.bed > shores.hg19.bed