From adce824ad898ed92d15a779b854e971ddee36735 Mon Sep 17 00:00:00 2001 From: Sadra Sabouri <43045767+sadrasabouri@users.noreply.github.com> Date: Thu, 16 Jan 2025 02:17:14 -0800 Subject: [PATCH] `Primer.name` Added (#43) * add : `DEFAULT_PRIMER_NAME` parameter added. * add : `name` property added to `Primer` class. * tests : tests added for properties. * log : changelog updated. * update : changelog updated. --- CHANGELOG.md | 4 ++++ opr/params.py | 2 ++ opr/primer.py | 16 ++++++++++++++-- tests/test_property.py | 13 +++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 tests/test_property.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 916d635..71689ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/opr/params.py b/opr/params.py index fc808df..8c945fa 100644 --- a/opr/params.py +++ b/opr/params.py @@ -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." diff --git a/opr/primer.py b/opr/primer.py index 8d0ccbf..bdb2c53 100644 --- a/opr/primer.py +++ b/opr/primer.py @@ -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 @@ -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 @@ -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): """ diff --git a/tests/test_property.py b/tests/test_property.py new file mode 100644 index 0000000..58029c8 --- /dev/null +++ b/tests/test_property.py @@ -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"