Skip to content

Commit

Permalink
Minor edits (#21)
Browse files Browse the repository at this point in the history
* fix : primer_sequence --> sequence

* doc : CHANGELOG.md updated

* fix : new_seq --> new_sequence
  • Loading branch information
sepandhaghighi authored Oct 10, 2024
1 parent db961d0 commit 022d614
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed
## [0.1] - 2024-06-05
### Added
- MeltingTemperature enum
- `MeltingTemperature` enum
- Basic melting temperature calculation
- `addition` and `multipication` operators overload
- `len` magic overload
Expand Down
38 changes: 19 additions & 19 deletions opr/primer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ class Primer:
>>> oprimer.molecular_weight
"""

def __init__(self, primer_sequence):
def __init__(self, sequence):
"""
Initialize the Primer instance.
:param primer_sequence: primer nucleotides sequence
:type primer_sequence: str
:param sequence: primer nucleotides sequence
:type sequence: str
:return: an instance of the Primer class
"""
self._sequence = Primer.validate_primer(primer_sequence)
self._sequence = Primer.validate_primer(sequence)
self._molecular_weight = None
self._gc_content = None
self._melting_temperature = {
Expand Down Expand Up @@ -86,11 +86,11 @@ def reverse(self, inplace=False):
:type inplace: bool
:return: new Primer object or None
"""
new_seq = self._sequence[::-1]
new_sequence = self._sequence[::-1]
if inplace:
self._sequence = new_seq
self._sequence = new_sequence
else:
return Primer(primer_sequence=new_seq)
return Primer(sequence=new_sequence)

def complement(self, inplace=False):
"""
Expand All @@ -100,33 +100,33 @@ def complement(self, inplace=False):
:type inplace: bool
:return: new Primer object or None
"""
new_seq = ""
new_sequence = ""
for item in self._sequence:
new_seq += DNA_COMPLEMENT_MAP[item]
new_sequence += DNA_COMPLEMENT_MAP[item]
if inplace:
self._sequence = new_seq
self._sequence = new_sequence
else:
return Primer(primer_sequence=new_seq)
return Primer(sequence=new_sequence)

@staticmethod
def validate_primer(primer_sequence):
def validate_primer(sequence):
"""
Validate the given primer sequence.
:param primer_sequence: primer nucleotides sequence
:type primer_sequence: any
:param sequence: primer nucleotides sequence
:type sequence: any
:return: an uppercased primer sequence
"""
if not isinstance(primer_sequence, str):
if not isinstance(sequence, str):
raise OPRBaseError(PRIMER_SEQUENCE_TYPE_ERROR)
primer_sequence = primer_sequence.upper()
sequence = sequence.upper()

if len(primer_sequence) < PRIMER_LOWER_LENGTH or len(primer_sequence) > PRIMER_HIGHEST_LENGTH:
if len(sequence) < PRIMER_LOWER_LENGTH or len(sequence) > PRIMER_HIGHEST_LENGTH:
warn(PRIMER_SEQUENCE_LENGTH_WARNING, RuntimeWarning)

if not all(base in VALID_BASES for base in primer_sequence):
if not all(base in VALID_BASES for base in sequence):
raise OPRBaseError(PRIMER_SEQUENCE_VALID_BASES_ERROR)
return primer_sequence
return sequence

@property
def sequence(self):
Expand Down

0 comments on commit 022d614

Please sign in to comment.