// File: CK7[P]abawaca/src/ReadMapping.cpp
// Function: Bio::ReadMapping::ReadMapping(char const*)
ReadMapping::ReadMapping(const char* SAM_line)
{
        // HWI-ST330_0096:2:2:5723:2221#TTAGGC/2        16      NODE_107_length_1448229_cov_184.575043  816000  255     85M     *       0       0       
        // AAGAANAAGCAACAAAAGGTAATTTGACAGTTGCAGGTCATGATTTAATGAACATAAAAAATAAAGAAGTTCCTTATTTACGTCG
        // A<6BB#3917.-8?4CDD?:D86DCD6;EC=BCDA,D=D:C>A+CCAA;0B>+B7ECEE?BEEFECDCCD7>1:;EE8DCEF8CF        XA:i:0  MD:Z:5A46A32    NM:i:2

        // HWI-ST330_0096:2:2:8826:2326#TTAGGC/2        4       *       0       0       *       *       0       0
        // TTTTACAGGCACTAATGCACACAGAAAAGGTTTCCAGGCAATTTTCAATGCTTGCTATAAAGCATAAATACTTAATAAAGAATTATTTTCCTTCAGATTA
        // HHHHHHHHHHEHHHHHHHHHHHHHHHHHHHDGHFFEFFDGGHFHEFBFBEHHEBHGHHHHHBEHG?FGGEHBG7HGBFH?DC?FBAB?=AFEBBFA+9DG XM:i:0

	string CIGAR_indels, CIGAR_mismatches;
	vector<string>	fs;

	split('\t', SAM_line, fs);

	QNAME = fs[0];
	FLAG = atoi(fs[1].c_str());
	RNAME = fs[2];
	POS = atoi(fs[3].c_str())-1;
	CIGAR_indels = fs[5];
	if(!strcmp(fs[6].c_str(), "=")) {
		m_same_ref = true;
		RNEXT = RNAME;
	}
	else {
		m_same_ref = false;
		RNEXT = fs[6];
	}
	PNEXT = atoi(fs[7].c_str())-1;
	TLEN = atoi(fs[8].c_str());
	SEQ = Bio::DNAString(fs[9]);
	QUAL = fs[10];

	// Look for the mismatch CIGAR string 
	for(int i=11; i<fs.size(); i++) {
		size_t pos_mdz = fs[i].find("MD:Z:");
		if(pos_mdz != string::npos) {
			size_t e = fs[i].find(" ", pos_mdz);
			if(e==string::npos) {
				CIGAR_mismatches = fs[i].substr(pos_mdz);
			}
			else {
				CIGAR_mismatches = fs[i].substr(pos_mdz, (e-pos_mdz+1));
			}
			break;
		}
	}	

	this->determine_snps(SEQ, QUAL, CIGAR_indels, CIGAR_mismatches, POS); 
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1e0, %rsp            # imm = 0x1E0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x168(%rbp)
leaq 0x2b99b(%rip), %rax     # 0x31830
movq %rax, (%rdi)
addq $0x8, %rdi
movq %rdi, -0x180(%rbp)
callq 0x4490
movq -0x168(%rbp), %rdi
addq $0x30, %rdi
movq %rdi, -0x178(%rbp)
callq 0x4490
movq -0x168(%rbp), %rdi
addq $0x58, %rdi
movq %rdi, -0x170(%rbp)
callq 0x4490
movq -0x168(%rbp), %rdi
addq $0x88, %rdi
movq %rdi, -0x160(%rbp)
callq 0x65b0
jmp 0x5ef2
movq -0x168(%rbp), %rdi
addq $0xa8, %rdi
movq %rdi, -0x1a0(%rbp)
callq 0x4490
movq -0x168(%rbp), %rdi
addq $0xd0, %rdi
movq %rdi, -0x198(%rbp)
callq 0x6510
leaq -0x40(%rbp), %rdi
callq 0x4490
leaq -0x60(%rbp), %rdi
callq 0x4490
leaq -0x78(%rbp), %rdi
callq 0x65d0
movq -0x10(%rbp), %rax
movq %rax, -0x190(%rbp)
leaq -0x99(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0x45d0
movq -0x190(%rbp), %rsi
movq -0x188(%rbp), %rdx
leaq -0x98(%rbp), %rdi
callq 0x4470
jmp 0x5f7b
movl $0x9, %edi
leaq -0x98(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x1eef0
jmp 0x5f92
leaq -0x98(%rbp), %rdi
callq 0x41c0
leaq -0x99(%rbp), %rdi
callq 0x4370
xorl %eax, %eax
movl %eax, %esi
leaq -0x78(%rbp), %rdi
callq 0x65f0
movq -0x168(%rbp), %rdi
movq %rax, %rsi
addq $0x8, %rdi
callq 0x4050
jmp 0x5fcc
leaq -0x78(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
movl $0x1, %esi
callq 0x65f0
movq %rax, %rdi
callq 0x4130
movq %rax, %rdi
callq 0x4520
movq -0x1a8(%rbp), %rdi
movl %eax, %ecx
movq -0x168(%rbp), %rax
movslq %ecx, %rcx
movq %rcx, 0x28(%rax)
movl $0x2, %esi
callq 0x65f0
movq -0x168(%rbp), %rdi
movq %rax, %rsi
addq $0x30, %rdi
callq 0x4050
jmp 0x6027
leaq -0x78(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
movl $0x3, %esi
callq 0x65f0
movq %rax, %rdi
callq 0x4130
movq %rax, %rdi
callq 0x4520
movq -0x1b0(%rbp), %rdi
movl %eax, %ecx
movq -0x168(%rbp), %rax
decl %ecx
movslq %ecx, %rcx
movq %rcx, 0x50(%rax)
movl $0x5, %esi
callq 0x65f0
movq %rax, %rsi
leaq -0x40(%rbp), %rdi
callq 0x4050
jmp 0x607d
leaq -0x78(%rbp), %rdi
movl $0x6, %esi
callq 0x65f0
movq %rax, %rdi
callq 0x4130
movq %rax, %rdi
leaq 0x1bf67(%rip), %rsi     # 0x22004
callq 0x44a0
cmpl $0x0, %eax
jne 0x6125
movq -0x168(%rbp), %rdi
movb $0x1, 0xc8(%rdi)
movq %rdi, %rsi
addq $0x30, %rsi
addq $0x58, %rdi
callq 0x4050
jmp 0x60c7
jmp 0x6158
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x64b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x6103
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x41c0
leaq -0x99(%rbp), %rdi
callq 0x4370
jmp 0x6472
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x6472
movq -0x168(%rbp), %rax
movb $0x0, 0xc8(%rax)
leaq -0x78(%rbp), %rdi
movl $0x6, %esi
callq 0x65f0
movq -0x168(%rbp), %rdi
movq %rax, %rsi
addq $0x58, %rdi
callq 0x4050
jmp 0x6156
jmp 0x6158
leaq -0x78(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
movl $0x7, %esi
callq 0x65f0
movq %rax, %rdi
callq 0x4130
movq %rax, %rdi
callq 0x4520
movq -0x1b8(%rbp), %rdi
movl %eax, %ecx
movq -0x168(%rbp), %rax
decl %ecx
movslq %ecx, %rcx
movq %rcx, 0x78(%rax)
movl $0x8, %esi
callq 0x65f0
movq %rax, %rdi
callq 0x4130
movq %rax, %rdi
callq 0x4520
movq -0x1b8(%rbp), %rdi
movl %eax, %ecx
movq -0x168(%rbp), %rax
movl %ecx, 0x80(%rax)
movl $0x9, %esi
callq 0x65f0
movq %rax, %rsi
leaq -0xc0(%rbp), %rdi
callq 0x1fbf0
jmp 0x61e1
movq -0x168(%rbp), %rdi
addq $0x88, %rdi
leaq -0xc0(%rbp), %rsi
movq %rsi, -0x1c0(%rbp)
callq 0x6610
movq -0x1c0(%rbp), %rdi
callq 0x6590
leaq -0x78(%rbp), %rdi
movl $0xa, %esi
callq 0x65f0
movq -0x168(%rbp), %rdi
movq %rax, %rsi
addq $0xa8, %rdi
callq 0x4050
jmp 0x6234
movl $0xb, -0xc4(%rbp)
movslq -0xc4(%rbp), %rax
movq %rax, -0x1c8(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x6640
movq %rax, %rcx
movq -0x1c8(%rbp), %rax
cmpq %rcx, %rax
jae 0x638d
movslq -0xc4(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x65f0
movq %rax, %rdi
leaq 0x1bd84(%rip), %rsi     # 0x22006
xorl %eax, %eax
movl %eax, %edx
callq 0x4670
movq %rax, -0xd0(%rbp)
cmpq $-0x1, -0xd0(%rbp)
je 0x6377
movslq -0xc4(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x65f0
movq %rax, %rdi
movq -0xd0(%rbp), %rdx
leaq 0x1bf49(%rip), %rsi     # 0x2220a
callq 0x4670
movq %rax, -0xd8(%rbp)
cmpq $-0x1, -0xd8(%rbp)
jne 0x6324
movslq -0xc4(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x65f0
movq %rax, %rsi
movq -0xd0(%rbp), %rdx
leaq -0xf8(%rbp), %rdi
movq $-0x1, %rcx
callq 0x4320
jmp 0x6306
leaq -0x60(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x4400
leaq -0xf8(%rbp), %rdi
callq 0x41c0
jmp 0x6375
movslq -0xc4(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x65f0
movq %rax, %rsi
movq -0xd0(%rbp), %rdx
movq -0xd8(%rbp), %rcx
subq %rdx, %rcx
incq %rcx
leaq -0x118(%rbp), %rdi
callq 0x4320
jmp 0x6359
leaq -0x60(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x4400
leaq -0x118(%rbp), %rdi
callq 0x41c0
jmp 0x638d
jmp 0x6379
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0x623e
movq -0x168(%rbp), %rax
movq %rax, %rcx
addq $0x88, %rcx
movq %rcx, -0x1d8(%rbp)
addq $0xa8, %rax
movq %rax, -0x1d0(%rbp)
leaq -0x138(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x4140
jmp 0x63c4
leaq -0x158(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x4140
jmp 0x63d6
movq -0x1d0(%rbp), %rdx
movq -0x1d8(%rbp), %rsi
movq -0x168(%rbp), %rdi
movq 0x50(%rdi), %r9
leaq -0x138(%rbp), %rcx
leaq -0x158(%rbp), %r8
callq 0x4c00
jmp 0x6404
leaq -0x158(%rbp), %rdi
callq 0x41c0
leaq -0x138(%rbp), %rdi
callq 0x41c0
leaq -0x78(%rbp), %rdi
callq 0x6660
leaq -0x60(%rbp), %rdi
callq 0x41c0
leaq -0x40(%rbp), %rdi
callq 0x41c0
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x6466
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x41c0
leaq -0x138(%rbp), %rdi
callq 0x41c0
leaq -0x78(%rbp), %rdi
callq 0x6660
leaq -0x60(%rbp), %rdi
callq 0x41c0
leaq -0x40(%rbp), %rdi
callq 0x41c0
movq -0x198(%rbp), %rdi
callq 0x6530
movq -0x1a0(%rbp), %rdi
callq 0x41c0
movq -0x160(%rbp), %rdi
callq 0x6590
movq -0x170(%rbp), %rdi
callq 0x41c0
movq -0x178(%rbp), %rdi
callq 0x41c0
movq -0x180(%rbp), %rdi
callq 0x41c0
movq -0x18(%rbp), %rdi
callq 0x45c0
nop