# Path: preimage/datasets/loader.py
# def load_amino_acids_and_descriptors(file_name=AminoAcidFile.blosum62_natural):
#     """Load amino acids and descriptors
# 
#     Parameters
#     ----------
#     file_name : string
#         file name of the amino acid matrix.
# 
#     Returns
#     -------
#     amino_acids: list
#         A list of amino acids (letters).
#     descriptors: array, shape = [n_amino_acids, n_amino_acids]
#         Substitution cost of each amino acid with all the other amino acids, where n_amino_acids is the number of
#         amino acids.
#     """
#     path_to_file = join(dirname(__file__), 'amino_acid_matrix', file_name)
#     with open(path_to_file, 'r') as data_file:
#         lines = data_file.readlines()
#     splitted_lines = numpy.array([line.split() for line in lines])
#     amino_acids = [str(letter) for letter in splitted_lines[:, 0]]
#     descriptors = numpy.array(splitted_lines[:, 1:], dtype=numpy.float)
#     return amino_acids, descriptors
# 
# Path: preimage/datasets/amino_acid_file.py
# class AminoAcidFile:
#     """Contain file name of amino acid property matrix from the literature.
# 
#     For more amino acid files see: http://graal.ift.ulaval.ca/bioinformatics/gs-kernel/.
# 
#     Attributes
#     ----------
#     blosum62_natural : string
#         file name of an amino acid matrix.
#     """
#     blosum62_natural = 'AA.blosum62.natural.dat'
# 
# Path: preimage/utils/position.py
# def compute_position_weights_matrix(max_position, sigma_position):
#     position_penalties = numpy.array([(i - j) for i in range(max_position) for j in range(max_position)],
#                                      dtype=numpy.float)
#     position_penalties = position_penalties.reshape(max_position, max_position)
#     position_penalties = numpy.square(position_penalties) / (-2 * (sigma_position ** 2))
#     return numpy.exp(position_penalties)
# 
# Path: preimage/utils/alphabet.py
# def transform_strings_to_integer_lists(Y, alphabet):
#     letter_to_int = get_n_gram_to_index(alphabet, 1)
#     n_examples = numpy.array(Y).shape[0]
#     max_length = numpy.max([len(y) for y in Y])
#     Y_int = numpy.zeros((n_examples, max_length), dtype=numpy.int8) - 1
#     for y_index, y in enumerate(Y):
#         for letter_index, letter in enumerate(y):
#             Y_int[y_index, letter_index] = letter_to_int[letter]
#     return Y_int


import numpy
from preimage.datasets.loader import load_amino_acids_and_descriptors
from preimage.kernels._generic_string import element_wise_generic_string_kernel, generic_string_kernel_with_sigma_c
from preimage.kernels._generic_string import element_wise_generic_string_kernel_with_sigma_c
from preimage.datasets.amino_acid_file import AminoAcidFile
from preimage.utils.position import compute_position_weights_matrix
from preimage.utils.alphabet import transform_strings_to_integer_lists
        self.amino_acid_file_name = amino_acid_file_name
        self.sigma_position = sigma_position
        self.sigma_amino_acid = sigma_amino_acid
        self.n = n
        self.is_normalized = is_normalized
        self.alphabet, self.descriptors = self._load_amino_acids_and_normalized_descriptors()

    def __call__(self, X1, X2):
        """Compute the similarity of all the strings of X1 with all the strings of X2 in the Generic String Kernel.

        Parameters
        ----------
        X1 : array, shape=[n_samples, ]
            Strings, where n_samples is the number of samples in X1.
        X2 : array, shape=[n_samples, ]
            Strings, where n_samples is the number of samples in X2.

        Returns
        -------
        gram_matrix : array, shape = [n_samples_x1, n_samples_x2]
            Similarity of each string of X1 with each string of X2, n_samples_x1 is the number of samples in X1 and
            n_samples_x2 is the number of samples in X2.
        """
        X1 = numpy.array(X1)
        X2 = numpy.array(X2)
        amino_acid_similarity_matrix = self.get_alphabet_similarity_matrix()
        is_symmetric = bool(X1.shape == X2.shape and numpy.all(X1 == X2))
        max_length, x1_lengths, x2_lengths = self._get_lengths(X1, X2)
        position_matrix = self.get_position_matrix(max_length)
        X1_int = transform_strings_to_integer_lists(X1, self.alphabet)

# Path: preimage/datasets/loader.py
# def load_amino_acids_and_descriptors(file_name=AminoAcidFile.blosum62_natural):
#     """Load amino acids and descriptors
# 
#     Parameters
#     ----------
#     file_name : string
#         file name of the amino acid matrix.
# 
#     Returns
#     -------
#     amino_acids: list
#         A list of amino acids (letters).
#     descriptors: array, shape = [n_amino_acids, n_amino_acids]
#         Substitution cost of each amino acid with all the other amino acids, where n_amino_acids is the number of
#         amino acids.
#     """
#     path_to_file = join(dirname(__file__), 'amino_acid_matrix', file_name)
#     with open(path_to_file, 'r') as data_file:
#         lines = data_file.readlines()
#     splitted_lines = numpy.array([line.split() for line in lines])
#     amino_acids = [str(letter) for letter in splitted_lines[:, 0]]
#     descriptors = numpy.array(splitted_lines[:, 1:], dtype=numpy.float)
#     return amino_acids, descriptors
# 
# Path: preimage/datasets/amino_acid_file.py
# class AminoAcidFile:
#     """Contain file name of amino acid property matrix from the literature.
# 
#     For more amino acid files see: http://graal.ift.ulaval.ca/bioinformatics/gs-kernel/.
# 
#     Attributes
#     ----------
#     blosum62_natural : string
#         file name of an amino acid matrix.
#     """
#     blosum62_natural = 'AA.blosum62.natural.dat'
# 
# Path: preimage/utils/position.py
# def compute_position_weights_matrix(max_position, sigma_position):
#     position_penalties = numpy.array([(i - j) for i in range(max_position) for j in range(max_position)],
#                                      dtype=numpy.float)
#     position_penalties = position_penalties.reshape(max_position, max_position)
#     position_penalties = numpy.square(position_penalties) / (-2 * (sigma_position ** 2))
#     return numpy.exp(position_penalties)
# 
# Path: preimage/utils/alphabet.py
# def transform_strings_to_integer_lists(Y, alphabet):
#     letter_to_int = get_n_gram_to_index(alphabet, 1)
#     n_examples = numpy.array(Y).shape[0]
#     max_length = numpy.max([len(y) for y in Y])
#     Y_int = numpy.zeros((n_examples, max_length), dtype=numpy.int8) - 1
#     for y_index, y in enumerate(Y):
#         for letter_index, letter in enumerate(y):
#             Y_int[y_index, letter_index] = letter_to_int[letter]
#     return Y_int


# Path: preimage/kernels/generic_string.py
import numpy
from preimage.datasets.loader import load_amino_acids_and_descriptors
from preimage.kernels._generic_string import element_wise_generic_string_kernel, generic_string_kernel_with_sigma_c
from preimage.kernels._generic_string import element_wise_generic_string_kernel_with_sigma_c
from preimage.datasets.amino_acid_file import AminoAcidFile
from preimage.utils.position import compute_position_weights_matrix
from preimage.utils.alphabet import transform_strings_to_integer_lists

        self.amino_acid_file_name = amino_acid_file_name
        self.sigma_position = sigma_position
        self.sigma_amino_acid = sigma_amino_acid
        self.n = n
        self.is_normalized = is_normalized
        self.alphabet, self.descriptors = self._load_amino_acids_and_normalized_descriptors()

    def __call__(self, X1, X2):
        """Compute the similarity of all the strings of X1 with all the strings of X2 in the Generic String Kernel.

        Parameters
        ----------
        X1 : array, shape=[n_samples, ]
            Strings, where n_samples is the number of samples in X1.
        X2 : array, shape=[n_samples, ]
            Strings, where n_samples is the number of samples in X2.

        Returns
        -------
        gram_matrix : array, shape = [n_samples_x1, n_samples_x2]
            Similarity of each string of X1 with each string of X2, n_samples_x1 is the number of samples in X1 and
            n_samples_x2 is the number of samples in X2.
        """
        X1 = numpy.array(X1)
        X2 = numpy.array(X2)
        amino_acid_similarity_matrix = self.get_alphabet_similarity_matrix()
        is_symmetric = bool(X1.shape == X2.shape and numpy.all(X1 == X2))
        max_length, x1_lengths, x2_lengths = self._get_lengths(X1, X2)
        position_matrix = self.get_position_matrix(max_length)
        X1_int = transform_strings_to_integer_lists(X1, self.alphabet)

        X2_int = transform_strings_to_integer_lists(X2, self.alphabet)