Skip to content

Commit

Permalink
Primer.name Added (#43)
Browse files Browse the repository at this point in the history
* add : `DEFAULT_PRIMER_NAME` parameter added.

* add : `name` property added to `Primer` class.

* tests : tests added for properties.

* log : changelog updated.

* update : changelog updated.
  • Loading branch information
sadrasabouri authored Jan 16, 2025
1 parent 64de7fe commit adce824
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- `name` property
### Changed
- Test system modified
## [0.2] - 2025-01-09
### Added
- `__eq__` overload
Expand Down
2 changes: 2 additions & 0 deletions opr/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
G_WEIGHT = 329.21
ANHYDROUS_MOLECULAR_WEIGHT_CONSTANT = 61.96

DEFAULT_PRIMER_NAME = "unknown"

PRIMER_SEQUENCE_TYPE_ERROR = "Primer sequence should be a string variable."
PRIMER_SEQUENCE_LENGTH_WARNING = "The recommended range for primer length is between 18 and 30."
PRIMER_SEQUENCE_VALID_BASES_ERROR = "Primer sequence should only contain the nucleotide bases A, T, C, and G."
Expand Down
16 changes: 14 additions & 2 deletions opr/primer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from enum import Enum
from warnings import warn
from .errors import OPRBaseError
from .params import VALID_BASES
from .params import DEFAULT_PRIMER_NAME, VALID_BASES
from .params import PRIMER_SEQUENCE_TYPE_ERROR, PRIMER_SEQUENCE_LENGTH_WARNING, PRIMER_SEQUENCE_VALID_BASES_ERROR, PRIMER_SEQUENCE_VALID_GC_CONTENT_RANGE_WARNING
from .params import PRIMER_LOWER_LENGTH, PRIMER_HIGHEST_LENGTH, PRIMER_LOWEST_GC_RANGE, PRIMER_HIGHEST_GC_RANGE
from .params import DNA_COMPLEMENT_MAP
Expand All @@ -28,15 +28,18 @@ class Primer:
>>> oprimer.molecular_weight
"""

def __init__(self, sequence):
def __init__(self, sequence, name=DEFAULT_PRIMER_NAME):
"""
Initialize the Primer instance.
:param sequence: primer nucleotides sequence
:type sequence: str
:param name: primer name
:type name: str
:return: an instance of the Primer class
"""
self._sequence = Primer.validate_primer(sequence)
self._name = name
self._molecular_weight = None
self._gc_content = None
self._gc_clamp = None
Expand Down Expand Up @@ -156,6 +159,15 @@ def sequence(self):
"""
return self._sequence

@property
def name(self):
"""
Return the primer name.
:return: primer name
"""
return self._name

@property
def molecular_weight(self):
"""
Expand Down
13 changes: 13 additions & 0 deletions tests/test_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from opr import Primer

TEST_CASE_NAME = "Property tests"


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


def test_name():
oprimer = Primer("ATCGATCGATCGATCGAT", "primer1")
assert oprimer.name == "primer1"

0 comments on commit adce824

Please sign in to comment.