Skip to content

Commit

Permalink
Merge pull request cogent3#1845 from GavinHuttley/develop
Browse files Browse the repository at this point in the history
MAINT: tidy __repr__ methods in Alignment classes
  • Loading branch information
GavinHuttley committed May 2, 2024
2 parents e195488 + 1b064f8 commit 83af9f8
Showing 1 changed file with 16 additions and 32 deletions.
48 changes: 16 additions & 32 deletions src/cogent3/core/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2601,6 +2601,22 @@ class AlignmentI(object):
default_gap = "-" # default gap character for padding
gap_chars = dict.fromkeys("-?") # default gap chars for comparisons

def __repr__(self):
seqs = []
limit = 10
delimiter = ""
for count, name in enumerate(self.names):
if count == 3:
seqs.append("...")
break
elts = list(str(self.named_seqs[name])[: limit + 1])
if len(elts) > limit:
elts.append("...")
seqs.append(f"{name}[{delimiter.join(elts)}]")
seqs = ", ".join(seqs)

return f"{len(self.names)} x {self.seq_len} {self.moltype.label} alignment: {seqs}"

def alignment_quality(self, app_name: str = "ic_score", **kwargs):
"""
Computes the alignment quality using the indicated app
Expand Down Expand Up @@ -4277,22 +4293,6 @@ def __str__(self):
result.append(">" + str(l) + "\n" + "".join(seq2str(s)))
return "\n".join(result) + "\n"

def __repr__(self) -> str:
seqs = []
limit = 10
delimiter = ""
for count, name in enumerate(self.names):
if count == 3:
seqs.append("...")
break
elts = list(str(self.named_seqs[name])[: limit + 1])
if len(elts) > limit:
elts.append("...")
seqs.append(f"{name}[{delimiter.join(elts)}]")
seqs = ", ".join(seqs)

return f"{len(self.names)} x {self.seq_len} alignment: {seqs}"

@c3warn.deprecated_args(
"2024.6",
reason="consistency with other methods",
Expand Down Expand Up @@ -4919,22 +4919,6 @@ def __getitem__(self, index):

return new

def __repr__(self) -> str:
seqs = []
limit = 10
delimiter = ""
for count, name in enumerate(self.names):
if count == 3:
seqs.append("...")
break
elts = list(str(self.named_seqs[name])[: limit + 1])
if len(elts) > limit:
elts.append("...")
seqs.append(f"{name}[{delimiter.join(elts)}]")
seqs = ", ".join(seqs)

return f"{len(self.names)} x {self.seq_len} alignment: {seqs}"

@property
def annotation_db(self):
return self._annotation_db
Expand Down

0 comments on commit 83af9f8

Please sign in to comment.