Commit 25b33ebe authored by Laros's avatar Laros
Browse files

Added fancy printing of a protein to the console (handy for debugging).


git-svn-id: https://humgenprojects.lumc.nl/svn/mutalyzer/trunk@655 eb6bd6ab-9ccd-42b9-aceb-e2899b4a52f1
parent 74f517c2
......@@ -73,16 +73,16 @@ def main(cmd):
print i
print "\nOld protein:"
print html2text.html2text(''.join(map(lambda x: str(x) + "<br>",
O.getOutput("oldProteinFancy"))))
for i in O.getOutput("oldProteinFancyText"):
print i
print "\nNew protein:"
print html2text.html2text(''.join(map(lambda x: str(x) + "<br>",
O.getOutput("newProteinFancy"))))
for i in O.getOutput("newProteinFancyText"):
print i
print "\nAlternative protein:"
print html2text.html2text(''.join(map(lambda x: str(x) + "<br>",
O.getOutput("altProteinFancy"))))
for i in O.getOutput("altProteinFancyText"):
print i
print "\nExon information:"
for i in O.getOutput("exonInfo") :
......
......@@ -662,7 +662,7 @@ def _insert_tag(s, pos1, pos2, tag1, tag2):
# Todo: cleanup
def print_protein_html(s, first, last, O, where):
def print_protein_html(s, first, last, O, where, text=False):
"""
Make a fancy representation of a protein and put it in the Output
object under the name 'where'. The representation contains HTML tags
......@@ -686,8 +686,13 @@ def print_protein_html(s, first, last, O, where):
block = 10 # Each block consists of 10 amino acids.
line = 6 * block # Each line consists of 6 blocks.
tag1 = '<b style="color:#FF0000">' # Use this tag for highlighting.
tag2 = '</b>' # And this one to end highlighting.
if text:
tag1 = '\033[91m' # Use this tag for highlighting.
tag2 = '\033[0m' # And this one to end highlighting.
else:
tag1 = '<b style="color:#FF0000">' # Use this tag for highlighting.
tag2 = '</b>' # And this one to end highlighting.
#else
# The maximum length for positions is the 10_log of the length of the
# protein.
......@@ -706,8 +711,12 @@ def print_protein_html(s, first, last, O, where):
o += line
O.addOutput(where, output)
# Add the position (while escaping any potential highlighting).
output = '<tt style="color:000000;font-weight:normal">%s</tt> ' \
% str(o).rjust(m)
if text:
output = '%s%s%s ' % (tag2, str(o).rjust(m), tag1)
else:
output = \
'<tt style="color:000000;font-weight:normal">%s</tt> ' % \
str(o).rjust(m)
# Add last line.
O.addOutput(where, output)
......
......@@ -1337,20 +1337,28 @@ def _add_transcript_info(mutator, transcript, output):
# use something like below in protein_description().
util.print_protein_html(protein_original + '*', 0, 0, output,
'oldProteinFancy')
util.print_protein_html(protein_original + '*', 0, 0, output,
'oldProteinFancyText', text=True)
if str(cds_variant[0:3]) in \
Bio.Data.CodonTable.unambiguous_dna_by_id \
[transcript.txTable].start_codons:
output.addOutput('newprotein', '?')
util.print_protein_html('?', 0, 0, output, 'newProteinFancy')
util.print_protein_html('?', 0, 0, output,
'newProteinFancyText', text=True)
output.addOutput('altStart', str(cds_variant[0:3]))
if str(protein_original[1:]) != str(protein_variant[1:]):
output.addOutput('altProtein',
'M' + protein_variant[1:] + '*')
util.print_protein_html('M' + protein_variant[1:] + '*', 0, 0,
output, 'altProteinFancy')
util.print_protein_html('M' + protein_variant[1:] + '*', 0,
0, output, 'altProteinFancy')
util.print_protein_html('M' + protein_variant[1:] + '*', 0,
0, output, 'altProteinFancyText', text=True)
else :
output.addOutput('newprotein', '?')
util.print_protein_html('?', 0, 0, output, 'newProteinFancy')
util.print_protein_html('?', 0, 0, output,
'newProteinFancyText', text=True)
else:
cds_length = util.cds_length(
......@@ -1362,12 +1370,16 @@ def _add_transcript_info(mutator, transcript, output):
# This is never used.
output.addOutput('myProteinDescription', descr)
util.print_protein_html(protein_original + '*', first, last_original,
output, 'oldProteinFancy')
util.print_protein_html(protein_original + '*', first,
last_original, output, 'oldProteinFancy')
util.print_protein_html(protein_original + '*', first,
last_original, output, 'oldProteinFancyText', text=True)
if str(protein_original) != str(protein_variant):
output.addOutput('newprotein', protein_variant + '*')
util.print_protein_html(protein_variant + '*', first, last_variant,
output, 'newProteinFancy')
util.print_protein_html(protein_variant + '*', first,
last_variant, output, 'newProteinFancy')
util.print_protein_html(protein_variant + '*', first,
last_variant, output, 'newProteinFancyText', text=True)
#_add_transcript_info
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment