# Path: alfpy/word_pattern.py
# class Pattern:
#     def __init__(self, pat_list, occr_list, pos_list=None):
#     def _alfree_format(self):
#     def _teiresias_format(self):
#     def format(self, formattype=None):
#     def reduce_alphabet(self, alphabet_dict):
#     def merge_revcomp(self):
#         def revcomp(s):
#     def __repr__(self):
#     def __str__(self):
# def _create_wordpattern(seq_list, k):
# def _create_wordpattern_positions(seq_list, k):
# def create(seq_list, word_size=1, wordpos=False):
# def create_from_fasta(handle, word_size=1, wordpos=False):
# def create_from_bigfasta(filename, k=1):
# def run_teiresias(input_filename, w=2, l=2, k=2, output_filename=None):
# def read(handle):
# def main():
# 
# Path: alfpy/word_sets_distance.py
# def _getwords(seq, word_size):
#     def __init__(self, seq_records, word_size, disttype='jaccard'):
#     def pwdist_jaccard(self, seq1idx, seq2idx):
#     def pwdist_dice(self, seq1idx, seq2idx):
#     def pwdist_hamming(self, seq1idx, seq2idx):
# def main():
# class Distance(distance.Distance):
# 
# Path: alfpy/utils/distmatrix.py
# def create(id_list, distance):
# def read_highcharts_matrix(id_list, data):
#     def __init__(self, id_list, data):
#     def normalize(self):
#     def __iter__(self):
#     def writer(self, handle, f, decimal_places):
#     def display(self, f="phylip", decimal_places=7):
#     def write_to_file(self, handle, f="phylip", decimal_places=7):
#     def highcharts(self):
#     def format(self, decimal_places=7):
#     def min(self):
#     def max(self):
#     def is_zero(self):
#     def __repr__(self):
# class Matrix():


import numpy as np
import unittest
from alfpy import word_pattern
from alfpy import word_sets_distance
from alfpy.utils import distmatrix
from . import utils



class Test(unittest.TestCase, utils.ModulesCommonTest):

    def __init__(self, *args, **kwargs):
        super(Test, self).__init__(*args, **kwargs)
        utils.ModulesCommonTest.set_test_data()
        self.p = word_pattern.create(self.pep_records.seq_list, 2)

    def test_getwords(self):
        words = word_sets_distance._getwords('ATGCGTA', 2)
        self.assertSetEqual(words, set(['GT', 'CG', 'GC', 'AT', 'TG', 'TA']))

    def test_distance_dice(self):
        # The result of this function is identical
        # to the Dice distance implemented in word_bool_distance.
        dist = word_sets_distance.Distance(self.pep_records, 2, 'dice')
        matrix = distmatrix.create(self.pep_records.id_list, dist)
        exp = [
            "   4",
            "seq1       0.0000000 0.1964286 0.3928571 0.4457831",
            "seq2       0.1964286 0.0000000 0.2452830 0.4025974",
            "seq3       0.3928571 0.2452830 0.0000000 0.3766234",
            "seq4       0.4457831 0.4025974 0.3766234 0.0000000"
        ]
        self.assertEqual(matrix.format(), "\n".join(exp))

    def test_distance_hamming(self):
        dist = word_sets_distance.Distance(self.pep_records, 2, 'hamming')

# Path: alfpy/word_pattern.py
# class Pattern:
#     def __init__(self, pat_list, occr_list, pos_list=None):
#     def _alfree_format(self):
#     def _teiresias_format(self):
#     def format(self, formattype=None):
#     def reduce_alphabet(self, alphabet_dict):
#     def merge_revcomp(self):
#         def revcomp(s):
#     def __repr__(self):
#     def __str__(self):
# def _create_wordpattern(seq_list, k):
# def _create_wordpattern_positions(seq_list, k):
# def create(seq_list, word_size=1, wordpos=False):
# def create_from_fasta(handle, word_size=1, wordpos=False):
# def create_from_bigfasta(filename, k=1):
# def run_teiresias(input_filename, w=2, l=2, k=2, output_filename=None):
# def read(handle):
# def main():
# 
# Path: alfpy/word_sets_distance.py
# def _getwords(seq, word_size):
#     def __init__(self, seq_records, word_size, disttype='jaccard'):
#     def pwdist_jaccard(self, seq1idx, seq2idx):
#     def pwdist_dice(self, seq1idx, seq2idx):
#     def pwdist_hamming(self, seq1idx, seq2idx):
# def main():
# class Distance(distance.Distance):
# 
# Path: alfpy/utils/distmatrix.py
# def create(id_list, distance):
# def read_highcharts_matrix(id_list, data):
#     def __init__(self, id_list, data):
#     def normalize(self):
#     def __iter__(self):
#     def writer(self, handle, f, decimal_places):
#     def display(self, f="phylip", decimal_places=7):
#     def write_to_file(self, handle, f="phylip", decimal_places=7):
#     def highcharts(self):
#     def format(self, decimal_places=7):
#     def min(self):
#     def max(self):
#     def is_zero(self):
#     def __repr__(self):
# class Matrix():


# Path: tests/test_word_sets_distance.py
import numpy as np
import unittest
from alfpy import word_pattern
from alfpy import word_sets_distance
from alfpy.utils import distmatrix
from . import utils




class Test(unittest.TestCase, utils.ModulesCommonTest):

    def __init__(self, *args, **kwargs):
        super(Test, self).__init__(*args, **kwargs)
        utils.ModulesCommonTest.set_test_data()
        self.p = word_pattern.create(self.pep_records.seq_list, 2)

    def test_getwords(self):
        words = word_sets_distance._getwords('ATGCGTA', 2)
        self.assertSetEqual(words, set(['GT', 'CG', 'GC', 'AT', 'TG', 'TA']))

    def test_distance_dice(self):
        # The result of this function is identical
        # to the Dice distance implemented in word_bool_distance.
        dist = word_sets_distance.Distance(self.pep_records, 2, 'dice')
        matrix = distmatrix.create(self.pep_records.id_list, dist)
        exp = [
            "   4",
            "seq1       0.0000000 0.1964286 0.3928571 0.4457831",
            "seq2       0.1964286 0.0000000 0.2452830 0.4025974",
            "seq3       0.3928571 0.2452830 0.0000000 0.3766234",
            "seq4       0.4457831 0.4025974 0.3766234 0.0000000"
        ]
        self.assertEqual(matrix.format(), "\n".join(exp))

    def test_distance_hamming(self):
        dist = word_sets_distance.Distance(self.pep_records, 2, 'hamming')

        matrix = distmatrix.create(self.pep_records.id_list, dist)