Step 1: Making separate bed files for the intronic & exonic regions
- Go to UCSC table browser.
- Fill out the options as I did below, then select get output
- Then a second page will appear where you select “Introns plus” and leave as 0 to just get the introns
- select “get BED”
- then repeat, renaming the file to UCSC_exons_hg19.tsv and on the second page selecting “Exons plus”
- you can use the UCSC genome browser to confirm the files have only introns (or only exons)
Step 2: Extracting the specific regions from your bam file
This samtools command will only output alignments overlapping the input BED file.
The -h option = output file will include the header. The -L option = output alignments overlapping the input BED file.
Only output alignments overlapping introns:
samtools view -h -L UCSC_Introns_hg19_.bed sample.bam > sample_introns.bam
Only output alignments overlapping exons:
samtools view -h -L UCSC_exons_hg19_new.bed sample.bam > sample_exons.bam