// File: simonrharris[P]SKA/src/sk_refalign.cpp
// Function: printVariantSites(std::basic_ofstream<char, std::char_traits<char>>&, int, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&)
void printVariantSites(std::ofstream & myOutfile, const int totalbases, const std::vector < std::string > & sampleNames, const std::vector < std::string > & mySequences){
	std::vector < int > sitestoprint;
	sitestoprint.reserve(10000);
	std::vector < int > constantBases (4, 0);
	for (int i=0; i<totalbases; ++i){

		std::vector < int > baseVector (6, 0);

		for (int j=0; j<sampleNames.size(); ++j){
			char base=toupper(mySequences[j][i]);
			baseVector[base_score[base]]++;
		}

		int acgtCount=0;
		int constbase=-1;

		for (int i=0; i<4; ++i){
			if (baseVector[i]>0){
				acgtCount++;
				constbase=i;
			}
		}

		if (acgtCount==1){
			constantBases[constbase]++;
		}
		else if (acgtCount>1) {
			sitestoprint.push_back(i);
		}
		
	}

	std::cout << "Printing alignment of " << sitestoprint.size() << " variant sites" << std::endl;

	for (int i=0; i<sampleNames.size(); ++i){
		std::string mySequence (sitestoprint.size(), '-');
		for (int j=0; j<sitestoprint.size(); ++j){
			mySequence[j]=mySequences[i][sitestoprint[j]];
		}
		myOutfile << ">" << sampleNames[i] << std::endl << mySequence << std::endl;
	}

	std::cout << "Constant sites (a c g t):" << std::endl;
	std::cout << constantBases[0] << " " << constantBases[1]  << " " << constantBases[2]  << " " << constantBases[3]  << std::endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x1ac10
movq -0xd8(%rbp), %rdi
movl $0x2710, %esi           # imm = 0x2710
callq 0x2e050
jmp 0x3678d
movl $0x0, -0x64(%rbp)
leaq -0x65(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x1a8f0
movq -0xe0(%rbp), %rcx
leaq -0x60(%rbp), %rdi
movl $0x4, %esi
leaq -0x64(%rbp), %rdx
callq 0x1a910
jmp 0x367bf
leaq -0x65(%rbp), %rdi
callq 0x1a990
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x369e8
movl $0x0, -0x8c(%rbp)
leaq -0x8d(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x1a8f0
movq -0xe8(%rbp), %rcx
leaq -0x88(%rbp), %rdi
movl $0x6, %esi
leaq -0x8c(%rbp), %rdx
callq 0x1a910
jmp 0x36819
leaq -0x8d(%rbp), %rdi
callq 0x1a990
movl $0x0, -0x94(%rbp)
movslq -0x94(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x18(%rbp), %rdi
callq 0xb670
movq %rax, %rcx
movq -0xf0(%rbp), %rax
cmpq %rcx, %rax
jae 0x36906
movq -0x20(%rbp), %rdi
movslq -0x94(%rbp), %rsi
callq 0xf2d0
movq %rax, %rdi
movslq -0x6c(%rbp), %rsi
callq 0x65c0
movsbl (%rax), %edi
callq 0x6a20
movb %al, -0x95(%rbp)
movsbq -0x95(%rbp), %rcx
leaq 0x42cfe(%rip), %rax     # 0x79590
movsbq (%rax,%rcx), %rsi
leaq -0x88(%rbp), %rdi
callq 0x1a9b0
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x3682f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x36dd5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x65(%rbp), %rdi
callq 0x1a990
jmp 0x36dd5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x8d(%rbp), %rdi
callq 0x1a990
jmp 0x36dcc
movl $0x0, -0x9c(%rbp)
movl $0xffffffff, -0xa0(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0xa4(%rbp)
cmpl $0x4, -0xa4(%rbp)
jge 0x36973
movslq -0xa4(%rbp), %rsi
leaq -0x88(%rbp), %rdi
callq 0x1a9b0
cmpl $0x0, (%rax)
jle 0x36960
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
movl -0xa4(%rbp), %eax
movl %eax, -0xa0(%rbp)
jmp 0x36962
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x36924
cmpl $0x1, -0x9c(%rbp)
jne 0x36995
movslq -0xa0(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x1a9b0
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x369ce
cmpl $0x1, -0x9c(%rbp)
jle 0x369cc
leaq -0x38(%rbp), %rdi
leaq -0x6c(%rbp), %rsi
callq 0x1ac30
jmp 0x369ad
jmp 0x369cc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x1aa00
jmp 0x36dcc
jmp 0x369ce
leaq -0x88(%rbp), %rdi
callq 0x1aa00
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x367cf
movq 0x425b9(%rip), %rdi     # 0x78fa8
leaq 0x22c92(%rip), %rsi     # 0x59688
callq 0x6520
movq %rax, -0xf8(%rbp)
jmp 0x36a04
leaq -0x38(%rbp), %rdi
callq 0xf7f0
movq -0xf8(%rbp), %rdi
movq %rax, %rsi
callq 0x6120
movq %rax, -0x100(%rbp)
jmp 0x36a25
movq -0x100(%rbp), %rdi
leaq 0x23955(%rip), %rsi     # 0x5a388
callq 0x6520
movq %rax, -0x108(%rbp)
jmp 0x36a41
movq -0x108(%rbp), %rdi
movq 0x42541(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x36a56
movl $0x0, -0xa8(%rbp)
movslq -0xa8(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x18(%rbp), %rdi
callq 0xb670
movq %rax, %rcx
movq -0x110(%rbp), %rax
cmpq %rcx, %rax
jae 0x36c84
leaq -0x38(%rbp), %rdi
callq 0xf7f0
movq %rax, -0x120(%rbp)
leaq -0xc9(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x6910
movq -0x120(%rbp), %rsi
movq -0x118(%rbp), %rcx
leaq -0xc8(%rbp), %rdi
movl $0x2d, %edx
callq 0x9150
jmp 0x36ace
leaq -0xc9(%rbp), %rdi
callq 0x65a0
movl $0x0, -0xd0(%rbp)
movslq -0xd0(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq -0x38(%rbp), %rdi
callq 0xf7f0
movq %rax, %rcx
movq -0x128(%rbp), %rax
cmpq %rcx, %rax
jae 0x36bd6
movq -0x20(%rbp), %rdi
movslq -0xa8(%rbp), %rsi
callq 0xf2d0
movq %rax, -0x140(%rbp)
movslq -0xd0(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x1a9b0
movq -0x140(%rbp), %rdi
movslq (%rax), %rsi
callq 0x65c0
movb (%rax), %al
movb %al, -0x131(%rbp)
movslq -0xd0(%rbp), %rsi
leaq -0xc8(%rbp), %rdi
callq 0x69e0
movq %rax, -0x130(%rbp)
jmp 0x36b68
movq -0x130(%rbp), %rax
movb -0x131(%rbp), %cl
movb %cl, (%rax)
movl -0xd0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd0(%rbp)
jmp 0x36ae4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x36dcc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xc9(%rbp), %rdi
callq 0x65a0
jmp 0x36dcc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x6a08
jmp 0x36dcc
movq -0x8(%rbp), %rdi
leaq 0x234a6(%rip), %rsi     # 0x5a087
callq 0x6520
movq %rax, -0x148(%rbp)
jmp 0x36bef
movq -0x18(%rbp), %rdi
movslq -0xa8(%rbp), %rsi
callq 0xf2d0
movq -0x148(%rbp), %rdi
movq %rax, %rsi
callq 0x64d0
movq %rax, -0x150(%rbp)
jmp 0x36c17
movq -0x150(%rbp), %rdi
movq 0x4236b(%rip), %rsi     # 0x78f90
callq 0x6570
movq %rax, -0x158(%rbp)
jmp 0x36c33
movq -0x158(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x64d0
movq %rax, -0x160(%rbp)
jmp 0x36c4f
movq -0x160(%rbp), %rdi
movq 0x42333(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x36c64
leaq -0xc8(%rbp), %rdi
callq 0x6a08
movl -0xa8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa8(%rbp)
jmp 0x36a60
movq 0x4231d(%rip), %rdi     # 0x78fa8
leaq 0x23705(%rip), %rsi     # 0x5a397
callq 0x6520
movq %rax, -0x168(%rbp)
jmp 0x36ca0
movq -0x168(%rbp), %rdi
movq 0x422e2(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x36cb5
xorl %eax, %eax
movl %eax, %esi
leaq -0x60(%rbp), %rdi
callq 0x1a9b0
movl (%rax), %esi
movq 0x422dd(%rip), %rdi     # 0x78fa8
callq 0x68d0
movq %rax, -0x170(%rbp)
jmp 0x36cd9
movq -0x170(%rbp), %rdi
leaq 0x23666(%rip), %rsi     # 0x5a34d
callq 0x6520
movq %rax, -0x178(%rbp)
jmp 0x36cf5
leaq -0x60(%rbp), %rdi
movl $0x1, %esi
callq 0x1a9b0
movq -0x178(%rbp), %rdi
movl (%rax), %esi
callq 0x68d0
movq %rax, -0x180(%rbp)
jmp 0x36d1a
movq -0x180(%rbp), %rdi
leaq 0x23625(%rip), %rsi     # 0x5a34d
callq 0x6520
movq %rax, -0x188(%rbp)
jmp 0x36d36
leaq -0x60(%rbp), %rdi
movl $0x2, %esi
callq 0x1a9b0
movq -0x188(%rbp), %rdi
movl (%rax), %esi
callq 0x68d0
movq %rax, -0x190(%rbp)
jmp 0x36d5b
movq -0x190(%rbp), %rdi
leaq 0x235e4(%rip), %rsi     # 0x5a34d
callq 0x6520
movq %rax, -0x198(%rbp)
jmp 0x36d77
leaq -0x60(%rbp), %rdi
movl $0x3, %esi
callq 0x1a9b0
movq -0x198(%rbp), %rdi
movl (%rax), %esi
callq 0x68d0
movq %rax, -0x1a0(%rbp)
jmp 0x36d9c
movq -0x1a0(%rbp), %rdi
movq 0x421e6(%rip), %rsi     # 0x78f90
callq 0x6570
jmp 0x36db1
leaq -0x60(%rbp), %rdi
callq 0x1aa00
leaq -0x38(%rbp), %rdi
callq 0x1aa00
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
leaq -0x60(%rbp), %rdi
callq 0x1aa00
leaq -0x38(%rbp), %rdi
callq 0x1aa00
movq -0x40(%rbp), %rdi
callq 0x6900
nopw (%rax,%rax)