Create a HTML page for this BAM file.

def create_html(self):
        """Create a HTML page for this BAM file."""

        roc_dicts = []
        with open(self._roc_fn, "r") as roc:
            for line in roc:
                line = line.strip()
                if line != "" and line[0] != "#":
                    (q, M, w, m, P, U, u, T, t, x, a) = map(int, line.split("\t"))
                    roc_dict = {
                        "q": q,
                        "M": M,
                        "w": w,
                        "m": m,
                        "P": P,
                        "U": U,
                        "u": u,
                        "T": T,
                        "t": t,
                        "x": x,
                        "a": a,
                        "mapped": M + w + m + P,
                        "unmapped": U + u + T + t + x,
                    }
                    roc_dicts.append(roc_dict)
        tbody = os.linesep.join(
            [
                """
				<tr>
					<td>        {quality}                   </td>
					<td>        {mapped}                    </td>
					<td><small> {mapped_proc:.2f}   </small></td>
					<td>        {M}                         </td>
					<td><small> {M_proc:.2f}        </small></td>
					<td>        {w}                         </td>
					<td><small> {w_proc:.2f}        </small></td>
					<td>        {m}                         </td>
					<td><small> {m_proc:.2f}        </small></td>
					<td>        {P}                         </td>
					<td><small> {P_proc:.2f}        </small></td>
					<td>        {unmapped}                  </td>
					<td><small> {unmapped_proc:.2f} </small></td>
					<td>        {U}                         </td>
					<td><small> {U_proc:.2f}        </small></td>
					<td>        {u}                         </td>
					<td><small> {u_proc:.2f}        </small></td>
					<td>        {T}                         </td>
					<td><small> {T_proc:.2f}        </small></td>
					<td>        {t}                         </td>
					<td><small> {t_proc:.2f}        </small></td>
					<td>        {x}                         </td>
					<td><small> {x_proc:.2f}        </small></td>
					<td>        {sum}                       </td>
					<td>        {prec_proc:.3f}              </td>
				</tr>
			""".format(
                    quality=roc_dict["q"],
                    mapped=roc_dict["mapped"],
                    mapped_proc=100.0 * (roc_dict["mapped"]) / roc_dict["a"],
                    M=roc_dict["M"],
                    M_proc=100.0 * (roc_dict["M"]) / (roc_dict["mapped"]) if (roc_dict["mapped"]) != 0 else 0,
                    w=roc_dict["w"],
                    w_proc=100.0 * (roc_dict["w"]) / (roc_dict["mapped"]) if (roc_dict["mapped"]) != 0 else 0,
                    m=roc_dict["m"],
                    m_proc=100.0 * (roc_dict["m"]) / (roc_dict["mapped"]) if (roc_dict["mapped"]) != 0 else 0,
                    P=roc_dict["P"],
                    P_proc=100.0 * (roc_dict["P"]) / (roc_dict["mapped"]) if (roc_dict["mapped"]) != 0 else 0,
                    unmapped=roc_dict["unmapped"],
                    unmapped_proc=100.0 * (roc_dict["unmapped"]) / roc_dict["a"],
                    U=roc_dict["U"],
                    U_proc=100.0 * (roc_dict["U"]) / (roc_dict["unmapped"]) if (roc_dict["unmapped"]) != 0 else 0,
                    u=roc_dict["u"],
                    u_proc=100.0 * (roc_dict["u"]) / (roc_dict["unmapped"]) if (roc_dict["unmapped"]) != 0 else 0,
                    T=roc_dict["T"],
                    T_proc=100.0 * (roc_dict["T"]) / (roc_dict["unmapped"]) if (roc_dict["unmapped"]) != 0 else 0,
                    t=roc_dict["t"],
                    t_proc=100.0 * (roc_dict["t"]) / (roc_dict["unmapped"]) if (roc_dict["unmapped"]) != 0 else 0,
                    x=roc_dict["x"],
                    x_proc=100.0 * (roc_dict["x"]) / (roc_dict["unmapped"]) if (roc_dict["unmapped"]) != 0 else 0,
                    sum=roc_dict["a"],
                    prec_proc=100.0 * (roc_dict["M"]) / (roc_dict["mapped"]) if (roc_dict["mapped"]) != 0 else 0,
                ) for roc_dict in roc_dicts
            ]
        )

        with open(self._html_fn, "w+") as html:
            program_info = ["No information available (PG header is essing)."]
            for x in rnftools.utils.shell(
                '"{samtools}" view -H "{bam}"'.format(
                    samtools="samtools",
                    bam=self._bam_fn,
                ), iterable=True
            ):
                x = x.strip()

                if x[:3] == "@PG":
                    pg_header = x[4:].strip()
                    parts = pg_header.split("\t")

                    program_info = ["<table>"]
                    for part in parts:
                        (lvalue, _, rvalue) = part.partition(":")
                        program_info.append(
                            '<tr><td style="font-weight:bold">{}:</td><td style="text-align:left">{}</td></tr>'.format(
                                lvalue, rvalue
                            )
                        )

                    program_info.append("</table>")

            eval_info = ["<table>"]
            for (lvalue, rvalue) in [
                ("BAM file", self._bam_fn),
                ("Allowed delta", self.report.allowed_delta),
            ]:
                eval_info.append(
                    '<tr><td style="font-weight:bold">{}:</td><td style="text-align:left">{}</td></tr>'.format(
                        lvalue, rvalue
                    )
                )

            eval_info.append("</table>")

            css_src = textwrap.dedent(
                """
					table            {border-collapse:collapse;}
					td               {border: solid #aaaaff 1px;padding:4px;text-align:right;}
					colgroup, thead  {border: solid black 2px;padding 2px;}
					.link_to_top     {font-size:10pt;}
					.desc            {color:#aaa;}
					.formats         {text-align:left;margin-bottom:20px;}
				"""
            )

            html_src = """<!DOCTYPE html>
				<html>
				<head>
					<meta charset="UTF-8" />
					<title>{name}</title>
					<style type="text/css">
					{css}
					</style>
				</head>
				<body>
					<h1 id="top">
						{name}
						<span class="link_to_top">
							[<a href="{homepage}">Back to main report</a>]
						</span>
					</h1>
	
					<p>
						<a href="#info_eval">Information about evaluation</a> -
						<a href="#info_prog">Information about program</a> -
						<a href="#roctable">ROC table</a> -
						<a href="#graphs">Graphs</a>
					</p>
	
					<h2 id="info_eval">
						Information about evaluation
						{headline_links}
					</h2>
	
					{eval_info}
	
					<h2 id="info_prog">
						Information about program
						{headline_links}
					</h2>
	
	
					{program_info}
	
					<h2 id="roctable">
						ROC table
						{headline_links}
					</h2>
	
					<p style="font-size:80%">
						<strong>M</strong>:
							mapped correctly
							<span class="desc">
								(all segments of tuple are mapped once and correctly),
							</span>
						<strong>w</strong>:
							mapped to wrong position
							<span class="desc">
								(at least one segment was mapped to a wrong position),
							</span>
						<strong>m</strong>:
							mapped but should be unmapped
							<span class="desc">
								(at least one segment was mapped but the read should not be mapped),
							</span>
						<strong>P</strong>:
							multimapped
							<span class="desc">
								(read should be mapped but it at least one segment was mapped several
								times and all segments were mapped correctly at least once),
							</span>
						<strong>U</strong>:
							unmapped correctly
							<span class="desc">
								(all segments of the read were correctly marked as unmapped),
							</span>
						<strong>u</strong>:
							unmapped but should be mapped
							<span class="desc">
								(at least one segment was mapped but entire read should be unmapped),
							</span>
						<strong>T</strong>:
							thresholded correctly
							<span class="desc">
								(read shoud not be mapped),
							</span>
						<strong>t</strong>:
							thresholded incorrectly
							<span class="desc">
								(read should be mapped),
							</span>
						<strong>x</strong>:
							unknown
							<span class="desc">
								(read is probably not reported by mapper)
							</span>
					</p>
					<table>
						<colgroup span="1" style="">
						<colgroup span="2" style="background-color:#ddd">
						<colgroup span="8" style="">
						<colgroup span="2" style="background-color:#ddd">
						<colgroup span="10" style="">
						<colgroup span="1" style="background-color:#ddd">
						<colgroup span="1" style="">
						<thead style="font-weight:bold;background-color:#ddddff">
							<tr style="font-weight:bold;background-color:#ddddff">
								<td>q</td>
								<td>mapped</td>
								<td>%</td>
								<td>M</td>
								<td>%</td>
								<td>w</td>
								<td>%</td>
								<td>m</td>
								<td>%</td>
								<td>P</td>
								<td>%</td>
								<td>unmapped</td>
								<td>%</td>
								<td>U</td>
								<td>%</td>
								<td>u</td>
								<td>%</td>
								<td>T</td>
								<td>%</td>
								<td>t</td>
								<td>%</td>
								<td>x</td>
								<td>%</td>
								<td>sum</td>
								<td>prec. (%)</td>
							</tr>
						</thead>
						<tbody>
							{tbody}
						</tbody>
					</table>
	
					<h2 id="graphs">
						Graphs
						{headline_links}
					</h2>
	
					<div class="formats">
						<img src="{svg}" />
						<br />
						<a href="{svg}">SVG version</a>
						|
						<a href="{roc}" type="text/csv">ROC file</a>
						|
						<a href="{gp}" type="text/plain">GP file</a>
					</div>
	
	
				</body>
				</html>
				""".format(
                name=self.name, tbody=tbody, css=css_src,
                svg=os.path.relpath(self._svg_fn, os.path.dirname(self._html_fn)),
                roc=os.path.relpath(self._roc_fn, os.path.dirname(self._html_fn)),
                gp=os.path.relpath(self._gp_fn, os.path.dirname(self._html_fn)), eval_info=os.linesep.join(eval_info),
                program_info=os.linesep.join(program_info),
                homepage=os.path.relpath(self.report.html_fn(), os.path.dirname(self._html_fn)), headline_links='''
							<span class="link_to_top">
								[<a href="#top">Top of this page</a>]
								[<a href="{homepage}">Back to main report</a>]
							</span>
						'''.format(homepage=os.path.relpath(self.report.html_fn(), os.path.dirname(self._html_fn)), )
            )

            tidy_html_src = bs4.BeautifulSoup(html_src).prettify()
            html.write(tidy_html_src)