Convert text file to html?
Functions

Right now, write_html manages both parsing and writing to a file. Separate this function into two functions, perhaps parse_data and write_data.

String Formatting

This

s = "&lt;pre&gt;" + line + "&lt;/pre&gt;"
e.write("&lt;td&gt;" + sequence_1 + '&lt;/td&gt;' + '\n')


can be written like this

s = f"&lt;pre&gt;{line}&gt;&lt;/pre&gt;"
e.write(f"&lt;td&gt;{sequence_1}&lt;/td&gt;\n")


The f"" allows you to directly implement variables into your strings.

Simplification

This

elif line.startswith('# Gaps:'):
    line = line.split()
    gaps = line[2]


can be written like this

elif line.startswith('# Gaps:'):
    gaps = line.split()[2]


The same with these two:

if line.startswith('# 1:'):
    sequence_1 = line.split()[2]
elif line.startswith('# 2:'):
    sequence_2 = line.split()[2]


Variable Assignments

This

sequence_1 = ''
sequence_2 = ''
identity = ''
similarity = ''
gaps = ''
html_string = ''


can be written like this

sequence_1, sequence_2, identity, gaps, similarity, html_string = '', '', '', '', '', ''


Type Hints

You can use type hints to make it clear what is being accepted as parameters, and what is being returned by the function.

From this

def write_html(result):


to this

def write_html(result: str) -&gt; None:


Docstrings

You should include a docstring at the beginning of every function, method, class, and module you write. This will allow documentation to identify what these are supposed to do.

def write_html(result: str) -&gt; None:
    """
    (Description about this method here)
    """
    ... code here ...