This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Determing number of spliced alignments in a BAM file

What is the best way of determining the number of spiced alignments in a BAM file with SAMTOOLS? My research on the web shows that the character "N" in CIGAR string indicates a splice.

Thank you, Greg

samtools bam

1 answer

You can play with bash commands..

I don't remember the column that represents the CIGAR (I believe is column 7)

You can do the following

cat your_file.sam | cut -f 7 | grep "N" | wc -l

If playing with BAM files

samtools view your_file.bam | cut -f 7 | grep "N" | wc -l

With cat and samtools view you open the content of the file and pipe it to the cut command, which select column 7. With grep you select those lanes containing a N into the CIGAR string, and pipe it again to wc -l which count the lanes containing such a N

Thank you for your assistance!

Actually, it's column -f6.

You've helped me too, thanks!!

Log in to answer this question.