I have written a program in python that processes and outputs mapped results as either a bam or sam file. It works fine until I have indels within the sequence. when I try to process the result file using samtools, it returns the following error:
samtools [e::sam_parse1] cigar and query sequence are of different length"
...even though the cigar and query sequence are of the same length (see below sample sam lines which returned the error).
mapped_read1 0 chr1 1379078 60 17M1D58M = 1379078 0 CTATCAATTTTTTGTTTTTTGTTGTTGTTGTTTTTTAAGGATTGTGGGCCGGGTACAGTGACTCACGCCTGTAATC AAAEEEEEE/EEAEE/EEEEEEEEEEEEEEEEEEEEEEE6<EAE/EEE<AEEEEEEAE/EEEEEEEEAEEEEEEEE MD:Z:13T3^G58 XG:Z:1 NH:i:1 NM:Z:1 XM:Z:1 XN:Z:0 XO:Z:1 AS:Z:-13 YT:Z:UU
mapped_read2 99 chr1 1654630 60 34M2D24M = 1654630 211 ATTCTACTTTATTTGTGCAAAATCTTTTTTTTCCTTTTTTTTTTTAGAGGCGGGGTCTTG EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAEEEEEEEEEEEEE MD:Z:34^T^T24 XG:Z:2 NH:i:1 NM:Z:0 XM:Z:0 XN:Z:0 XO:Z:1 AS:Z:-11 YT:Z:0
mapped_read3 0 chr1 1684108 60 24M1D43M = 1684108 0 CACTCAGCAGTCGTGAGACGCTTGCCCAATTGCCTTTTCTTTTAAAGGCCCCTGCCATTTCCCAAACC AAAEEEEEEEEEEEEAEEEEEEEEEEEEEEEEE<EEEEEEEEEEEEEEEE<EEEEEEEEEAEEEEEEE MD:Z:24^C37A5 XG:Z:1 NH:i:1 NM:Z:1 XM:Z:1 XN:Z:0 XO:Z:1 AS:Z:-11 YT:Z:UU
mapped_read 0 chr1 1889614 60 47M1D72M = 1889614 0 ACCAGCCTGGTTAACAGGATCTCTTTTACAAAGAGATCCCATCTCTTAAAAAAAAAAAAAAAAAAGGCTTCCATGAAGATGAATTAAGCAAACAAAAGCTGATACTGCTTCTGCATGCTA AAAAEEE/EEEEEEEAEEEEEEEEAEEEEEEE/EEAEEEAEEEAEEEEEEEEEEEEEEEEEEEE/EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAEEEEEEEEEEEEEEEEEEEEEE MD:Z:47^A72 XG:Z:1 NH:i:1 NM:Z:0 XM:Z:0 XN:Z:0 XO:Z:1 AS:Z:-8 YT:Z:UU
mapped_read4 0 chr1 2286565 60 58M1D10M = 2286565 0 GATTTGAACCCCAAATATAATAATTAAAGTGAGTGTGCATTTTATTCTTACCACATCAGGCAAACGCTG EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE/EEEEE MD:Z:31C26^G10 XG:Z:1 NH:i:1 NM:Z:1 XM:Z:1 XN:Z:0 XO:Z:1 AS:Z:-13 YT:Z:UU
mapped_read5 0 chr1 2946932 60 9M1D59M = 2946932 0 ACAAAACCTGGCCCACCCTGGTGAGGGGAGTTCTAGCCTCTCCCAGGCCCCCATGGCACGATCTAAGTG AAAEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE MD:Z:9^G25C33 XG:Z:1 NH:i:1 NM:Z:1 XM:Z:1 XN:Z:0 XO:Z:1 AS:Z:-13 YT:Z:UU
mapped_read6 0 chr1 4479047 60 42M2D57M = 4479047 0 GTGTAAAAGTGTTCCTTTTCACCACATCCATGCCAACGTCTATATTTTTTTTTTGGATTTTATATTAATTGGCCATTCTTGCAGGAGTAAGGTGGTATCTC AAAEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE//EEEEEEEEEEAAEEEEEEEEEEEEEEEEEEEEEEEEAEEEEEEEE MD:Z:42^T^T57 XG:Z:2 NH:i:1 NM:Z:0 XM:Z:0 XN:Z:0 XO:Z:1 AS:Z:-11 YT:Z:UU
This result bam/sam file was generated using the pysam module in python. Any help would be appreciated. I have tried using samtools 0.1.18, 1.2, 1.6, 1.13, all with the same error.
Thanks. cigar strings with deletions are clipped by 1. I am fixing it now.