From 85215bc348d2fa09e29eb13025419e92a96628c4 Mon Sep 17 00:00:00 2001 From: Yan Wong Date: Tue, 3 Dec 2024 11:37:10 +0000 Subject: [PATCH] Show child alleles & identical parent alleles in bold --- sc2ts/info.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/sc2ts/info.py b/sc2ts/info.py index 60d4175..9168a02 100644 --- a/sc2ts/info.py +++ b/sc2ts/info.py @@ -1128,14 +1128,16 @@ def node_mutations(self, node): return muts def _copying_table(self, node, edges): - def css_cell(allele): + def css_cell(allele, bold=False, show_colour=True): # function for the cell style - nucleotide colours faded from SNiPit cols = {"A": "#869eb5", "T": "#adbda8", "C": "#d19394", "G": "#c3dde6"} - return ( - ' style="border: 1px solid black; background-color: ' - + cols.get(allele, "white") - + '; border-collapse: collapse;"' - ) + css = "" + if show_colour: + css += "border: 1px solid black; border-collapse: collapse" + css += ";background-color:" + cols.get(allele, "white") + if bold: + css += ";font-weight: bold" + return "" if css == "" else f' style="{css}"' vrl = ' style="writing-mode: vertical-rl; transform: rotate(180deg)"' @@ -1160,15 +1162,19 @@ def css_cell(allele): pos = int(var.site.position) positions.append(f"{pos}") ref.append(f"{var.site.ancestral_state}") - allele = var.alleles[var.genotypes[0]] - child.append(f"{allele}") + child_allele = var.alleles[var.genotypes[0]] + child.append(f"{child_allele}") edge_index = np.searchsorted(edges.left, pos, side="right") - 1 parent_col = parent_cols[edges[edge_index].parent] for j in range(1, len(var.genotypes)): - allele = var.alleles[var.genotypes[j]] - css = css_cell(allele) if j == parent_col else "" - parents[j - 1].append(f"{allele}") + parent_allele = var.alleles[var.genotypes[j]] + css = css_cell( + parent_allele, + bold=parent_allele==child_allele, + show_colour=j == parent_col, + ) + parents[j - 1].append(f"{parent_allele}") extra_mut.append(f"{mutations.get(pos, '')}")