Skip to content

Instantly share code, notes, and snippets.

@knmkr
Created December 13, 2012 08:27
Show Gist options
  • Save knmkr/4274996 to your computer and use it in GitHub Desktop.
Save knmkr/4274996 to your computer and use it in GitHub Desktop.
Get sequence with colors, according to color table {sub_sequence: color_name }, e.g, {'A': 'red'}.
from termcolor import colored
def seq2colored_seq(seq, color_table):
"""Return sequence with colors, according to color_table {sub_sequence: color_name}, e.g, {'A': 'red'}.
"""
result = ''
for x in seq:
if x in color_table:
x = colored(x, color_table[x], attrs=['reverse'])
result += x
return result
def _main():
print seq2colored_seq('TTTAAAGGGCCC', {'A':'red', 'T':'green'})
if __name__ == '__main__':
_main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment