Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iter #46

Merged
merged 8 commits into from
Jan 30, 2025
Merged

Iter #46

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]
### Added
- `__iter__` overload
- `double_runs` property
- `repeats` method
- `name` property
Expand Down
8 changes: 8 additions & 0 deletions opr/primer.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ def __str__(self):
"""
return self._sequence

def __iter__(self):
"""
Iterate through Primer.

:return: base as Generator[str]
"""
yield from self.sequence

def reverse(self, inplace=False):
"""
Reverse sequence.
Expand Down
3 changes: 2 additions & 1 deletion tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ def test_double_runs():
double_runs_2nd = {}
for pair in pairs:
double_runs_2nd[pair] = p1.double_runs[pair]
assert len(double_runs_2nd) == len(double_runs) and all(double_runs[pair] == double_runs_2nd[pair] for pair in double_runs)
assert len(double_runs_2nd) == len(double_runs) and all(
double_runs[pair] == double_runs_2nd[pair] for pair in double_runs)
14 changes: 13 additions & 1 deletion tests/test_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,19 @@ def test_double_runs():
p1 = Primer("ATATCGAACACACACACA")
double_runs = p1.double_runs
print(double_runs)
true_answer = {'GT': 0, 'CA': 5, 'AT': 2, 'TA': 0, 'GC': 0, 'GA': 0, 'AG': 0, 'TG': 0, 'CG': 0, 'TC': 0, 'AC': 5, 'CT': 0}
true_answer = {
'GT': 0,
'CA': 5,
'AT': 2,
'TA': 0,
'GC': 0,
'GA': 0,
'AG': 0,
'TG': 0,
'CG': 0,
'TC': 0,
'AC': 5,
'CT': 0}
assert len(true_answer) == len(double_runs) and all(double_runs[pair] == true_answer[pair] for pair in double_runs)


Expand Down
8 changes: 8 additions & 0 deletions tests/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@ def test_str():
oprimer_2 = Primer("ATCGC")
oprimer_concat = oprimer_1 + oprimer_2
assert str(oprimer_1) + str(oprimer_2) == oprimer_concat.sequence


def test_iter():
oprimer_1 = Primer("ATCG")
sequence = ""
for base in oprimer_1:
sequence += base
assert oprimer_1.sequence == sequence
2 changes: 1 addition & 1 deletion tests/test_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def test_sequence():
oprimer = Primer("ATCGATCGATCGATCGAT")
assert oprimer.sequence== "ATCGATCGATCGATCGAT"
assert oprimer.sequence == "ATCGATCGATCGATCGAT"


def test_name():
Expand Down