# Path: phydmslib/constants.py
# AA_TO_INDEX = {aa: i for (i, aa) in INDEX_TO_AA.items()}
# 
# NT_TO_INDEX = {nt: i for (i, nt) in INDEX_TO_NT.items()}


import collections
import os
import tempfile
import string
import math
import shutil
import natsort
import numpy
import matplotlib
import pylab
import PyPDF2
import weblogolib  # weblogo library
import weblogolib.colorscheme  # weblogo library
import corebio.matrix  # weblogo library
import corebio.utils  # weblogo library
    import doctest
from phydmslib.constants import AA_TO_INDEX, NT_TO_INDEX
    charged residues red and hydrophobic ones blue.
    """
    d = {'A': 1.8, 'C': 2.5, 'D': -3.5, 'E': -3.5, 'F': 2.8, 'G': -0.4,
         'H': -3.2, 'I': 4.5, 'K': -3.9, 'L': 3.8, 'M': 1.9, 'N': -3.5,
         'P': -1.6, 'Q': -3.5, 'R': -4.5, 'S': -0.8, 'T': -0.7, 'V': 4.2,
         'W': -0.9, 'Y': -1.3}
    aas = sorted(AA_TO_INDEX.keys())
    hydrophobicities = [d[aa] for aa in aas]
    if reverse:
        hydrophobicities = [-1 * x for x in hydrophobicities]
    mapper = pylab.cm.ScalarMappable(cmap=maptype)
    mapper.set_clim(min(hydrophobicities), max(hydrophobicities))
    mapping_d = {'*': '#000000'}
    for (aa, h) in zip(aas, hydrophobicities):
        tup = mapper.to_rgba(h, bytes=True)
        (red, green, blue, alpha) = tup
        mapping_d[aa] = '#%02x%02x%02x' % (red, green, blue)
        assert len(mapping_d[aa]) == 7
    cmap = mapper.get_cmap()
    return (cmap, mapping_d, mapper)


def MWColorMapping(maptype='jet', reverse=True):
    """Maps amino-acid molecular weights to colors. Otherwise, this
    function is identical to *KyteDoolittleColorMapping*
    """
    d = {'A': 89, 'R': 174, 'N': 132, 'D': 133, 'C': 121, 'Q': 146, 'E': 147,
         'G': 75, 'H': 155, 'I': 131, 'L': 131, 'K': 146, 'M': 149, 'F': 165,
         'P': 115, 'S': 105, 'T': 119, 'W': 204, 'Y': 181, 'V': 117}


# Path: phydmslib/constants.py
# AA_TO_INDEX = {aa: i for (i, aa) in INDEX_TO_AA.items()}
# 
# NT_TO_INDEX = {nt: i for (i, nt) in INDEX_TO_NT.items()}


# Path: phydmslib/weblogo.py
import collections
import os
import tempfile
import string
import math
import shutil
import natsort
import numpy
import matplotlib
import pylab
import PyPDF2
import weblogolib  # weblogo library
import weblogolib.colorscheme  # weblogo library
import corebio.matrix  # weblogo library
import corebio.utils  # weblogo library
    import doctest
from phydmslib.constants import AA_TO_INDEX, NT_TO_INDEX

    charged residues red and hydrophobic ones blue.
    """
    d = {'A': 1.8, 'C': 2.5, 'D': -3.5, 'E': -3.5, 'F': 2.8, 'G': -0.4,
         'H': -3.2, 'I': 4.5, 'K': -3.9, 'L': 3.8, 'M': 1.9, 'N': -3.5,
         'P': -1.6, 'Q': -3.5, 'R': -4.5, 'S': -0.8, 'T': -0.7, 'V': 4.2,
         'W': -0.9, 'Y': -1.3}
    aas = sorted(AA_TO_INDEX.keys())
    hydrophobicities = [d[aa] for aa in aas]
    if reverse:
        hydrophobicities = [-1 * x for x in hydrophobicities]
    mapper = pylab.cm.ScalarMappable(cmap=maptype)
    mapper.set_clim(min(hydrophobicities), max(hydrophobicities))
    mapping_d = {'*': '#000000'}
    for (aa, h) in zip(aas, hydrophobicities):
        tup = mapper.to_rgba(h, bytes=True)
        (red, green, blue, alpha) = tup
        mapping_d[aa] = '#%02x%02x%02x' % (red, green, blue)
        assert len(mapping_d[aa]) == 7
    cmap = mapper.get_cmap()
    return (cmap, mapping_d, mapper)


def MWColorMapping(maptype='jet', reverse=True):
    """Maps amino-acid molecular weights to colors. Otherwise, this
    function is identical to *KyteDoolittleColorMapping*
    """
    d = {'A': 89, 'R': 174, 'N': 132, 'D': 133, 'C': 121, 'Q': 146, 'E': 147,
         'G': 75, 'H': 155, 'I': 131, 'L': 131, 'K': 146, 'M': 149, 'F': 165,
         'P': 115, 'S': 105, 'T': 119, 'W': 204, 'Y': 181, 'V': 117}


    aas = sorted(AA_TO_INDEX.keys())