I wanted to see a particular sequence in our re-sequencing data using IGV. However the .bam file is too big (10Gb) to handle. Since I am interested in only a small region in the genome, I wondering if there is any way to generate a .sam/.bam file only for that region. Thank you very much in advance!
Chenglin
FYI, -b will always write the header if it's present (this isn't documented, but see here), so
samtools view -b chr1:100-200 > small.bam
will do the same thing.Thanks Devon. Didn't know that.
Thank you very much for your answer. Do I need to put the reference genome index file (
My_genome.fasta.fai
) in the command? Actually I typed something like thissamtools view -bh chr1:100-200 My_genome.fasta.fai small.sam > small.bam
, but I got error information[main_samview] fail to open "My_genome.fasta.fai" for reading.
My index file is there, why can't it be read? Thanks!You won't need the fai file at all.
The syntax is:
Edit: Just to make things clearer, in your case the command would be
samtools view -b small.bam chr1:100-200 > small.subset.bam
. The input must be a sorted and indexed BAM or CRAM file.Thank you very much for your help. I tried and made it.
Thank you, Ashutosh. I just made it.