I was recently approached by a colleague who was doing a lot of high-throughput amplicon sequencing, and wanted to see the pairwise alignment of many reads without a lot of copy-and-paste. Since the information necessary to reproduce each alignment is present in the CIGAR and MD tag of a SAM/BAM file, I wrote a C++ program called sam2pairwise to do so.
The program takes one or more SAM entries and outputs the alignments, along with any deletions, insertions, mismatches, or trimming. For example, given an entry like this:
r002 0 ref 9 30 1S2I6M1P1I1P1I4M2I * 0 0 AAAAGATAAGGGATAAA * NM:i:6 MD:Z:10
...it can be presented to sam2pairwise like this:
samtools view file.bam | sam2pairwise
...and produces the following output:
r002 0 ref 9 30 1S2I6M1P1I1P1I4M2I * 0 0
AAAAGATAA*G*GGATAAA
|||||| ||||
N--AGATAA*-*-GATA--
For more information, please visit the github repo.
Adding a link to a related post Is it possible to reconstruct alignment from CIGAR and MD strings alone?