Skip to content

Commit

Permalink
Add string representation for SequenceProfile
Browse files Browse the repository at this point in the history
  • Loading branch information
padix-key committed Sep 8, 2024
1 parent a1f8079 commit e93d448
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/biotite/sequence/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,23 @@ def gaps(self, new_gaps):
)
self._gaps = new_gaps

def __str__(self):
# Add an additional row and column for the position and symbol indicators
print_matrix = np.full(
(self.symbols.shape[0] + 1, self.symbols.shape[1] + 1), "", dtype=object
)
print_matrix[1:, 1:] = self.symbols.astype(str)
print_matrix[0, 1:] = [str(sym) for sym in self.alphabet]
print_matrix[1:, 0] = [str(i) for i in range(self.symbols.shape[0])]
max_len = len(max(print_matrix.flatten(), key=len))
return "\n".join(
[
" ".join([str(cell).rjust(max_len) for cell in row])
for row in print_matrix
]
)

def __repr__(self):
"""Represent SequenceProfile as a string for debugging."""
return (
f"SequenceProfile(np.{np.array_repr(self.symbols)}, "
f"np.{np.array_repr(self.gaps)}, Alphabet({self.alphabet}))"
Expand Down

0 comments on commit e93d448

Please sign in to comment.