# Path: graftm/deduplicator.py
# class Deduplicator:
#     r"""Deduplicates sequences"""
#     
#     def deduplicate(self, aligned_sequence_objects):
#         r"""Sort the given aligned_sequence objects into an array of arrays,
#         where input sequences are grouped iff they have the same sequence
#         
#         Parameters
#         ----------
#         aligned_sequence_objects: array of Sequence objects
#             input sequences
#             
#         Returns
#         -------
#         Array of arrays of Sequence objects"""
#         
#         sequence_to_groups = {}
#         for s in aligned_sequence_objects:
#             try:
#                 sequence_to_groups[s.seq].append(s)
#             except KeyError:
#                 sequence_to_groups[s.seq] = [s]
#         return list(sequence_to_groups.values())
#     
#     def lca_taxonomy(self, deduplicated_sequences, taxonomy_hash):
#         r'''Given a set of deduplicated sequences and a taxonomy hash,
#         return the respective LCAs of taxonomy
#         
#         Parameters
#         ----------
#         deduplicated_sequences: Array of arrays of Sequence objects
#             as output from deduplicate()
#         taxonomy_hash: dictionary 
#             of sequence names to taxonomy array (i.e. array of str)
#         
#         Returns
#         -------
#         Array of taxonomy LCAs'''
#         
#         to_return = []
#         for dup_group in deduplicated_sequences:
#             lca = taxonomy_hash[dup_group[0].name]
#             for s in dup_group[1:]:
#                 for i, tax in enumerate(taxonomy_hash[s.name]):
#                     if i >= len(lca) or tax != lca[i]:
#                         lca = lca[:i]
#                         break
#                 if len(lca) > len(taxonomy_hash[s.name]):
#                     lca = lca[:len(taxonomy_hash[s.name])]
#             to_return.append(lca)
#         return to_return
# 
# Path: graftm/sequence_io.py
# class Sequence:
#     def __init__(self, name, seq):
#         self.name = name
#         self.seq = seq


import unittest
import os
import sys
from graftm.deduplicator import Deduplicator
from graftm.sequence_io import Sequence
#
# Copyright
#
# This is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License.
# If not, see <http://www.gnu.org/licenses/>.
#=======================================================================


sys.path = [os.path.join(os.path.dirname(os.path.realpath(__file__)),'..')]+sys.path

class Tests(unittest.TestCase):
    def s(self, seqs):
        to_return = []
        current_seq = None
        for bit in str.split(seqs,' '):
            if current_seq:
                current_seq.seq = bit
                to_return.append(current_seq)
                current_seq = None
            else:

# Path: graftm/deduplicator.py
# class Deduplicator:
#     r"""Deduplicates sequences"""
#     
#     def deduplicate(self, aligned_sequence_objects):
#         r"""Sort the given aligned_sequence objects into an array of arrays,
#         where input sequences are grouped iff they have the same sequence
#         
#         Parameters
#         ----------
#         aligned_sequence_objects: array of Sequence objects
#             input sequences
#             
#         Returns
#         -------
#         Array of arrays of Sequence objects"""
#         
#         sequence_to_groups = {}
#         for s in aligned_sequence_objects:
#             try:
#                 sequence_to_groups[s.seq].append(s)
#             except KeyError:
#                 sequence_to_groups[s.seq] = [s]
#         return list(sequence_to_groups.values())
#     
#     def lca_taxonomy(self, deduplicated_sequences, taxonomy_hash):
#         r'''Given a set of deduplicated sequences and a taxonomy hash,
#         return the respective LCAs of taxonomy
#         
#         Parameters
#         ----------
#         deduplicated_sequences: Array of arrays of Sequence objects
#             as output from deduplicate()
#         taxonomy_hash: dictionary 
#             of sequence names to taxonomy array (i.e. array of str)
#         
#         Returns
#         -------
#         Array of taxonomy LCAs'''
#         
#         to_return = []
#         for dup_group in deduplicated_sequences:
#             lca = taxonomy_hash[dup_group[0].name]
#             for s in dup_group[1:]:
#                 for i, tax in enumerate(taxonomy_hash[s.name]):
#                     if i >= len(lca) or tax != lca[i]:
#                         lca = lca[:i]
#                         break
#                 if len(lca) > len(taxonomy_hash[s.name]):
#                     lca = lca[:len(taxonomy_hash[s.name])]
#             to_return.append(lca)
#         return to_return
# 
# Path: graftm/sequence_io.py
# class Sequence:
#     def __init__(self, name, seq):
#         self.name = name
#         self.seq = seq


# Path: test/test_deduplicator.py
import unittest
import os
import sys
from graftm.deduplicator import Deduplicator
from graftm.sequence_io import Sequence

#
# Copyright
#
# This is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License.
# If not, see <http://www.gnu.org/licenses/>.
#=======================================================================


sys.path = [os.path.join(os.path.dirname(os.path.realpath(__file__)),'..')]+sys.path

class Tests(unittest.TestCase):
    def s(self, seqs):
        to_return = []
        current_seq = None
        for bit in str.split(seqs,' '):
            if current_seq:
                current_seq.seq = bit
                to_return.append(current_seq)
                current_seq = None
            else:

                current_seq = Sequence(bit, '')