1.several tool sets have been created to manipulate SAM/BAM files:
samtools , bamtools , picard??
2.how can I select from or filter data from BAM files?
2.1? clarify some wording:
?selecting means to keep alignments that match a condition
filter means to remove alignments that match a condition
-f? ?(flag) includes only alignments where the bits match the bits in the flag
-F? (flag) includes only alignments where the bits do not match the bits in the flag
2.2 recall what flag 4 means and how to use it :
samtools flags 4? ?#表示unmap?reads
samtools view -f 4 file.bam | head? ?# select and view the unmapped reads
samtools view -f 4 file.bam | wc -l #count the unmapped reads
samtools view -c -f 4 file.bam? # count the unmapped reads
samtools view -c? -F 4 file.bam # count the mapped reads
samtools view -b -F 4 file.bam > file_mapped_reads # separate unmapped reads
samtools view -c -f 16 file.bam # reads that align to reverse strand
samtools view -c -F 4 -f 16 file.bam # reads that align to reverse stand and not unmapped.
samtools view -c -F 20 file.bam # reads that align to forwards strand and are not unmapped
samtools view -b -f 4 file.bam > file_mapped_reads # separate mapped reads
2.3 Get an overview of the alignments in a BAM file
samtools flagstat file.bam # produces a report on flags
samtools idxstats file.bam # produces a report on how many reads align to each chromosome
bamtools stats -in file.bam # produces a report on flags
2.4 how do I filter on mapping quality?
The mapping quality column contains a number that the aligner fillls in . This number is rarely an objection quantity , it rather reflects a subjective value designated by the tool developer.
smatools view -c -q 1 file.bam? #select uniquely mapped reads when these were a aligned with BWA
smatools view -c -q 1 -F 4 -F 16 file.bam # mapping quality over 1 and on the forward strand (file.bam by BWA)
2.5 how can I find out the depth of coverage ?
samtools depth file.bam? | head? # compute the depth of coverage, compute the number of reads that overlap each base .
samtools depth -a file.bam | head? # ask for all position and you can verify that it starts at 1
smatools depth file.bam | sort -k 3 -rn | head? # sort by depth?