# Path: crumbs/utils/bin_utils.py
# BIN_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..',
#                                        'bin'))
# 
# Path: crumbs/seq/seq.py
# def assing_kind_to_seqs(kind, seqs, file_format):
#     'It puts each seq into a NamedTuple named Seq'
#     return (SeqWrapper(kind, seq, file_format) for seq in seqs)
# 
# def get_str_seq(seq):
#     seq_class = seq.kind
#     if seq_class == SEQITEM:
#         seq = seq.object.lines[1].strip()
#     elif seq_class == SEQRECORD:
#         seq = str(seq.object.seq)
#     return seq.strip()
# 
# Path: crumbs/seq/utils/seq_utils.py
# def uppercase_length(string):
#     'It returns the number of uppercase characters found in the string'
#     return len(re.findall("[A-Z]", string))
# 
# class ChangeCase(object):
#     'It changes the sequence case.'
# 
#     def __init__(self, action):
#         'The initiator'
#         if action not in (UPPERCASE, LOWERCASE, SWAPCASE):
#             msg = 'Action should be: uppercase, lowercase or invertcase'
#             raise ValueError(msg)
#         self.action = action
# 
#     def __call__(self, seqs):
#         'It changes the case of the seqrecords.'
#         action = self.action
#         processed_seqs = []
#         for seq in seqs:
#             str_seq = get_str_seq(seq)
#             if action == UPPERCASE:
#                 str_seq = str_seq.upper()
#             elif action == LOWERCASE:
#                 str_seq = str_seq.lower()
#             elif action == SWAPCASE:
#                 str_seq = str_seq.swapcase()
#             else:
#                 raise NotImplementedError()
#             seq = copy_seq(seq, seq=str_seq)
#             processed_seqs.append(seq)
#         return processed_seqs
# 
# def get_uppercase_segments(string):
#     '''It detects the unmasked regions of a sequence
# 
#     It returns a list of (start, end) tuples'''
#     start = 0
#     for is_upper, group in itertools.groupby(string, lambda x: x.isupper()):
#         group = list(group)
#         end = start + len(group) - 1
#         if is_upper:
#             yield start, end
#         start = end + 1
# 
# Path: crumbs/utils/tags.py
# SWAPCASE = 'swap'
# 
# UPPERCASE = 'upper'
# 
# LOWERCASE = 'lower'
# 
# SEQRECORD = 'seqrecord'


import unittest
import os.path
from cStringIO import StringIO
from tempfile import NamedTemporaryFile
from subprocess import check_output
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
from crumbs.utils.bin_utils import BIN_DIR
from crumbs.seq.seq import assing_kind_to_seqs, get_str_seq
from crumbs.seq.utils.seq_utils import (uppercase_length, ChangeCase,
                                        get_uppercase_segments)
from crumbs.utils.tags import SWAPCASE, UPPERCASE, LOWERCASE, SEQRECORD
# Copyright 2012 Jose Blanca, Peio Ziarsolo, COMAV-Univ. Politecnica Valencia
# This file is part of seq_crumbs.
# seq_crumbs 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.

# seq_crumbs is 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
# along with seq_crumbs. If not, see <http://www.gnu.org/licenses/>.

# pylint: disable=R0201
# pylint: disable=R0904
# pylint: disable=C0111





class UppercaseLengthTest(unittest.TestCase):
    'It tests the uppercase character count'
    def test_uppercase_length(self):
        'It counts the number of uppercase letters in a string'

# Path: crumbs/utils/bin_utils.py
# BIN_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..',
#                                        'bin'))
# 
# Path: crumbs/seq/seq.py
# def assing_kind_to_seqs(kind, seqs, file_format):
#     'It puts each seq into a NamedTuple named Seq'
#     return (SeqWrapper(kind, seq, file_format) for seq in seqs)
# 
# def get_str_seq(seq):
#     seq_class = seq.kind
#     if seq_class == SEQITEM:
#         seq = seq.object.lines[1].strip()
#     elif seq_class == SEQRECORD:
#         seq = str(seq.object.seq)
#     return seq.strip()
# 
# Path: crumbs/seq/utils/seq_utils.py
# def uppercase_length(string):
#     'It returns the number of uppercase characters found in the string'
#     return len(re.findall("[A-Z]", string))
# 
# class ChangeCase(object):
#     'It changes the sequence case.'
# 
#     def __init__(self, action):
#         'The initiator'
#         if action not in (UPPERCASE, LOWERCASE, SWAPCASE):
#             msg = 'Action should be: uppercase, lowercase or invertcase'
#             raise ValueError(msg)
#         self.action = action
# 
#     def __call__(self, seqs):
#         'It changes the case of the seqrecords.'
#         action = self.action
#         processed_seqs = []
#         for seq in seqs:
#             str_seq = get_str_seq(seq)
#             if action == UPPERCASE:
#                 str_seq = str_seq.upper()
#             elif action == LOWERCASE:
#                 str_seq = str_seq.lower()
#             elif action == SWAPCASE:
#                 str_seq = str_seq.swapcase()
#             else:
#                 raise NotImplementedError()
#             seq = copy_seq(seq, seq=str_seq)
#             processed_seqs.append(seq)
#         return processed_seqs
# 
# def get_uppercase_segments(string):
#     '''It detects the unmasked regions of a sequence
# 
#     It returns a list of (start, end) tuples'''
#     start = 0
#     for is_upper, group in itertools.groupby(string, lambda x: x.isupper()):
#         group = list(group)
#         end = start + len(group) - 1
#         if is_upper:
#             yield start, end
#         start = end + 1
# 
# Path: crumbs/utils/tags.py
# SWAPCASE = 'swap'
# 
# UPPERCASE = 'upper'
# 
# LOWERCASE = 'lower'
# 
# SEQRECORD = 'seqrecord'


# Path: test/seq/test_seq_utils.py
import unittest
import os.path
from cStringIO import StringIO
from tempfile import NamedTemporaryFile
from subprocess import check_output
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
from crumbs.utils.bin_utils import BIN_DIR
from crumbs.seq.seq import assing_kind_to_seqs, get_str_seq
from crumbs.seq.utils.seq_utils import (uppercase_length, ChangeCase,
                                        get_uppercase_segments)
from crumbs.utils.tags import SWAPCASE, UPPERCASE, LOWERCASE, SEQRECORD

# Copyright 2012 Jose Blanca, Peio Ziarsolo, COMAV-Univ. Politecnica Valencia
# This file is part of seq_crumbs.
# seq_crumbs 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.

# seq_crumbs is 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
# along with seq_crumbs. If not, see <http://www.gnu.org/licenses/>.

# pylint: disable=R0201
# pylint: disable=R0904
# pylint: disable=C0111





class UppercaseLengthTest(unittest.TestCase):
    'It tests the uppercase character count'
    def test_uppercase_length(self):
        'It counts the number of uppercase letters in a string'

        assert uppercase_length('aCTaGGt') == 4