Skip to content

Commit 9a18eea

Browse files
manuleraBjornFJohansson
authored andcommitted
add getitem to DseqParts dataclass
1 parent cf756a9 commit 9a18eea

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/pydna/alphabet.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,17 +484,29 @@ def __iter__(self):
484484
)
485485
)
486486

487+
def __getitem__(self, index: int) -> str:
488+
"""
489+
Allow indexing DseqParts instances.
490+
>>> from pydna.alphabet import get_parts
491+
>>> parts = get_parts("eeATCGuggCCGgg")
492+
>>> parts[0]
493+
'ee'
494+
>>> parts[2]
495+
'ATCGuggCCGgg'
496+
"""
497+
return tuple(self)[index]
498+
487499

488500
def get_parts(datastring: str) -> DseqParts:
489501
"""
490-
A namedtuple containing the parts of a dsDNA sequence.
502+
Returns a DseqParts instance containing the parts of a dsDNA sequence.
491503
492504
The datastring should contain a string with dscode symbols.
493505
A regex is used to capture the single stranded regions at the ends as
494506
well as the regiond in the middle.
495507
496508
The figure below numbers the regex capture groups and what they capture
497-
as well as the namedtuple field name.
509+
as well as the DseqParts instance field name.
498510
499511
::
500512

0 commit comments

Comments
 (0)