From 3ebf90386070986a5f86ab1f53ded991ef3d5f8c Mon Sep 17 00:00:00 2001 From: Robert McArthur Date: Mon, 29 Apr 2024 15:42:33 +1000 Subject: [PATCH] DOC: clean up seqcol.to_html comments --- src/cogent3/core/alignment.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/cogent3/core/alignment.py b/src/cogent3/core/alignment.py index 9021dd659..12c3d2c07 100644 --- a/src/cogent3/core/alignment.py +++ b/src/cogent3/core/alignment.py @@ -2208,6 +2208,7 @@ def to_html( colors=colors, font_size=font_size, font_family=font_family ) + # Gather stats about the sequence lengths seq_lens = sorted([len(seq) for seq in self.seqs]) if seq_lens: min_seq_len = seq_lens[0] @@ -2230,12 +2231,10 @@ def to_html( name_order = list(self.names) selected = self - gaps = "".join(selected.moltype.gaps) # Gets gap characters - - # Need to do this on a per Sequence basis. + # Stylise each character in each sequence + gaps = "".join(selected.moltype.gaps) template = '%%s' styled_seqs = defaultdict(list) - max_truncated_len = 0 for name in name_order: sequence = str(self.named_seqs[name])[:limit] @@ -2258,13 +2257,14 @@ def to_html( styled_seqs[name] = seq + # Ensure all sublists are of same length for name in styled_seqs: if len(styled_seqs[name]) < max_truncated_len: styled_seqs[name].extend( [""] * (max_truncated_len - len(styled_seqs[name])) ) - # make a html table + # Make html table seqs = array([styled_seqs[n] for n in name_order], dtype="O") table = [""] seq_ = "" @@ -2275,7 +2275,8 @@ def to_html( seqblock = seqs[:, i : i + wrap].tolist() for n, s in zip(name_order, seqblock): s = "".join(s) - if len(s) > 0: # If the row in the seq col is populated + # Filter out rows that are empty (due to combination of shorter sequences + wrapping) + if len(s) > 0: row = "".join([label_ % n, seq_ % s]) table.append(f"{row}") table.append("
%s
")