# Path: abpytools/home.py
# class Home:
# 
#     def __init__(self):
# 
#         self.homedir = os.path.dirname(os.path.abspath(__file__))
# 
# Path: abpytools/utils/python_config.py
# class PythonConfig:
#     def __init__(self):
#         self._backend = get_ipython_info()
#         self._matplotlib_interactive = plt.isinteractive()
# 
#     @property
#     def ipython_info(self):
#         return self._backend
# 
#     @property
#     def matplotlib_interactive(self):
#         return self._matplotlib_interactive  # pragma: no cover


import warnings
import _pickle as cPickle
import matplotlib.pyplot as plt
from abpytools.home import Home
from ..utils.python_config import PythonConfig

def load_alignment_algorithm(algorithm):
    if algorithm.lower() == 'needleman_wunsch':
        return needleman_wunsch

    else:
        raise ValueError("Unknown algorithm")


def load_substitution_matrix(substitution_matrix):

    abpytools_directory = Home().homedir

    if substitution_matrix in SUPPORTED_SUBSITUTION_MATRICES:
        with open('{}/data/{}.txt'.format(abpytools_directory, substitution_matrix), 'rb') as f:
            matrix = cPickle.load(f)
    else:
        raise ValueError("Unknown substitution matrix")

    return matrix


def needleman_wunsch(seq_1, seq_2, substitution_matrix, indel=-1):

    if indel >= 0:
        f = "Indel must be negative, setting indel to {}.".format(-indel)
        warnings.warn(f)
        indel = -indel

    # initialise matrix

# Path: abpytools/home.py
# class Home:
# 
#     def __init__(self):
# 
#         self.homedir = os.path.dirname(os.path.abspath(__file__))
# 
# Path: abpytools/utils/python_config.py
# class PythonConfig:
#     def __init__(self):
#         self._backend = get_ipython_info()
#         self._matplotlib_interactive = plt.isinteractive()
# 
#     @property
#     def ipython_info(self):
#         return self._backend
# 
#     @property
#     def matplotlib_interactive(self):
#         return self._matplotlib_interactive  # pragma: no cover


# Path: abpytools/analysis/analysis_helper_functions.py
import warnings
import _pickle as cPickle
import matplotlib.pyplot as plt
from abpytools.home import Home
from ..utils.python_config import PythonConfig


def load_alignment_algorithm(algorithm):
    if algorithm.lower() == 'needleman_wunsch':
        return needleman_wunsch

    else:
        raise ValueError("Unknown algorithm")


def load_substitution_matrix(substitution_matrix):

    abpytools_directory = Home().homedir

    if substitution_matrix in SUPPORTED_SUBSITUTION_MATRICES:
        with open('{}/data/{}.txt'.format(abpytools_directory, substitution_matrix), 'rb') as f:
            matrix = cPickle.load(f)
    else:
        raise ValueError("Unknown substitution matrix")

    return matrix


def needleman_wunsch(seq_1, seq_2, substitution_matrix, indel=-1):

    if indel >= 0:
        f = "Indel must be negative, setting indel to {}.".format(-indel)
        warnings.warn(f)
        indel = -indel

    # initialise matrix

    init_matrix = init_score_matrix(seq_1=seq_1, seq_2=seq_2,