Skip to content

Commit

Permalink
Adding missing __repr__ docstrings in Wise and UniGene
Browse files Browse the repository at this point in the history
Removed a redundant __str__ definition, if not defined then
Python defaults to using __repr__ anyway (thanks Markus!).

See flake8 D105.
  • Loading branch information
peterjc committed Jun 9, 2019
1 parent 91509ec commit 37f2350
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Bio/UniGene/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def _init_from_text(self, text):
setattr(self, key.lower(), val)

def __repr__(self):
"""Return UniGene SequenceLine object as a string."""
return self.text


Expand Down Expand Up @@ -165,6 +166,7 @@ def _init_from_text(self, text):
setattr(self, key.lower(), val)

def __repr__(self):
"""Return UniGene ProtsimLine object as a string."""
return self.text


Expand Down Expand Up @@ -195,6 +197,7 @@ def _init_from_text(self, text):
setattr(self, key.lower(), val)

def __repr__(self):
"""Return UniGene STSLine object as a string."""
return self.text


Expand Down Expand Up @@ -246,6 +249,7 @@ def __init__(self):
self.txmap = [] # TXMAP entries, array of TXMap entries

def __repr__(self):
"""Represent the UniGene Record object as a string for debugging."""
return "<%s> %s %s\n%s" % (self.__class__.__name__,
self.ID, self.symbol, self.title)

Expand Down
1 change: 1 addition & 0 deletions Bio/Wise/dnal.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def identity_fraction(self):
header = "identity_fraction\tmatches\tmismatches\tgaps\textensions"

def __str__(self):
"""Statistics as a tab separated string."""
return "\t".join(str(x) for x in (self.identity_fraction(),
self.matches, self.mismatches,
self.gaps, self.extensions))
Expand Down
14 changes: 7 additions & 7 deletions Bio/Wise/psw.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def __init__(self, column_unit):
list.__init__(self, [column_unit.column, None])

def __repr__(self):
return "%s(%s, %s)" % (self.kind, self[0], self[1])
"""Represent the AlignmentColumn object as a string for debugging."""
return "%s(%r, %r)" % (self.kind, self[0], self[1])

def append(self, column_unit):
"""Add a unit to the Column."""
Expand All @@ -85,10 +86,9 @@ def __init__(self, unit, column, kind):
self.column = column
self.kind = kind

def __str__(self):
return "ColumnUnit(unit=%s, column=%s, %s)" % (self.unit, self.column, self.kind)

__repr__ = __str__
def __repr__(self):
"""Represent the ColumnUnit object as a string for debugging."""
return "ColumnUnit(unit=%r, column=%r, kind=%r)" % (self.unit, self.column, self.kind)


_re_unit = re.compile(r"^Unit +([01])- \[ *(-?\d+)- *(-?\d+)\] \[(\w+)\]$")
Expand All @@ -100,9 +100,9 @@ def parse_line(line):
>>> print(parse_line("Column 0:"))
None
>>> parse_line("Unit 0- [ -1- 0] [SEQUENCE]")
ColumnUnit(unit=0, column=0, SEQUENCE)
ColumnUnit(unit=0, column=0, kind='SEQUENCE')
>>> parse_line("Unit 1- [ 85- 86] [SEQUENCE]")
ColumnUnit(unit=1, column=86, SEQUENCE)
ColumnUnit(unit=1, column=86, kind='SEQUENCE')
"""
match = _re_unit.match(line.rstrip())

Expand Down
6 changes: 3 additions & 3 deletions Tests/test_psw.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ def test_AlignmentColumn_assertions(self):

def test_ColumnUnit(self):
self.assertEqual(repr(psw.ColumnUnit(0, 33, "SEQUENCE")),
"ColumnUnit(unit=0, column=33, SEQUENCE)")
"ColumnUnit(unit=0, column=33, kind='SEQUENCE')")

self.assertEqual(repr(psw.ColumnUnit(1, 33, "INSERT")),
"ColumnUnit(unit=1, column=33, INSERT)")
"ColumnUnit(unit=1, column=33, kind='INSERT')")

self.assertEqual(repr(psw.ColumnUnit(1, 33, "END")),
"ColumnUnit(unit=1, column=33, END)")
"ColumnUnit(unit=1, column=33, kind='END')")

PARSED = "[SEQUENCE(39, 22), SEQUENCE(40, 23), SEQUENCE(41, 24), SEQUENCE(42, 25), SEQUENCE(43, 26), SEQUENCE(44, 27), END(0, 27)]"

Expand Down

0 comments on commit 37f2350

Please sign in to comment.