Skip to content

Commit

Permalink
GC Clamp Property Added to Primer Class (#32)
Browse files Browse the repository at this point in the history
* add : `gc_clamp` property added to `Primer`.

* test : tests added.

* log : changes logged.

* update : README.md updated.

* fix : document comments applied.

* update : `gc_clamp` tests updated.

* update : comments applied.

* test : new test added.
  • Loading branch information
sadrasabouri authored Dec 27, 2024
1 parent 09cfd0a commit d5ed809
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
### Added
- `equality` operator overload
- `gc_clamp` property
## [0.1] - 2024-11-27
### Added
- `MeltingTemperature` enum
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
>>> primer1.gc_content
0.5217391304347826
```
#### GC clamp
```pycon
>>> primer1.gc_clamp
1
```
#### Melting temperature
```pycon
>>> primer1.melting_temperature()
Expand Down
13 changes: 13 additions & 0 deletions opr/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,16 @@ def basic_melting_temperature_calc(sequence):
else:
melting_temperature = 64.9 + 41 * ((g_count + c_count - 16.4) / (a_count + t_count + g_count + c_count))
return melting_temperature


def gc_clamp_calc(sequence):
"""
Calculate GC clamp.
:param sequence: primer sequence
:type sequence: str
:return: number of guanine (G) or cytosine (C) bases in the last 5 bases of the primer
"""
if len(sequence) < 5:
return 0
return sequence[-5:].count('G') + sequence[-5:].count('C')
22 changes: 21 additions & 1 deletion opr/primer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .params import DNA_COMPLEMENT_MAP
from .params import PRIMER_ADDITION_ERROR, PRIMER_MULTIPLICATION_ERROR
from .params import PRIMER_MELTING_TEMPERATURE_NOT_IMPLEMENTED_ERROR
from .functions import molecular_weight_calc, basic_melting_temperature_calc
from .functions import molecular_weight_calc, basic_melting_temperature_calc, gc_clamp_calc


class MeltingTemperature(Enum):
Expand Down Expand Up @@ -40,6 +40,7 @@ def __init__(self, sequence):
self._sequence = Primer.validate_primer(sequence)
self._molecular_weight = None
self._gc_content = None
self._gc_clamp = None
self._melting_temperature = {
MeltingTemperature.BASIC: None,
MeltingTemperature.SALT_ADJUSTED: None,
Expand Down Expand Up @@ -197,6 +198,25 @@ def gc_content(self, _):
def gc_content(self, _):
raise OPRBaseError(PRIMER_NOT_REMOVABLE_ATTRIBUTE_ERROR)

@property
def gc_clamp(self):
"""
Calculate GC clamp of the primer.
:return: GC clamp of the primer
"""
if self._gc_clamp is None:
self._gc_clamp = gc_clamp_calc(self._sequence)
return self._gc_clamp

@gc_clamp.setter
def gc_clamp(self, _):
raise OPRBaseError(PRIMER_READ_ONLY_ATTRIBUTE_ERROR)

@gc_clamp.deleter
def gc_clamp(self, _):
raise OPRBaseError(PRIMER_NOT_REMOVABLE_ATTRIBUTE_ERROR)

def melting_temperature(self, method=MeltingTemperature.BASIC):
"""
Calculate(if needed) the melting temperature.
Expand Down
12 changes: 12 additions & 0 deletions tests/test_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ def test_gc_content_3(): #Reference: https://jamiemcgowan.ie/bioinf/gc_content.h
oprimer = Primer("ATTTTTT")
assert oprimer.gc_content == 0

def test_gc_clamp_1(): #Reference: https://www.bioinformatics.org/sms2/pcr_primer_stats.html
oprimer = Primer("ATCGATCGATCGATCGGTCG")
assert oprimer.gc_clamp == 4

def test_gc_clamp_2(): #Reference: https://www.bioinformatics.org/sms2/pcr_primer_stats.html
oprimer = Primer("ATCG")
assert oprimer.gc_clamp == 0

def test_gc_clamp_3(): #Reference: https://www.bioinformatics.org/sms2/pcr_primer_stats.html
oprimer = Primer("ACTTA")
assert oprimer.gc_clamp == 1

def test_melt_temp_1(): #Reference: http://biotools.nubic.northwestern.edu/OligoCalc.html
oprimer = Primer("ATCGATCGATCGATCGATCG")
basic_melt_temp = oprimer.melting_temperature(MeltingTemperature.BASIC)
Expand Down

0 comments on commit d5ed809

Please sign in to comment.