def get_protein_colors(palette='tab20'): """Get protein color dict""" from Bio.PDB.Polypeptide import aa1 aa1 = list(aa1) aa1.append('-') aa1.append('X') import matplotlib as mpl from matplotlib import cm pal = cm.get_cmap(palette, 256) pal = [mpl.colors.to_hex(i) for i in pal(np.linspace(0, 1, 20))] pal.append('white') pal.append('white') pcolors = {i:j for i,j in zip(aa1,pal)} return pcolors
def get_sequence_colors(seq): """Get colors for a sequence""" from bokeh.palettes import brewer, viridis, plasma from Bio.PDB.Polypeptide import aa1 pal = plasma(20) pal.append('white') aa1 = list(aa1) aa1.append('-') pcolors = {i: j for i, j in zip(aa1, pal)} text = list(seq) clrs = {'A': 'red', 'T': 'green', 'G': 'orange', 'C': 'blue', '-': 'white'} try: colors = [clrs[i] for i in text] except: colors = [pcolors[i] for i in text] return colors
def get_sequence_colors(seqs, palette='tab20'): """Get colors for a sequence""" from Bio.PDB.Polypeptide import aa1 aa1 = list(aa1) aa1.append('-') import matplotlib as mpl from matplotlib import cm pal = cm.get_cmap(palette, 256) pal = [mpl.colors.to_hex(i) for i in pal(np.linspace(0, 1, 20))] pal.append('white') pcolors = {i: j for i, j in zip(aa1, pal)} text = [i for s in list(seqs) for i in s] clrs = {'A': 'red', 'T': 'green', 'G': 'orange', 'C': 'blue', '-': 'white'} try: colors = [clrs[i] for i in text] except: colors = [pcolors[i] for i in text] return colors