// File: 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
movq %rsp, %rbp
subq $0x440, %rsp            # imm = 0x440
movq %rsi, -0x320(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x2e0(%rbp)
movq %rdi, %rax
movq %rax, -0x318(%rbp)
callq 0x44b0
movq -0x2e0(%rbp), %rdi
addq $0x20, %rdi
movq %rdi, -0x310(%rbp)
callq 0x5330
movq -0x2e0(%rbp), %rdi
addq $0x38, %rdi
movq %rdi, -0x308(%rbp)
callq 0x5330
movq -0x2e0(%rbp), %rdi
addq $0x50, %rdi
movq %rdi, -0x300(%rbp)
callq 0x5330
movq -0x2e0(%rbp), %rdi
addq $0x68, %rdi
movq %rdi, -0x2f8(%rbp)
callq 0x9020
movq -0x2e0(%rbp), %rdi
subq $-0x80, %rdi
movq %rdi, -0x2f0(%rbp)
callq 0x7210
movq -0x2e0(%rbp), %rdi
addq $0x98, %rdi
movq %rdi, -0x2e8(%rbp)
callq 0x7210
movq -0x2e0(%rbp), %rdi
addq $0xb0, %rdi
movq %rdi, -0x2d8(%rbp)
callq 0x9020
callq 0x5150
movq %rax, -0x2d0(%rbp)
jmp 0x11609
movq -0x2d0(%rbp), %rax
testb $0x1, 0xec(%rax)
je 0x11679
movq 0x149a0(%rip), %rdi     # 0x25fc0
leaq 0x9ff9(%rip), %rsi      # 0x1b620
callq 0x4330
movq %rax, -0x328(%rbp)
jmp 0x11635
movq -0x320(%rbp), %rsi
movq -0x328(%rbp), %rdi
callq 0x4320
movq %rax, -0x330(%rbp)
jmp 0x11651
movq -0x330(%rbp), %rdi
leaq 0x9e97(%rip), %rsi      # 0x1b4f6
callq 0x4330
jmp 0x11666
jmp 0x11679
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x120ca
movq -0x320(%rbp), %rdi
callq 0x4130
movq %rax, %rsi
leaq -0x228(%rbp), %rdi
movl $0x8, %edx
callq 0x4630
jmp 0x1169b
movq -0x228(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x228(%rbp,%rax), %rdi
callq 0x4590
movb %al, -0x331(%rbp)
jmp 0x116bb
movb -0x331(%rbp), %al
testb $0x1, %al
jne 0x1172c
jmp 0x116c7
movq 0x1491a(%rip), %rdi     # 0x25fe8
leaq 0x994b(%rip), %rsi      # 0x1b020
callq 0x4330
movq %rax, -0x340(%rbp)
jmp 0x116e3
movq -0x320(%rbp), %rsi
movq -0x340(%rbp), %rdi
callq 0x4320
movq %rax, -0x348(%rbp)
jmp 0x116ff
movq -0x348(%rbp), %rdi
leaq 0x9de9(%rip), %rsi      # 0x1b4f6
callq 0x4330
jmp 0x11714
xorl %edi, %edi
callq 0x4400
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x120be
leaq -0x248(%rbp), %rdi
callq 0x44b0
leaq -0x268(%rbp), %rdi
callq 0x44b0
movq -0x228(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x228(%rbp,%rax), %rdi
callq 0x4590
movb %al, -0x349(%rbp)
jmp 0x11764
movb -0x349(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x34a(%rbp)
jne 0x11779
jmp 0x117b9
movq -0x318(%rbp), %rdi
addq $0x38, %rdi
callq 0xe1f0
movl %eax, -0x35c(%rbp)
callq 0x5150
movq %rax, -0x358(%rbp)
jmp 0x1179d
movl -0x35c(%rbp), %eax
movq -0x358(%rbp), %rcx
cmpl 0xe8(%rcx), %eax
setl %al
movb %al, -0x34a(%rbp)
movb -0x34a(%rbp), %al
testb $0x1, %al
jne 0x117c8
jmp 0x11964
leaq -0x228(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x4080
jmp 0x117dd
xorl %eax, %eax
movl %eax, %esi
leaq -0x248(%rbp), %rdi
callq 0x46c0
movq %rax, -0x368(%rbp)
jmp 0x117f6
movq -0x368(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3e, %eax
jne 0x11924
movq -0x318(%rbp), %rdi
addq $0x20, %rdi
callq 0xe1f0
cmpq $0x0, %rax
je 0x1184b
movq -0x318(%rbp), %rdi
addq $0x38, %rdi
leaq -0x268(%rbp), %rsi
callq 0x13650
jmp 0x11838
jmp 0x1184b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x120a6
movq -0x318(%rbp), %rdi
addq $0x38, %rdi
callq 0xe1f0
movl %eax, -0x374(%rbp)
callq 0x5150
movq %rax, -0x370(%rbp)
jmp 0x1186f
movl -0x374(%rbp), %eax
movq -0x370(%rbp), %rcx
cmpl 0xe8(%rcx), %eax
jge 0x11916
movq -0x318(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x388(%rbp)
xorl %eax, %eax
movl %eax, %edx
leaq -0x248(%rbp), %rdi
movq %rdi, -0x380(%rbp)
movl $0x20, %esi
callq 0x41f0
movq -0x380(%rbp), %rsi
movq %rax, %rcx
decq %rcx
leaq -0x288(%rbp), %rdi
movl $0x1, %edx
callq 0x4360
jmp 0x118d6
movq -0x388(%rbp), %rdi
leaq -0x288(%rbp), %rsi
callq 0xcb10
jmp 0x118eb
leaq -0x288(%rbp), %rdi
callq 0x41e0
jmp 0x11916
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x288(%rbp), %rdi
callq 0x41e0
jmp 0x120a6
leaq -0x268(%rbp), %rdi
callq 0x4490
jmp 0x1195f
leaq -0x2a8(%rbp), %rdi
leaq -0x268(%rbp), %rsi
leaq -0x248(%rbp), %rdx
callq 0x136c0
jmp 0x11940
leaq -0x268(%rbp), %rdi
leaq -0x2a8(%rbp), %rsi
callq 0x4420
leaq -0x2a8(%rbp), %rdi
callq 0x41e0
jmp 0x11744
movq -0x318(%rbp), %rdi
addq $0x38, %rdi
callq 0xe1f0
movl %eax, -0x394(%rbp)
callq 0x5150
movq %rax, -0x390(%rbp)
jmp 0x11988
movl -0x394(%rbp), %eax
movq -0x390(%rbp), %rcx
cmpl 0xe8(%rcx), %eax
jge 0x119b8
movq -0x318(%rbp), %rdi
addq $0x38, %rdi
leaq -0x268(%rbp), %rsi
callq 0x13650
jmp 0x119b6
jmp 0x119b8
movq -0x318(%rbp), %rdi
addq $0x20, %rdi
callq 0xe1f0
movq -0x318(%rbp), %rdi
movl %eax, 0xc8(%rdi)
addq $0x38, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x74a0
movq %rax, %rdi
callq 0x4260
movq %rax, %rcx
movq -0x318(%rbp), %rax
movl %ecx, 0xcc(%rax)
movq 0x145bf(%rip), %rdi     # 0x25fc0
leaq 0x9c34(%rip), %rsi      # 0x1b63c
callq 0x4330
movq %rax, -0x3a0(%rbp)
jmp 0x11a16
movq -0x3a0(%rbp), %rdi
movq -0x318(%rbp), %rax
movl 0xc8(%rax), %esi
callq 0x45c0
movq %rax, -0x3a8(%rbp)
jmp 0x11a38
movq -0x3a8(%rbp), %rdi
leaq 0x9c16(%rip), %rsi      # 0x1b65c
callq 0x4330
movq %rax, -0x3b0(%rbp)
jmp 0x11a54
movq -0x3b0(%rbp), %rdi
movq -0x318(%rbp), %rax
movl 0xcc(%rax), %esi
callq 0x45c0
movq %rax, -0x3b8(%rbp)
jmp 0x11a76
movq -0x3b8(%rbp), %rdi
leaq 0x9a72(%rip), %rsi      # 0x1b4f6
callq 0x4330
jmp 0x11a8b
movl $0x0, -0x2ac(%rbp)
movq -0x318(%rbp), %rcx
movl -0x2ac(%rbp), %eax
cmpl 0xc8(%rcx), %eax
jge 0x11b7d
movl $0x0, -0x2b0(%rbp)
movq -0x318(%rbp), %rcx
movl -0x2b0(%rbp), %eax
cmpl 0xcc(%rcx), %eax
jge 0x11b67
movq -0x318(%rbp), %rdi
addq $0x38, %rdi
movslq -0x2ac(%rbp), %rsi
callq 0x74a0
movq %rax, %rdi
movslq -0x2b0(%rbp), %rsi
callq 0x46c0
movq %rax, -0x3c0(%rbp)
jmp 0x11b00
movq -0x3c0(%rbp), %rax
movsbl (%rax), %edi
callq 0x4640
movq -0x318(%rbp), %rdi
movb %al, -0x3c9(%rbp)
addq $0x38, %rdi
movslq -0x2ac(%rbp), %rsi
callq 0x74a0
movq %rax, %rdi
movslq -0x2b0(%rbp), %rsi
callq 0x46c0
movq %rax, -0x3c8(%rbp)
jmp 0x11b44
movq -0x3c8(%rbp), %rax
movb -0x3c9(%rbp), %cl
movb %cl, (%rax)
movl -0x2b0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2b0(%rbp)
jmp 0x11ab8
jmp 0x11b69
movl -0x2ac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2ac(%rbp)
jmp 0x11a95
movq -0x318(%rbp), %rdi
callq 0x12140
jmp 0x11b8b
movq -0x318(%rbp), %rdi
callq 0x12220
jmp 0x11b99
movq -0x318(%rbp), %rdi
callq 0x122f0
jmp 0x11ba7
movq -0x318(%rbp), %rdi
callq 0x12650
jmp 0x11bb5
movq -0x318(%rbp), %rdi
callq 0x127c0
jmp 0x11bc3
callq 0x5150
movq %rax, -0x3d8(%rbp)
jmp 0x11bd1
movq -0x3d8(%rbp), %rax
testb $0x1, 0xec(%rax)
je 0x12079
movq 0x143d4(%rip), %rdi     # 0x25fc0
leaq 0x9a75(%rip), %rsi      # 0x1b668
callq 0x4330
jmp 0x11bfa
movl $0x0, -0x2b4(%rbp)
movq -0x318(%rbp), %rdi
movl -0x2b4(%rbp), %eax
movl %eax, -0x3dc(%rbp)
callq 0x4260
movq %rax, %rcx
movl -0x3dc(%rbp), %eax
cmpl %ecx, %eax
jge 0x11c8f
movq -0x318(%rbp), %rdi
movslq -0x2b4(%rbp), %rsi
callq 0x46c0
movq %rax, -0x3e8(%rbp)
jmp 0x11c45
movq -0x3e8(%rbp), %rax
movsbl (%rax), %esi
movq 0x1436a(%rip), %rdi     # 0x25fc0
callq 0x43e0
movq %rax, -0x3f0(%rbp)
jmp 0x11c64
movq -0x3f0(%rbp), %rdi
leaq 0x9a50(%rip), %rsi      # 0x1b6c2
callq 0x4330
jmp 0x11c79
jmp 0x11c7b
movl -0x2b4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2b4(%rbp)
jmp 0x11c04
movq 0x1432a(%rip), %rdi     # 0x25fc0
leaq 0x9859(%rip), %rsi      # 0x1b4f6
callq 0x4330
jmp 0x11ca4
movq 0x14315(%rip), %rdi     # 0x25fc0
leaq 0x99c3(%rip), %rsi      # 0x1b675
callq 0x4330
jmp 0x11cb9
movl $0x0, -0x2b8(%rbp)
movq -0x318(%rbp), %rcx
movl -0x2b8(%rbp), %eax
cmpl 0xc8(%rcx), %eax
jge 0x11d2f
movq -0x318(%rbp), %rdi
addq $0x38, %rdi
movslq -0x2b8(%rbp), %rsi
callq 0x74a0
movq %rax, %rsi
movq 0x142c7(%rip), %rdi     # 0x25fc0
callq 0x4320
movq %rax, -0x3f8(%rbp)
jmp 0x11d07
movq -0x3f8(%rbp), %rdi
leaq 0x97e1(%rip), %rsi      # 0x1b4f6
callq 0x4330
jmp 0x11d1c
jmp 0x11d1e
movl -0x2b8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2b8(%rbp)
jmp 0x11cc3
movq 0x1428a(%rip), %rdi     # 0x25fc0
leaq 0x994f(%rip), %rsi      # 0x1b68c
callq 0x4330
jmp 0x11d44
movl $0x0, -0x2bc(%rbp)
movq -0x318(%rbp), %rdi
movl -0x2bc(%rbp), %eax
movl %eax, -0x3fc(%rbp)
addq $0x80, %rdi
callq 0x5160
movq %rax, %rcx
movl -0x3fc(%rbp), %eax
cmpl %ecx, %eax
jge 0x11dd5
movq -0x318(%rbp), %rdi
subq $-0x80, %rdi
movslq -0x2bc(%rbp), %rsi
callq 0x5180
movss (%rax), %xmm0
movq 0x14224(%rip), %rdi     # 0x25fc0
callq 0x4290
movq %rax, -0x408(%rbp)
jmp 0x11daa
movq -0x408(%rbp), %rdi
leaq 0x990a(%rip), %rsi      # 0x1b6c2
callq 0x4330
jmp 0x11dbf
jmp 0x11dc1
movl -0x2bc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2bc(%rbp)
jmp 0x11d4e
movq 0x141e4(%rip), %rdi     # 0x25fc0
leaq 0x9713(%rip), %rsi      # 0x1b4f6
callq 0x4330
jmp 0x11dea
movq 0x141cf(%rip), %rdi     # 0x25fc0
leaq 0x98a7(%rip), %rsi      # 0x1b69f
callq 0x4330
jmp 0x11dff
movl $0x0, -0x2c0(%rbp)
movq -0x318(%rbp), %rdi
movl -0x2c0(%rbp), %eax
movl %eax, -0x40c(%rbp)
addq $0x68, %rdi
callq 0x9150
movq %rax, %rcx
movl -0x40c(%rbp), %eax
cmpl %ecx, %eax
jge 0x11e88
movq -0x318(%rbp), %rdi
addq $0x68, %rdi
movslq -0x2c0(%rbp), %rsi
callq 0x7480
movl (%rax), %esi
movq 0x1416e(%rip), %rdi     # 0x25fc0
callq 0x45c0
movq %rax, -0x418(%rbp)
jmp 0x11e60
movq -0x418(%rbp), %rdi
leaq 0x9854(%rip), %rsi      # 0x1b6c2
callq 0x4330
jmp 0x11e75
jmp 0x11e77
movl -0x2c0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c0(%rbp)
jmp 0x11e09
movq 0x14131(%rip), %rdi     # 0x25fc0
leaq 0x9660(%rip), %rsi      # 0x1b4f6
callq 0x4330
jmp 0x11e9d
movq 0x1411c(%rip), %rdi     # 0x25fc0
leaq 0x9803(%rip), %rsi      # 0x1b6ae
callq 0x4330
jmp 0x11eb2
movl $0x0, -0x2c4(%rbp)
movq -0x318(%rbp), %rdi
movl -0x2c4(%rbp), %eax
movl %eax, -0x41c(%rbp)
addq $0x98, %rdi
callq 0x5160
movq %rax, %rcx
movl -0x41c(%rbp), %eax
cmpl %ecx, %eax
jge 0x11fa6
movq -0x318(%rbp), %rdi
addq $0x68, %rdi
movslq -0x2c4(%rbp), %rsi
callq 0x7480
movq %rax, %rcx
movq -0x318(%rbp), %rax
movl (%rcx), %ecx
movl %ecx, -0x420(%rbp)
movl 0xc8(%rax), %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x420(%rbp), %eax
cmpl %ecx, %eax
jge 0x11f79
movq -0x318(%rbp), %rdi
addq $0x98, %rdi
movslq -0x2c4(%rbp), %rsi
callq 0x5180
movss (%rax), %xmm0
movq 0x1406c(%rip), %rdi     # 0x25fc0
callq 0x4290
movq %rax, -0x428(%rbp)
jmp 0x11f62
movq -0x428(%rbp), %rdi
leaq 0x9752(%rip), %rsi      # 0x1b6c2
callq 0x4330
jmp 0x11f77
jmp 0x11f90
movq 0x14040(%rip), %rdi     # 0x25fc0
leaq 0x9736(%rip), %rsi      # 0x1b6bd
callq 0x4330
jmp 0x11f8e
jmp 0x11f90
jmp 0x11f92
movl -0x2c4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c4(%rbp)
jmp 0x11ebc
movq 0x14013(%rip), %rdi     # 0x25fc0
leaq 0x9542(%rip), %rsi      # 0x1b4f6
callq 0x4330
jmp 0x11fbb
movq 0x13ffe(%rip), %rdi     # 0x25fc0
leaq 0x96fb(%rip), %rsi      # 0x1b6c4
callq 0x4330
jmp 0x11fd0
movl $0x0, -0x2c8(%rbp)
movq -0x318(%rbp), %rdi
movl -0x2c8(%rbp), %eax
movl %eax, -0x42c(%rbp)
addq $0xb0, %rdi
callq 0x9150
movq %rax, %rcx
movl -0x42c(%rbp), %eax
cmpl %ecx, %eax
jge 0x12062
movq -0x318(%rbp), %rdi
addq $0xb0, %rdi
movslq -0x2c8(%rbp), %rsi
callq 0x7480
movl (%rax), %esi
movq 0x13f97(%rip), %rdi     # 0x25fc0
callq 0x45c0
movq %rax, -0x438(%rbp)
jmp 0x12037
movq -0x438(%rbp), %rdi
leaq 0x967d(%rip), %rsi      # 0x1b6c2
callq 0x4330
jmp 0x1204c
jmp 0x1204e
movl -0x2c8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c8(%rbp)
jmp 0x11fda
movq 0x13f57(%rip), %rdi     # 0x25fc0
leaq 0x9486(%rip), %rsi      # 0x1b4f6
callq 0x4330
jmp 0x12077
jmp 0x12079
leaq -0x268(%rbp), %rdi
callq 0x41e0
leaq -0x248(%rbp), %rdi
callq 0x41e0
leaq -0x228(%rbp), %rdi
callq 0x40b0
addq $0x440, %rsp            # imm = 0x440
popq %rbp
retq
leaq -0x268(%rbp), %rdi
callq 0x41e0
leaq -0x248(%rbp), %rdi
callq 0x41e0
leaq -0x228(%rbp), %rdi
callq 0x40b0
movq -0x2d8(%rbp), %rdi
callq 0x9170
movq -0x2e8(%rbp), %rdi
callq 0x4ea0
movq -0x2f0(%rbp), %rdi
callq 0x4ea0
movq -0x2f8(%rbp), %rdi
callq 0x9170
movq -0x300(%rbp), %rdi
callq 0x5540
movq -0x308(%rbp), %rdi
callq 0x5540
movq -0x310(%rbp), %rdi
callq 0x5540
movq -0x2e0(%rbp), %rdi
callq 0x41e0
movq -0x18(%rbp), %rdi
callq 0x45e0
nopw %cs:(%rax,%rax)