# Path: abstar/utils/indels.py
# class Indel(object):
# class Insertion(Indel):
# class Deletion(Indel):
#     def __init__(self, indel):
#     def __contains__(self, item):
#     def __getitem__(self, key):
#     def _get_frame(self):
#     def __init__(self, indel):
#     def imgt_formatted(self):
#     def abstar_formatted(self):
#     def json_formatted(self):
#     def __init__(self, indel):
#     def imgt_formatted(self):
#     def abstar_formatted(self):
#     def json_formatted(self):
# def find_insertions(antibody, segment):
# def _annotate_insertion(segment, start, length, sequence, fixed=False):
# def _fix_frameshift_insertion(antibody, segment, s, e):
# def find_deletions(antibody, segment):
# def _annotate_deletion(segment, start, length, sequence, fixed=False):
# def _fix_frameshift_deletion(antibody, segment, s, e):
# 
# Path: abstar/utils/mixins.py
# class LoggingMixin(object):
#     """docstring for LoggingMixin"""
#     def __init__(self):
#         self._log = None
#         self._exceptions = None
# 
# 
#     @property
#     def logs(self):
#         if self._log is not None:
#             return self._log
#         return []
# 
# 
#     @property
#     def exceptions(self):
#         if self._exceptions is not None:
#             return self._exceptions
#         return []
# 
# 
#     def log(self, *args, **kwargs):
#         '''
#         Records a log message
#         '''
#         sep = kwargs.get('sep', ' ')
#         lstring = sep.join([str(a) for a in args])
#         if self._log is None:
#             self._log = [lstring, ]
#         else:
#             self._log.append(lstring)
# 
# 
#     def exception(self, *args, **kwargs):
#         '''
#         Records an exception.
#         '''
#         sep = kwargs.get('sep', '\n')
#         estring = sep.join([str(a) for a in args])
#         if self._exceptions is None:
#             self._exceptions = [estring, ]
#         else:
#             self._exceptions.append(estring)
# 
# 
#     def format_log(self):
#         '''
#         Formats the log, including exceptions.
# 
#         Log formatting will only be performed on sequences that had an
#         error during annotation, unless AbStar is run in debug
#         mode. In debug mode, all sequences will be logged.
# 
#         Returns:
#         --------
# 
#             str: Formatted log string.
#         '''
#         output = ''
#         output += '\n'.join(self.logs)
#         if self._check_for_exceptions():
#             output += '\n\n'
#             output += self._format_exceptions()
#         output += '\n\n'
#         return output
# 
# 
#     def _check_for_exceptions(self):
#         if self.exceptions:
#             return True
#         if self.v is not None:
#             if self.v._exceptions:
#                 return True
#         if self.d is not None:
#             if self.d._exceptions:
#                 return True
#         if self.j is not None:
#             if self.j._exceptions:
#                 return True
#         return False
# 
# 
#     def _format_exceptions(self):
#         exceptions = []
#         exceptions += self.exceptions
#         estring = '\n\nEXCEPTIONS\n'
#         estring += '----------\n\n'
#         if self.v is not None:
#             exceptions += self.v.exceptions
#         if self.d is not None:
#             exceptions += self.d.exceptions
#         if self.j is not None:
#             exceptions += self.j.exceptions
#         estring += '\n\n'.join([e for e in exceptions])
#         return estring


import math
import os
import traceback
from Bio import SeqIO
from Bio.Seq import Seq
from abutils.core.sequence import Sequence
from abutils.utils.alignment import global_alignment, local_alignment
from abutils.utils.codons import codon_lookup
from abutils.utils.decorators import lazy_property
from ..utils import indels
from ..utils.mixins import LoggingMixin


    def _fix_ambigs(self, antibody):
        '''
        Fixes ambiguous nucleotides by replacing them with the germline nucleotide.
        '''
        self.query_alignment = ''.join([q if q.upper() != 'N' else g for q, g in zip(self.query_alignment,
                                                                                     self.germline_alignment)])
        # don't forget to also correct ambigs in the oriented_input sequence
        antibody.oriented_input.sequence = antibody.oriented_input.sequence[:self.query_start] + \
            self.query_alignment.replace('-', '') + \
            antibody.oriented_input.sequence[self.query_end + 1:]


    def _indel_check(self):
        if any(['-' in self.query_alignment, '-' in self.germline_alignment]):
            return True
        return False


    def _find_indels(self, antibody):
        '''
        Identifies and annotates indels in the query sequence.
        '''
        if self._indel_check():
            self.insertions = indels.find_insertions(antibody, self)
            if self.insertions:
                # only set self.has_insertion to 'yes' if the sequence has an in-frame insertion
                if 'yes' in [ins['in frame'] for ins in self.insertions]:
                    self.has_insertion = 'yes'

# Path: abstar/utils/indels.py
# class Indel(object):
# class Insertion(Indel):
# class Deletion(Indel):
#     def __init__(self, indel):
#     def __contains__(self, item):
#     def __getitem__(self, key):
#     def _get_frame(self):
#     def __init__(self, indel):
#     def imgt_formatted(self):
#     def abstar_formatted(self):
#     def json_formatted(self):
#     def __init__(self, indel):
#     def imgt_formatted(self):
#     def abstar_formatted(self):
#     def json_formatted(self):
# def find_insertions(antibody, segment):
# def _annotate_insertion(segment, start, length, sequence, fixed=False):
# def _fix_frameshift_insertion(antibody, segment, s, e):
# def find_deletions(antibody, segment):
# def _annotate_deletion(segment, start, length, sequence, fixed=False):
# def _fix_frameshift_deletion(antibody, segment, s, e):
# 
# Path: abstar/utils/mixins.py
# class LoggingMixin(object):
#     """docstring for LoggingMixin"""
#     def __init__(self):
#         self._log = None
#         self._exceptions = None
# 
# 
#     @property
#     def logs(self):
#         if self._log is not None:
#             return self._log
#         return []
# 
# 
#     @property
#     def exceptions(self):
#         if self._exceptions is not None:
#             return self._exceptions
#         return []
# 
# 
#     def log(self, *args, **kwargs):
#         '''
#         Records a log message
#         '''
#         sep = kwargs.get('sep', ' ')
#         lstring = sep.join([str(a) for a in args])
#         if self._log is None:
#             self._log = [lstring, ]
#         else:
#             self._log.append(lstring)
# 
# 
#     def exception(self, *args, **kwargs):
#         '''
#         Records an exception.
#         '''
#         sep = kwargs.get('sep', '\n')
#         estring = sep.join([str(a) for a in args])
#         if self._exceptions is None:
#             self._exceptions = [estring, ]
#         else:
#             self._exceptions.append(estring)
# 
# 
#     def format_log(self):
#         '''
#         Formats the log, including exceptions.
# 
#         Log formatting will only be performed on sequences that had an
#         error during annotation, unless AbStar is run in debug
#         mode. In debug mode, all sequences will be logged.
# 
#         Returns:
#         --------
# 
#             str: Formatted log string.
#         '''
#         output = ''
#         output += '\n'.join(self.logs)
#         if self._check_for_exceptions():
#             output += '\n\n'
#             output += self._format_exceptions()
#         output += '\n\n'
#         return output
# 
# 
#     def _check_for_exceptions(self):
#         if self.exceptions:
#             return True
#         if self.v is not None:
#             if self.v._exceptions:
#                 return True
#         if self.d is not None:
#             if self.d._exceptions:
#                 return True
#         if self.j is not None:
#             if self.j._exceptions:
#                 return True
#         return False
# 
# 
#     def _format_exceptions(self):
#         exceptions = []
#         exceptions += self.exceptions
#         estring = '\n\nEXCEPTIONS\n'
#         estring += '----------\n\n'
#         if self.v is not None:
#             exceptions += self.v.exceptions
#         if self.d is not None:
#             exceptions += self.d.exceptions
#         if self.j is not None:
#             exceptions += self.j.exceptions
#         estring += '\n\n'.join([e for e in exceptions])
#         return estring


# Path: abstar/core/germline.py
import math
import os
import traceback
from Bio import SeqIO
from Bio.Seq import Seq
from abutils.core.sequence import Sequence
from abutils.utils.alignment import global_alignment, local_alignment
from abutils.utils.codons import codon_lookup
from abutils.utils.decorators import lazy_property
from ..utils import indels
from ..utils.mixins import LoggingMixin



    def _fix_ambigs(self, antibody):
        '''
        Fixes ambiguous nucleotides by replacing them with the germline nucleotide.
        '''
        self.query_alignment = ''.join([q if q.upper() != 'N' else g for q, g in zip(self.query_alignment,
                                                                                     self.germline_alignment)])
        # don't forget to also correct ambigs in the oriented_input sequence
        antibody.oriented_input.sequence = antibody.oriented_input.sequence[:self.query_start] + \
            self.query_alignment.replace('-', '') + \
            antibody.oriented_input.sequence[self.query_end + 1:]


    def _indel_check(self):
        if any(['-' in self.query_alignment, '-' in self.germline_alignment]):
            return True
        return False


    def _find_indels(self, antibody):
        '''
        Identifies and annotates indels in the query sequence.
        '''
        if self._indel_check():
            self.insertions = indels.find_insertions(antibody, self)
            if self.insertions:
                # only set self.has_insertion to 'yes' if the sequence has an in-frame insertion
                if 'yes' in [ins['in frame'] for ins in self.insertions]:
                    self.has_insertion = 'yes'

            self.deletions = indels.find_deletions(antibody, self)