I tried using the above script, but found that parsing blast output (blast-2.2.29+) created some inconsistencies in CIGAR string (read length was different according to CIGAR, so both samtools 0.1.19 and picard 1.72 complained. Turned out the script was reporting deletions instead insertions and vice versa. I am posting the fixed code: