Commit 934c2bff authored by Mikael Boden's avatar Mikael Boden

L3

parent d56ac8d9
...@@ -643,13 +643,15 @@ class Alignment(): ...@@ -643,13 +643,15 @@ class Alignment():
distmat[i, j] = distmat[j, i] = dist distmat[i, j] = distmat[j, i] = dist
return distmat return distmat
def writeHTML(self, filename): def writeHTML(self, filename=None):
""" Generate HTML that displays the alignment in color. """ Generate HTML that displays the alignment in color.
Requires that the alphabet is annotated with the label 'html-color' (see Sequence.annotateSym) Requires that the alphabet is annotated with the label 'html-color' (see Sequence.annotateSym)
and that each symbol maps to a text string naming the color, e.g. 'blue' and that each symbol maps to a text string naming the color, e.g. 'blue'
""" """
fh = open(filename, 'w') if filename == None:
fh.write('<html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">\n<title>Sequence Alignment</title>\n</head><body><pre>\n') htmlstr = '<pre>\n'
else:
htmlstr = '<html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">\n<title>Sequence Alignment</title>\n</head><body><pre>\n'
maxNameLength = self.getnamelen() maxNameLength = self.getnamelen()
html = ''.ljust(maxNameLength) + ' ' html = ''.ljust(maxNameLength) + ' '
for i in range(self.alignlen - 1): for i in range(self.alignlen - 1):
...@@ -658,7 +660,7 @@ class Alignment(): ...@@ -658,7 +660,7 @@ class Alignment():
else: else:
html += ' ' html += ' '
html += '%s\n' % (self.alignlen) html += '%s\n' % (self.alignlen)
fh.write(html) htmlstr += html
if self.alignlen > 10: if self.alignlen > 10:
html = ''.ljust(maxNameLength) + ' ' html = ''.ljust(maxNameLength) + ' '
for i in range(self.alignlen - 1): for i in range(self.alignlen - 1):
...@@ -667,7 +669,7 @@ class Alignment(): ...@@ -667,7 +669,7 @@ class Alignment():
else: else:
html += ' ' html += ' '
html += '\n' html += '\n'
fh.write(html) htmlstr += html
for seq in self.seqs: for seq in self.seqs:
html = seq.name.ljust(maxNameLength) + ' ' html = seq.name.ljust(maxNameLength) + ' '
for sym in seq: for sym in seq:
...@@ -676,9 +678,15 @@ class Alignment(): ...@@ -676,9 +678,15 @@ class Alignment():
color = 'white' color = 'white'
html += '<font style="BACKGROUND-COLOR: %s">%s</font>' % (color, sym) html += '<font style="BACKGROUND-COLOR: %s">%s</font>' % (color, sym)
html += '\n' html += '\n'
fh.write(html) htmlstr += html
fh.write('</pre></body></html>\n') htmlstr += '<pre>'
if filename:
fh = open(filename, 'w')
fh.write(htmlstr)
fh.write('</body></html>\n')
fh.close() fh.close()
else:
return htmlstr
def saveConsensus(aln, theta1 = 0.99, theta2 = 0.01, countgaps = False, consensus = True, filename = None): def saveConsensus(aln, theta1 = 0.99, theta2 = 0.01, countgaps = False, consensus = True, filename = None):
""" Display a table with rows for each alignment column, showing """ Display a table with rows for each alignment column, showing
......
Markdown is supported
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