// File: /workspace/github_cpp_makefile_star2_O2/gcollet[P]MstatX/src/msa.cpp
// Function: Msa::Msa(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
Msa :: Msa(string fname)
{
	/* Open file */
	if (Options::Get().verbose){
		cout << "Read Multiple Alignment in " << fname << "\n";
	}
	ifstream file(fname.c_str());
	if (!file.good()){
	  cerr << "Cannot open file " << fname << "\n";
		exit(0);
	}

	
	/* Read file */
	string s, tmp_seq;
	while (file.good() && (int) mali_seq.size() < Options::Get().nb_seq){
		getline(file,s);
		if (s[0] == '>'){
			if (mali_name.size() != 0){
			  mali_seq.push_back(tmp_seq);	
			}
			if ((int) mali_seq.size() < Options::Get().nb_seq){
  			mali_name.push_back(s.substr(1, s.find_first_of(' ') - 1));
			}
			tmp_seq.clear();
		} else {
			tmp_seq = tmp_seq + s;
		}
	}
	if ((int) mali_seq.size() < Options::Get().nb_seq){
	  mali_seq.push_back(tmp_seq);
	}
	
	nseq = (int) mali_name.size();
	ncol = (int) mali_seq[0].size();
	cout << "\nMultiple alignment : nb seq = "<<nseq<<", nb col = "<<ncol<<"\n";
	
	/* Change all mali.seq in upper case*/
	for (int i(0); i < nseq; ++i){
		for(int j(0); j < ncol; ++j){
			mali_seq[i][j] = toupper(mali_seq[i][j]);
		}
	}
	
	/* Analyse the multiple alignment */
	defineAlphabet();
	countGap();
	countFreq();
	countType();
	countEntropy();
	
	
	/* Print if verbose mode */
	if (Options::Get().verbose){
		cout << "\nAlphabet :\n";
	  for(int i(0); i < (int) alphabet.size(); ++i){
			cout << alphabet[i] << ";";
		}
		cout << "\n";
		cout << "\nMultiple Alignment :\n";
	  for(int i(0); i <nseq; ++i){
			cout << mali_seq[i] << "\n";
		}
		cout << "\nAA Frequencies :\n";
		for (int i(0); i < (int) aa_freq.size(); ++i){
			cout << aa_freq[i] << ";";
		}
		cout << "\n";
		cout << "\nGap counts :\n";
		for (int i(0); i < (int) gap_counts.size(); ++i){
			cout << gap_counts[i] << ";";
		}
		cout << "\n";
		cout << "\nAA Entropy :\n";
		for (int i(0); i < (int) entropy.size(); ++i){
			if (gap_counts[i] < nseq/10){
		  	cout << entropy[i] << ";";
			} else {
				cout << "-12.0;";
			}
		}
		cout << "\n";
		cout << "\nAA Types :\n";
		for (int i(0); i < (int) nb_type.size(); ++i){
				cout << nb_type[i] << ";";
		}
		cout << "\n";
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
movq %rdi, %rbx
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
andq $0x0, 0x8(%rdi)
movq %rsi, %r14
movb $0x0, 0x10(%rdi)
addq $0x20, %rdi
leaq 0x38(%rbx), %r15
movl $0xa8, %edx
movq %rdi, 0x8(%rsp)
xorl %esi, %esi
callq 0x4160
callq 0x4a00
cmpb $0x1, 0xec(%rax)
jne 0x90bf
movq 0x9f27(%rip), %rdi      # 0x12fc0
leaq 0x4580(%rip), %rsi      # 0xd620
callq 0x4250
movq %rax, %rdi
movq %r14, %rsi
callq 0x4240
leaq 0x443f(%rip), %rsi      # 0xd4f6
movq %rax, %rdi
callq 0x4250
movq (%r14), %rsi
leaq 0x70(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x4470
movq 0x70(%rsp), %rax
movq -0x18(%rax), %rcx
cmpl $0x0, 0x90(%rsp,%rcx)
jne 0x95dc
leaq 0x40(%rsp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
xorl %edx, %edx
leaq 0x20(%rsp), %rsi
movq %rsi, -0x10(%rsi)
andq $0x0, -0x8(%rsi)
movb %dl, (%rcx)
movb %dl, (%rsi)
leaq 0x30(%rsp), %r13
leaq 0x50(%rsp), %r14
movq -0x18(%rax), %rax
cmpl $0x0, 0x90(%rsp,%rax)
jne 0x9204
movq 0x38(%rbx), %rbp
movq 0x40(%rbx), %r12
callq 0x4a00
subq %rbp, %r12
shrq $0x5, %r12
cmpl %r12d, 0xe8(%rax)
jle 0x9204
leaq 0x70(%rsp), %rdi
movq %r13, %rsi
callq 0x4060
movq 0x30(%rsp), %rax
cmpb $0x3e, (%rax)
jne 0x91d4
movq 0x28(%rbx), %rax
cmpq 0x20(%rbx), %rax
je 0x9173
movq %r15, %rdi
leaq 0x10(%rsp), %rsi
callq 0xa0d8
movq 0x38(%rbx), %rbp
movq 0x40(%rbx), %r12
callq 0x4a00
subq %rbp, %r12
shrq $0x5, %r12
cmpl %r12d, 0xe8(%rax)
jle 0x91c4
movq %r13, %rdi
pushq $0x20
popq %rsi
xorl %edx, %edx
callq 0x4340
leaq -0x1(%rax), %rcx
movq %r14, %rdi
movq %r13, %rsi
pushq $0x1
popq %rdx
callq 0x4280
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x857a
movq %r14, %rdi
callq 0x4110
andq $0x0, 0x18(%rsp)
movq 0x10(%rsp), %rax
movb $0x0, (%rax)
jmp 0x91fa
movq %r14, %rdi
leaq 0x10(%rsp), %r12
movq %r12, %rsi
movq %r13, %rdx
callq 0xa104
movq %r12, %rdi
movq %r14, %rsi
callq 0x42f0
movq %r14, %rdi
callq 0x4110
movq 0x70(%rsp), %rax
jmp 0x9112
movq 0x38(%rbx), %r12
movq 0x40(%rbx), %r14
callq 0x4a00
subq %r12, %r14
shrq $0x5, %r14
cmpl %r14d, 0xe8(%rax)
jle 0x922e
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0xa0d8
movq 0x28(%rbx), %rax
movq 0x38(%rbx), %rcx
subq 0x20(%rbx), %rax
shrq $0x5, %rax
movl %eax, 0xc8(%rbx)
movl 0x8(%rcx), %eax
movl %eax, 0xcc(%rbx)
movq 0x9d6c(%rip), %rdi      # 0x12fc0
leaq 0x43e1(%rip), %rsi      # 0xd63c
callq 0x4250
movl 0xc8(%rbx), %esi
movq %rax, %rdi
callq 0x4420
leaq 0x43e7(%rip), %rsi      # 0xd65c
movq %rax, %rdi
callq 0x4250
movl 0xcc(%rbx), %esi
movq %rax, %rdi
callq 0x4420
leaq 0x4264(%rip), %rsi      # 0xd4f6
movq %rax, %rdi
callq 0x4250
xorl %r14d, %r14d
movslq 0xc8(%rbx), %rax
cmpq %rax, %r14
jge 0x92e0
movq %r14, %r12
shlq $0x5, %r12
xorl %r13d, %r13d
movslq 0xcc(%rbx), %rax
cmpq %rax, %r13
jge 0x92db
movq (%r15), %rax
movq (%rax,%r12), %rbp
movsbl (%rbp,%r13), %edi
callq 0x4480
movb %al, (%rbp,%r13)
incq %r13
jmp 0x92b3
incq %r14
jmp 0x929d
movq %rbx, %rdi
callq 0x96c8
movq %rbx, %rdi
callq 0x974c
movq %rbx, %rdi
callq 0x97cc
movq %rbx, %rdi
callq 0x9922
movq %rbx, %rdi
callq 0x9a22
callq 0x4a00
cmpb $0x1, 0xec(%rax)
jne 0x95ac
movq 0x9c9f(%rip), %rdi      # 0x12fc0
leaq 0x4340(%rip), %rsi      # 0xd668
callq 0x4250
xorl %r13d, %r13d
movq 0x9c89(%rip), %r14      # 0x12fc0
leaq 0x4384(%rip), %r12      # 0xd6c2
movslq 0x8(%rbx), %rax
cmpq %rax, %r13
jge 0x9367
movq (%rbx), %rax
movsbl (%rax,%r13), %esi
movq %r14, %rdi
callq 0x42b0
movq %rax, %rdi
movq %r12, %rsi
callq 0x4250
incq %r13
jmp 0x933e
movq 0x9c52(%rip), %rdi      # 0x12fc0
leaq 0x4181(%rip), %rsi      # 0xd4f6
callq 0x4250
movq 0x9c3f(%rip), %rdi      # 0x12fc0
leaq 0x42ed(%rip), %rsi      # 0xd675
callq 0x4250
xorl %r13d, %r13d
movq 0x9c29(%rip), %r14      # 0x12fc0
leaq 0x4158(%rip), %r12      # 0xd4f6
xorl %ebp, %ebp
movslq 0xc8(%rbx), %rax
cmpq %rax, %rbp
jge 0x93ce
movq (%r15), %rsi
addq %r13, %rsi
movq %r14, %rdi
callq 0x4240
movq %rax, %rdi
movq %r12, %rsi
callq 0x4250
incq %rbp
addq $0x20, %r13
jmp 0x93a0
movq 0x9beb(%rip), %rdi      # 0x12fc0
leaq 0x42b0(%rip), %rsi      # 0xd68c
callq 0x4250
xorl %r13d, %r13d
movq 0x9bd5(%rip), %r14      # 0x12fc0
leaq 0x42d0(%rip), %r12      # 0xd6c2
movq 0x80(%rbx), %rax
movq 0x88(%rbx), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r13
jge 0x942d
movss (%rax,%r13,4), %xmm0
movq %r14, %rdi
callq 0x41e0
movq %rax, %rdi
movq %r12, %rsi
callq 0x4250
incq %r13
jmp 0x93f2
movq 0x9b8c(%rip), %rdi      # 0x12fc0
leaq 0x40bb(%rip), %rsi      # 0xd4f6
callq 0x4250
movq 0x9b79(%rip), %rdi      # 0x12fc0
leaq 0x4251(%rip), %rsi      # 0xd69f
callq 0x4250
xorl %r14d, %r14d
movq 0x9b63(%rip), %r12      # 0x12fc0
leaq 0x425e(%rip), %r13      # 0xd6c2
movq 0x68(%rbx), %rax
movq 0x70(%rbx), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r14
jge 0x9497
movl (%rax,%r14,4), %esi
movq %r12, %rdi
callq 0x4420
movq %rax, %rdi
movq %r13, %rsi
callq 0x4250
incq %r14
jmp 0x9464
movq 0x9b22(%rip), %rdi      # 0x12fc0
leaq 0x4051(%rip), %rsi      # 0xd4f6
callq 0x4250
movq 0x9b0f(%rip), %r12      # 0x12fc0
leaq 0x41f6(%rip), %rsi      # 0xd6ae
movq %r12, %rdi
callq 0x4250
xorl %r13d, %r13d
pushq $0xa
popq %rbp
leaq 0x41f0(%rip), %r14      # 0xd6bd
movq 0x98(%rbx), %rdi
movq 0xa0(%rbx), %rax
subq %rdi, %rax
shrq $0x2, %rax
cltq
cmpq %rax, %r13
jge 0x9529
movq 0x68(%rbx), %rax
movl (%rax,%r13,4), %r8d
movl 0xc8(%rbx), %eax
cltd
idivl %ebp
movl %eax, %ecx
movq %r12, %rax
movq %r14, %rsi
cmpl %ecx, %r8d
jge 0x951c
movss (%rdi,%r13,4), %xmm0
movq %r12, %rdi
callq 0x41e0
leaq 0x41a6(%rip), %rsi      # 0xd6c2
movq %rax, %rdi
callq 0x4250
incq %r13
jmp 0x94cd
movq 0x9a90(%rip), %rdi      # 0x12fc0
leaq 0x3fbf(%rip), %rsi      # 0xd4f6
callq 0x4250
movq 0x9a7d(%rip), %rdi      # 0x12fc0
leaq 0x417a(%rip), %rsi      # 0xd6c4
callq 0x4250
xorl %r13d, %r13d
movq 0x9a67(%rip), %r14      # 0x12fc0
leaq 0x4162(%rip), %r12      # 0xd6c2
movq 0xb0(%rbx), %rax
movq 0xb8(%rbx), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r13
jge 0x9599
movl (%rax,%r13,4), %esi
movq %r14, %rdi
callq 0x4420
movq %rax, %rdi
movq %r12, %rsi
callq 0x4250
incq %r13
jmp 0x9560
movq 0x9a20(%rip), %rdi      # 0x12fc0
leaq 0x3f4f(%rip), %rsi      # 0xd4f6
callq 0x4250
leaq 0x10(%rsp), %rdi
callq 0x4110
leaq 0x30(%rsp), %rdi
callq 0x4110
leaq 0x70(%rsp), %rdi
callq 0x4090
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x9a05(%rip), %rdi      # 0x12fe8
leaq 0x3a36(%rip), %rsi      # 0xd020
callq 0x4250
movq %rax, %rdi
movq %r14, %rsi
callq 0x4240
leaq 0x3ef5(%rip), %rsi      # 0xd4f6
movq %rax, %rdi
callq 0x4250
xorl %edi, %edi
callq 0x42d0
movq %rax, (%rsp)
jmp 0x9658
jmp 0x9618
movq %rax, (%rsp)
jmp 0x9662
movq %rax, (%rsp)
leaq 0x50(%rsp), %rdi
callq 0x4110
jmp 0x9644
jmp 0x9640
jmp 0x9640
jmp 0x9640
jmp 0x9640
jmp 0x9640
jmp 0x9640
jmp 0x9640
jmp 0x9640
jmp 0x9640
movq %rax, (%rsp)
leaq 0x10(%rsp), %rdi
callq 0x4110
leaq 0x30(%rsp), %rdi
callq 0x4110
leaq 0x70(%rsp), %rdi
callq 0x4090
leaq 0x68(%rbx), %r12
leaq 0x80(%rbx), %r13
leaq 0x98(%rbx), %rbp
leaq 0xb0(%rbx), %rdi
leaq 0x50(%rbx), %r14
callq 0x5bbe
movq %rbp, %rdi
callq 0x49cc
movq %r13, %rdi
callq 0x49cc
movq %r12, %rdi
callq 0x5bbe
movq %r14, %rdi
callq 0x4b40
movq %r15, %rdi
callq 0x4b40
movq 0x8(%rsp), %rdi
callq 0x4b40
movq %rbx, %rdi
callq 0x4110
movq (%rsp), %rdi
callq 0x4430
nop