Monday, May 5, 2014

Subsetting/ extracting reads from bam files

1. Regions (make an index first, then select your regions)
samtools index bam_file 
samtools view -b file.bam chr1 > file_chr1.bam 
samtools view -b file.bam chr1:1-10000 > file_chr1_1_10000.bam 

2. Regions given in bed file
samtools view -bL regions.bed file.bam > file_regions.bam 

3. First n reads
samtools view -h file.bam | head -n 10000 | samtools view -bS - > file_n10000.bam

No comments:

Post a Comment