# Path: abstar/utils/regions.py
# IMGT_REGION_START_POSITIONS_AA = {'FR1': 1, 'CDR1': 27, 'FR2': 39, 'CDR2': 56,
#                                   'FR3': 66, 'CDR3': 105, 'FR4': 118}
# 
# IMGT_REGION_END_POSITIONS_AA = {'FR1': 26, 'CDR1': 38, 'FR2': 55, 'CDR2': 65,
#                                 'FR3': 104, 'CDR3': 117, 'FR4': 129}


import math
import re
import traceback
from abutils.utils import log
from abutils.utils.codons import codon_lookup as codons
from .regions import IMGT_REGION_START_POSITIONS_AA, IMGT_REGION_END_POSITIONS_AA
        antibody.log('FR2:', ', '.join([m.abstar_formatted for m in all_mutations.in_region('FR2')]))
        antibody.log('CDR2:', ', '.join([m.abstar_formatted for m in all_mutations.in_region('CDR2')]))
        antibody.log('FR3:', ', '.join([m.abstar_formatted for m in all_mutations.in_region('FR3')]))
        antibody.log('CDR3:', ', '.join([m.abstar_formatted for m in all_mutations.in_region('CDR3')]))
        antibody.log('FR4:', ', '.join([m.abstar_formatted for m in all_mutations.in_region('FR4')]))
        return all_mutations
    except:
        antibody.exception('NT MUTATIONS', traceback.format_exc())
        return Mutations()


def aa_mutations(antibody):
    try:
        all_mutations = Mutations()
        for segment in [antibody.v, antibody.j]:
            if segment is None:
                continue
            mutations = Mutations()
            for i, (q, g) in enumerate(zip(segment.query_alignment, segment.germline_alignment)):
                raw_nt_pos = i + segment.query_start
                imgt_nt_pos = segment.get_imgt_position_from_raw(raw_nt_pos)
                if imgt_nt_pos is None:
                    continue
                if imgt_nt_pos % 3 != 1:
                    continue
                if any([q == '-', g == '-']):
                    continue
                q_codon_end_pos = i + 3
                if q_codon_end_pos >= len(segment.query_alignment):
                    continue

# Path: abstar/utils/regions.py
# IMGT_REGION_START_POSITIONS_AA = {'FR1': 1, 'CDR1': 27, 'FR2': 39, 'CDR2': 56,
#                                   'FR3': 66, 'CDR3': 105, 'FR4': 118}
# 
# IMGT_REGION_END_POSITIONS_AA = {'FR1': 26, 'CDR1': 38, 'FR2': 55, 'CDR2': 65,
#                                 'FR3': 104, 'CDR3': 117, 'FR4': 129}


# Path: abstar/utils/mutations.py
import math
import re
import traceback
from abutils.utils import log
from abutils.utils.codons import codon_lookup as codons
from .regions import IMGT_REGION_START_POSITIONS_AA, IMGT_REGION_END_POSITIONS_AA

        antibody.log('FR2:', ', '.join([m.abstar_formatted for m in all_mutations.in_region('FR2')]))
        antibody.log('CDR2:', ', '.join([m.abstar_formatted for m in all_mutations.in_region('CDR2')]))
        antibody.log('FR3:', ', '.join([m.abstar_formatted for m in all_mutations.in_region('FR3')]))
        antibody.log('CDR3:', ', '.join([m.abstar_formatted for m in all_mutations.in_region('CDR3')]))
        antibody.log('FR4:', ', '.join([m.abstar_formatted for m in all_mutations.in_region('FR4')]))
        return all_mutations
    except:
        antibody.exception('NT MUTATIONS', traceback.format_exc())
        return Mutations()


def aa_mutations(antibody):
    try:
        all_mutations = Mutations()
        for segment in [antibody.v, antibody.j]:
            if segment is None:
                continue
            mutations = Mutations()
            for i, (q, g) in enumerate(zip(segment.query_alignment, segment.germline_alignment)):
                raw_nt_pos = i + segment.query_start
                imgt_nt_pos = segment.get_imgt_position_from_raw(raw_nt_pos)
                if imgt_nt_pos is None:
                    continue
                if imgt_nt_pos % 3 != 1:
                    continue
                if any([q == '-', g == '-']):
                    continue
                q_codon_end_pos = i + 3
                if q_codon_end_pos >= len(segment.query_alignment):
                    continue

                q_codon = segment.query_alignment[i:q_codon_end_pos]