# Path: constants.py
# ALPHABET = ['A', 'C', 'G', 'T']
# 
# EXTENDED_ALPHABET = ['A', 'C', 'G', 'T', 'N', 'M', 'K']
# 
# TFFM_KIND = enum(FIRST_ORDER="1st-order", DETAILED="detailed",
#                  ZERO_ORDER="0-order")
# 
# LOGO_TYPE = enum(SUMMARY="summary", DENSE="dense")


import sys
import os
import math
import re
import ghmm
import drawing
import exceptions_errors
import utils
import hit_module
from Bio.Alphabet import IUPAC
from Bio import SeqIO
from Bio import motifs
from constants import ALPHABET, EXTENDED_ALPHABET, TFFM_KIND, LOGO_TYPE

        :returns: The emission probabilities of ACGT by the state indexed by
            *index* at position *position* in the TFFM.
        :rtype: list

        """

        emissions_dic = {'A': 0., 'C': 0., 'G': 0., 'T': 0.}
        if self.kind == TFFM_KIND.FIRST_ORDER:
            for j in xrange(4):
                letter = ALPHABET[j]
                emissions_dic[letter] = self.getEmission(position)[index * 4 + j]
                proba = self.getEmission(position)[j * 4 + index]
                proba *= previous_position_proba[letter]
                position_proba[ALPHABET[index]] += proba
            emissions = zip(emissions_dic.values(), emissions_dic.keys())
        elif self.kind == TFFM_KIND.DETAILED:
            for j in xrange(4):
                start_state = (position - 1) * 4 + index
                end_state = position * 4 + j
                emissions_dic[ALPHABET[j]] = self.getTransition(start_state,
                                                                end_state)
                proba = previous_position_proba[ALPHABET[index]]
                proba *= self.getTransition(start_state, end_state)
                position_proba[ALPHABET[j]] += proba
            somme = sum(emissions_dic.values())
            emissions = zip(emissions_dic.values(), emissions_dic.keys())
            emissions = map(lambda (x, y): (x / somme, y), emissions)
        else:  # 0-order HMM here
            for j in xrange(4):

# Path: constants.py
# ALPHABET = ['A', 'C', 'G', 'T']
# 
# EXTENDED_ALPHABET = ['A', 'C', 'G', 'T', 'N', 'M', 'K']
# 
# TFFM_KIND = enum(FIRST_ORDER="1st-order", DETAILED="detailed",
#                  ZERO_ORDER="0-order")
# 
# LOGO_TYPE = enum(SUMMARY="summary", DENSE="dense")


# Path: tffm_module.py
import sys
import os
import math
import re
import ghmm
import drawing
import exceptions_errors
import utils
import hit_module
from Bio.Alphabet import IUPAC
from Bio import SeqIO
from Bio import motifs
from constants import ALPHABET, EXTENDED_ALPHABET, TFFM_KIND, LOGO_TYPE


        :returns: The emission probabilities of ACGT by the state indexed by
            *index* at position *position* in the TFFM.
        :rtype: list

        """

        emissions_dic = {'A': 0., 'C': 0., 'G': 0., 'T': 0.}
        if self.kind == TFFM_KIND.FIRST_ORDER:
            for j in xrange(4):
                letter = ALPHABET[j]
                emissions_dic[letter] = self.getEmission(position)[index * 4 + j]
                proba = self.getEmission(position)[j * 4 + index]
                proba *= previous_position_proba[letter]
                position_proba[ALPHABET[index]] += proba
            emissions = zip(emissions_dic.values(), emissions_dic.keys())
        elif self.kind == TFFM_KIND.DETAILED:
            for j in xrange(4):
                start_state = (position - 1) * 4 + index
                end_state = position * 4 + j
                emissions_dic[ALPHABET[j]] = self.getTransition(start_state,
                                                                end_state)
                proba = previous_position_proba[ALPHABET[index]]
                proba *= self.getTransition(start_state, end_state)
                position_proba[ALPHABET[j]] += proba
            somme = sum(emissions_dic.values())
            emissions = zip(emissions_dic.values(), emissions_dic.keys())
            emissions = map(lambda (x, y): (x / somme, y), emissions)
        else:  # 0-order HMM here
            for j in xrange(4):

                letter = ALPHABET[j]