Created
December 13, 2012 08:27
-
-
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'}.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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