// File: /workspace/github_cpp_makefile_star2_O2/simonrharris[P]SKA/src/sk_summary.cpp
// Function: summariseKmerFiles(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&)
int summariseKmerFiles(const std::vector < std::string > & kmerfiles)
{
	int kmersize;
	std::vector < std::string > fileSampleNames;
	std::ifstream fileStream;
	
	std::vector < char > baseorder = { 'A', 'C', 'G', 'T', 'N', 'O'};
	std::cout << "Sample\tKmer size\tTotal kmers\tAs\tCs\tGs\tTs\tNs\tOthers\tGC Content" << std::endl;
	for (int s = 0; s < kmerfiles.size(); ++s){
		
		if (openFileStream(kmerfiles[s], fileStream, false)){return 1;};
		
		readKmerHeader(fileStream, kmersize, fileSampleNames);

		std::map < char, std::vector < int > > basecounts{ {'A', std::vector < int > (fileSampleNames.size(), 0)}, {'C', std::vector < int > (fileSampleNames.size(), 0)}, {'G', std::vector < int > (fileSampleNames.size(), 0)}, {'T', std::vector < int > (fileSampleNames.size(), 0)}, {'N', std::vector < int > (fileSampleNames.size(), 0)}, {'O', std::vector < int > (fileSampleNames.size(), 0)}};

		std::vector < int > kmers(fileSampleNames.size(), 0);
		
		char base;
		char kmerbuffer[kmersize*2/3];
		char asciibuffer[int(ceil(float(fileSampleNames.size())/6))];

		while (fileStream.read(asciibuffer, sizeof(asciibuffer))){//read the ascii representation of the taxa
			std::string asciibits (asciibuffer, sizeof(asciibuffer));
			std::vector < bool > mybits;
			vectorbool_from_ascii(asciibits, mybits);//read the ascii representation of the taxa to a vector of bools

			while (fileStream.peek()!='\n' && fileStream.get(base)){
				base=toupper(base);
				fileStream.read(kmerbuffer, sizeof(kmerbuffer));
				std::string kmer (kmerbuffer, kmersize*2/3);
				
				for (int i=0; i<fileSampleNames.size(); ++i){ //add the kmer count to all samples that are true in the bitset
					if (mybits[i]){
						kmers[i]++;
						std::map < char, std::vector < int > >::iterator it = basecounts.find(base);//check if the kmer is in the map
						if ( it != basecounts.end() ){//if the kmer is in the map
							it->second[i]++;//increment the count for the base
						}
						else {//if the kmer isn't in the map
							basecounts['O'][i]++;//increment the count for other
						}
					}
				}
			}
			fileStream.ignore(256,'\n');//skip the end ofline character
    	}
		fileStream.close();
		
		for (int i=0; i<fileSampleNames.size(); ++i){ //print the results	
			std::cout << fileSampleNames[i] << "\t" << kmersize << "\t" << kmers[i] << "\t";
			for (std::vector < char >::iterator it=baseorder.begin(); it!=baseorder.end(); ++it){
				std::cout << basecounts[*it][i] << "\t";
			}
			float gccontent=(float(basecounts['C'][i])+float(basecounts['G'][i]))/(float(basecounts['A'][i])+float(basecounts['C'][i])+float(basecounts['G'][i])+float(basecounts['T'][i]));
			std::cout << gccontent << std::endl;
		}
    	fileSampleNames.clear();
	}

	return 0;
		
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x458, %rsp            # imm = 0x458
movq %rdi, -0x168(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
andq $0x0, -0x30(%rbp)
leaq -0x480(%rbp), %rdi
callq 0x5450
leaq -0x248(%rbp), %rsi
movl $0x54474341, (%rsi)     # imm = 0x54474341
movw $0x4f4e, 0x4(%rsi)      # imm = 0x4F4E
leaq -0x188(%rbp), %rdi
pushq $0x6
popq %rdx
leaq -0x278(%rbp), %rcx
callq 0x18124
movq 0x1e839(%rip), %rdi     # 0x35fb8
leaq 0xece1(%rip), %rsi      # 0x26467
callq 0x53f0
movq %rax, %rdi
callq 0x51c0
leaq -0x228(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0x208(%rbp), %rax
movq %rax, -0x148(%rbp)
leaq -0x1e8(%rbp), %rax
movq %rax, -0x140(%rbp)
leaq -0x1a8(%rbp), %rax
movq %rax, -0x138(%rbp)
xorl %ecx, %ecx
leaq -0x160(%rbp), %r15
leaq -0x278(%rbp), %r14
leaq -0x248(%rbp), %rbx
movq -0x168(%rbp), %rax
movq (%rax), %rdi
movq 0x8(%rax), %r12
subq %rdi, %r12
sarq $0x5, %r12
movq %rcx, -0x58(%rbp)
cmpq %rcx, %r12
jbe 0x17f36
movq -0x58(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rdi
leaq -0x480(%rbp), %rsi
xorl %edx, %edx
callq 0x73fe
testl %eax, %eax
jne 0x17f36
leaq -0x480(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0x832b
movq -0x38(%rbp), %rsi
subq -0x40(%rbp), %rsi
sarq $0x5, %rsi
andl $0x0, -0x44(%rbp)
leaq -0x110(%rbp), %rdi
leaq -0x44(%rbp), %rdx
leaq -0x50(%rbp), %rcx
callq 0xbe22
movb $0x41, -0x248(%rbp)
movaps -0x110(%rbp), %xmm0
movups %xmm0, -0x240(%rbp)
movq -0x100(%rbp), %rax
movq %rax, -0x230(%rbp)
andq $0x0, -0x100(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x110(%rbp)
movq -0x38(%rbp), %rsi
subq -0x40(%rbp), %rsi
sarq $0x5, %rsi
andl $0x0, -0x94(%rbp)
leaq -0xf0(%rbp), %rdi
leaq -0x94(%rbp), %rdx
leaq -0x4f(%rbp), %rcx
callq 0xbe22
movb $0x43, -0x228(%rbp)
movaps -0xf0(%rbp), %xmm0
movups %xmm0, -0x220(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0x210(%rbp)
andq $0x0, -0xe0(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0xf0(%rbp)
movq -0x38(%rbp), %rsi
subq -0x40(%rbp), %rsi
sarq $0x5, %rsi
andl $0x0, -0x90(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0x90(%rbp), %rdx
leaq -0x4e(%rbp), %rcx
callq 0xbe22
movb $0x47, -0x208(%rbp)
movaps -0xd0(%rbp), %xmm0
movups %xmm0, -0x200(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x1f0(%rbp)
andq $0x0, -0xc0(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0xd0(%rbp)
movq -0x38(%rbp), %rsi
subq -0x40(%rbp), %rsi
sarq $0x5, %rsi
andl $0x0, -0x8c(%rbp)
movq %r15, %rdi
leaq -0x8c(%rbp), %rdx
leaq -0x4d(%rbp), %rcx
callq 0xbe22
movb $0x54, -0x1e8(%rbp)
movaps -0x160(%rbp), %xmm0
movups %xmm0, -0x1e0(%rbp)
movq -0x150(%rbp), %rax
movq %rax, -0x1d0(%rbp)
andq $0x0, -0x150(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x160(%rbp)
movq -0x38(%rbp), %rsi
subq -0x40(%rbp), %rsi
sarq $0x5, %rsi
andl $0x0, -0x88(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0x88(%rbp), %rdx
leaq -0x4c(%rbp), %rcx
callq 0xbe22
movb $0x4e, -0x1c8(%rbp)
movaps -0xb0(%rbp), %xmm0
movups %xmm0, -0x1c0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x1b0(%rbp)
andq $0x0, -0xa0(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0xb0(%rbp)
movq -0x38(%rbp), %rsi
subq -0x40(%rbp), %rsi
sarq $0x5, %rsi
andl $0x0, -0x84(%rbp)
leaq -0x130(%rbp), %rdi
leaq -0x84(%rbp), %rdx
leaq -0x4b(%rbp), %rcx
callq 0xbe22
movb $0x4f, -0x1a8(%rbp)
movaps -0x130(%rbp), %xmm0
movups %xmm0, -0x1a0(%rbp)
movq -0x120(%rbp), %rax
movq %rax, -0x190(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x130(%rbp)
andq $0x0, -0x120(%rbp)
movq %r14, %rdi
movq %rbx, %rsi
pushq $0x6
popq %rdx
leaq -0x4a(%rbp), %rcx
leaq -0x49(%rbp), %r8
callq 0x1815a
movl $0xa8, %r12d
leaq (%r12,%rbp), %rdi
addq $-0x248, %rdi           # imm = 0xFDB8
callq 0xc052
addq $-0x20, %r12
cmpq $-0x18, %r12
jne 0x17a82
leaq -0x130(%rbp), %rdi
callq 0xc052
leaq -0xb0(%rbp), %rdi
callq 0xc052
movq %r15, %rdi
callq 0xc052
leaq -0xd0(%rbp), %r13
movq %r13, %rdi
callq 0xc052
leaq -0xf0(%rbp), %rdi
callq 0xc052
leaq -0x110(%rbp), %r12
movq %r12, %rdi
callq 0xc052
movq -0x38(%rbp), %rsi
subq -0x40(%rbp), %rsi
sarq $0x5, %rsi
andl $0x0, -0x248(%rbp)
movq %r13, %rdi
movq %rbx, %rdx
movq %r12, %rcx
callq 0xbe22
movq %rsp, %rsi
movl -0x48(%rbp), %eax
addl %eax, %eax
cltd
pushq $0x3
popq %rcx
idivl %ecx
movq %rax, -0x80(%rbp)
addq $0xf, %rax
andq $-0x10, %rax
movq %rsp, %r12
subq %rax, %r12
movq %r12, %rsp
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
sarq $0x5, %rax
movq %rsi, -0x170(%rbp)
js 0x17b46
cvtsi2ss %rax, %xmm0
jmp 0x17b5b
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
cvtsi2ss %rax, %xmm0
addss %xmm0, %xmm0
divss 0xdb0d(%rip), %xmm0     # 0x25670
callq 0x5220
cvttss2si %xmm0, %ecx
leaq 0xf(%rcx), %rax
andq $-0x10, %rax
movq %rsp, %rdx
subq %rax, %rdx
movq %rdx, %rsp
movq %rcx, -0x78(%rbp)
movq %rdx, -0x60(%rbp)
leaq (%rdx,%rcx), %rax
movq %rax, -0x70(%rbp)
leaq -0x480(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x78(%rbp), %rdx
callq 0x54c0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x17d3e
leaq -0x100(%rbp), %rax
movq %rax, -0x110(%rbp)
leaq -0x110(%rbp), %r13
movq %r13, %rdi
movq -0x60(%rbp), %rsi
movq -0x70(%rbp), %rdx
callq 0x7828
andq $0x0, -0x248(%rbp)
andl $0x0, -0x240(%rbp)
andq $0x0, -0x238(%rbp)
andl $0x0, -0x230(%rbp)
andq $0x0, -0x228(%rbp)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x7bb6
leaq -0x480(%rbp), %rdi
callq 0x5140
cmpl $0xa, %eax
je 0x17d11
leaq -0x480(%rbp), %rdi
movq %r15, %rsi
callq 0x5550
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x17d11
movsbl -0x160(%rbp), %edi
callq 0x56f0
movb %al, -0x160(%rbp)
leaq -0x480(%rbp), %rdi
movq %r12, %rsi
movq -0x80(%rbp), %rdx
callq 0x54c0
movl -0x48(%rbp), %eax
addl %eax, %eax
cltd
pushq $0x3
popq %rcx
idivl %ecx
movslq %eax, %rdx
leaq -0xe0(%rbp), %rax
movq %rax, -0xf0(%rbp)
addq %r12, %rdx
leaq -0xf0(%rbp), %rdi
movq %r12, %rsi
callq 0x7828
xorl %r13d, %r13d
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
sarq $0x5, %rax
cmpq %r13, %rax
jbe 0x17d00
movq %rbx, %rdi
movq %r13, %rsi
callq 0x903c
testq %rdx, (%rax)
je 0x17cfb
movq -0xd0(%rbp), %rax
incl (%rax,%r13,4)
movq %r14, %rdi
movq %r15, %rsi
callq 0x185cc
leaq -0x270(%rbp), %rcx
cmpq %rcx, %rax
je 0x17cde
movq 0x28(%rax), %rax
jmp 0x17cf7
movb $0x4f, -0xb0(%rbp)
movq %r14, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x181a2
movq (%rax), %rax
incl (%rax,%r13,4)
incq %r13
jmp 0x17c95
leaq -0xf0(%rbp), %rdi
callq 0x5778
jmp 0x17c09
movl $0x100, %esi            # imm = 0x100
leaq -0x480(%rbp), %rdi
pushq $0xa
popq %rdx
callq 0x5260
movq %rbx, %rdi
callq 0x908a
leaq -0x110(%rbp), %rdi
callq 0x5778
jmp 0x17b8d
leaq -0x480(%rbp), %rdi
callq 0x50a0
xorl %r13d, %r13d
movq -0x58(%rbp), %r12
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rax
subq %rsi, %rax
sarq $0x5, %rax
cmpq %r13, %rax
jbe 0x17f07
movq %r13, %rax
shlq $0x5, %rax
addq %rax, %rsi
movq 0x1e23e(%rip), %rdi     # 0x35fb8
callq 0x53a0
movq %rax, %rdi
leaq 0xe538(%rip), %rsi      # 0x262c1
callq 0x53f0
movl -0x48(%rbp), %esi
movq %rax, %rdi
callq 0x56a0
movq %rax, %rdi
leaq 0xe51e(%rip), %rsi      # 0x262c1
callq 0x53f0
movq -0xd0(%rbp), %rcx
movl (%rcx,%r13,4), %esi
movq %rax, %rdi
callq 0x56a0
movq %rax, %rdi
leaq 0xe4fc(%rip), %rsi      # 0x262c1
callq 0x53f0
movq -0x188(%rbp), %r12
cmpq -0x180(%rbp), %r12
je 0x17e0c
movq %r14, %rdi
movq %r12, %rsi
callq 0x181f0
movq (%rax), %rax
movl (%rax,%r13,4), %esi
movq 0x1e1c5(%rip), %rdi     # 0x35fb8
callq 0x56a0
movq %rax, %rdi
leaq 0xe4bf(%rip), %rsi      # 0x262c1
callq 0x53f0
incq %r12
jmp 0x17dd1
movb $0x43, -0x248(%rbp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x181a2
movq (%rax), %rax
movl (%rax,%r13,4), %r12d
movb $0x47, -0x110(%rbp)
movq %r14, %rdi
leaq -0x110(%rbp), %rsi
callq 0x181a2
movq (%rax), %rax
cvtsi2ssl (%rax,%r13,4), %xmm0
movss %xmm0, -0x80(%rbp)
movb $0x41, -0xf0(%rbp)
movq %r14, %rdi
leaq -0xf0(%rbp), %rsi
callq 0x181a2
movq (%rax), %rax
movl (%rax,%r13,4), %eax
movl %eax, -0x60(%rbp)
movb $0x43, -0xb0(%rbp)
movq %r14, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x181a2
movq (%rax), %rax
movl (%rax,%r13,4), %eax
movl %eax, -0x78(%rbp)
movb $0x47, -0x130(%rbp)
movq %r14, %rdi
leaq -0x130(%rbp), %rsi
callq 0x181a2
movq (%rax), %rax
movl (%rax,%r13,4), %eax
movl %eax, -0x70(%rbp)
movb $0x54, -0x44(%rbp)
movq %r14, %rdi
leaq -0x44(%rbp), %rsi
callq 0x181a2
cvtsi2ss %r12d, %xmm0
cvtsi2ssl -0x60(%rbp), %xmm1
cvtsi2ssl -0x78(%rbp), %xmm2
addss -0x80(%rbp), %xmm0
cvtsi2ssl -0x70(%rbp), %xmm3
movq (%rax), %rax
cvtsi2ssl (%rax,%r13,4), %xmm4
addss %xmm1, %xmm2
addss %xmm2, %xmm3
addss %xmm3, %xmm4
divss %xmm4, %xmm0
movq 0x1e0c6(%rip), %rdi     # 0x35fb8
callq 0x5300
movq %rax, %rdi
callq 0x51c0
incq %r13
jmp 0x17d4d
leaq -0x40(%rbp), %rdi
callq 0xbe96
movq -0x170(%rbp), %rsp
leaq -0xd0(%rbp), %rdi
callq 0xc052
movq %r14, %rdi
callq 0x1823e
incq %r12
movq %r12, %rcx
jmp 0x177df
xorl %ebx, %ebx
cmpq -0x58(%rbp), %r12
seta %bl
leaq -0x188(%rbp), %rdi
callq 0x1435a
leaq -0x480(%rbp), %rdi
callq 0x50e0
leaq -0x40(%rbp), %rdi
callq 0x911e
movl %ebx, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
jmp 0x18106
movq %rax, %r14
jmp 0x18112
jmp 0x18090
jmp 0x180b2
movq %rax, %r14
movl $0xa8, %r15d
leaq (%r15,%rbp), %rdi
addq $-0x248, %rdi           # imm = 0xFDB8
callq 0xc052
addq $-0x20, %r15
cmpq $-0x18, %r15
jne 0x17f94
leaq -0x130(%rbp), %rdi
callq 0xc052
movb $0x1, %r15b
jmp 0x17fc5
movq %rax, %r14
xorl %r15d, %r15d
leaq -0xb0(%rbp), %rdi
callq 0xc052
jmp 0x17fe7
movq %rax, %r14
xorl %r15d, %r15d
leaq -0x1c8(%rbp), %rax
movq %rax, -0x138(%rbp)
leaq -0x160(%rbp), %rdi
callq 0xc052
movq -0x138(%rbp), %rax
movq %rax, -0x140(%rbp)
jmp 0x18009
movq %rax, %r14
xorl %r15d, %r15d
leaq -0xd0(%rbp), %rdi
callq 0xc052
movq -0x140(%rbp), %rax
movq %rax, -0x148(%rbp)
jmp 0x1802b
movq %rax, %r14
xorl %r15d, %r15d
leaq -0xf0(%rbp), %rdi
callq 0xc052
movq -0x148(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0x110(%rbp), %rdi
callq 0xc052
cmpq -0x68(%rbp), %rbx
sete %al
testb %r15b, %r15b
jne 0x180fa
testb %al, %al
jne 0x180fa
movq -0x68(%rbp), %rdi
leaq -0x20(%rdi), %r15
addq $-0x18, %rdi
callq 0xc052
movq %r15, %rdi
cmpq %rbx, %r15
jne 0x1806a
jmp 0x180fa
movq %rax, %r14
xorl %r15d, %r15d
jmp 0x18042
jmp 0x18090
movq %rax, %r14
jmp 0x180ee
movq %rax, %r14
jmp 0x180fa
jmp 0x180b2
jmp 0x180b2
jmp 0x180b2
jmp 0x180b2
jmp 0x180b2
jmp 0x180b2
jmp 0x180b2
jmp 0x180b2
jmp 0x180b2
jmp 0x180ad
jmp 0x180b2
jmp 0x180ad
movq %rax, %r14
jmp 0x180ca
movq %rax, %r14
jmp 0x180e2
jmp 0x180bb
jmp 0x180bb
movq %rax, %r14
leaq -0xf0(%rbp), %rdi
callq 0x5778
leaq -0x248(%rbp), %rdi
callq 0x908a
leaq -0x110(%rbp), %rdi
callq 0x5778
leaq -0xd0(%rbp), %rdi
callq 0xc052
leaq -0x278(%rbp), %rdi
callq 0x1823e
leaq -0x188(%rbp), %rdi
callq 0x1435a
leaq -0x480(%rbp), %rdi
callq 0x50e0
leaq -0x40(%rbp), %rdi
callq 0x911e
movq %r14, %rdi
callq 0x56c0
nop