Skip to content

Commit

Permalink
feedback applied
Browse files Browse the repository at this point in the history
  • Loading branch information
AHReccese committed Oct 8, 2024
1 parent 7c83ab8 commit 75d74d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
28 changes: 10 additions & 18 deletions opr/primer.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,21 @@ def gc_content(self, _):
def gc_content(self, _):
raise OPRBaseError(PRIMER_NOT_REMOVABLE_ATTRIBUTE_ERROR)

@property
def melting_temperature(self):
def melting_temperature(self, method=MeltingTemperature.BASIC):
"""
Calculate(if needed) the melting temperature.
:return: approximated melting temperatures
:param method: requested calculation mode for melting temperature
:type method: MeltingTemperature
:return: approximated melting temperature
"""
if self._melting_temperature[method] != None:
return self._melting_temperature[method]
a_count = self._sequence.count('A')
t_count = self._sequence.count('T')
c_count = self._sequence.count('C')
g_count = self._sequence.count('G')
warn(PRIMER_SUPPORTED_MELTING_TEMPERATURE_CALCULATIONS)
if self._melting_temperature[MeltingTemperature.BASIC] is None:
if method == MeltingTemperature.BASIC:
if len(self) <= 13:
# Tm= (wA+xT) * 2 + (yG+zC) * 4
# where w,x,y,z are the number of the bases A,T,G,C in the sequence,
Expand All @@ -222,16 +224,6 @@ def melting_temperature(self):
# (CHSL Press)
self._melting_temperature[MeltingTemperature.BASIC] = 64.9 + 41 * \
((g_count + c_count - 16.4) / (a_count + t_count + g_count + c_count))
return self._melting_temperature

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

@melting_temperature.deleter
def melting_temperature(self, _):
self.melting_temperature = {
MeltingTemperature.BASIC: None,
MeltingTemperature.SALT_ADJUSTED: None,
MeltingTemperature.NEAREST_NEIGHBOR: None,
}
else:
raise(NotImplementedError(PRIMER_SUPPORTED_MELTING_TEMPERATURE_CALCULATIONS))
return self._melting_temperature[method]
7 changes: 4 additions & 3 deletions tests/test_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ def test_gc_content_3(): #Reference: https://jamiemcgowan.ie/bioinf/gc_content.h

def test_melt_temp_1(): #Reference: http://biotools.nubic.northwestern.edu/OligoCalc.html
oprimer = Primer("ATCGATCGATCGATCGATCG")
assert round(oprimer.melting_temperature[MeltingTemperature.BASIC],1) == 51.8
basic_melt_temp = oprimer.melting_temperature(MeltingTemperature.BASIC)
assert round(basic_melt_temp,1) == 51.8

def test_melt_temp_2(): #Reference: http://biotools.nubic.northwestern.edu/OligoCalc.html
oprimer = Primer("ATCG")
print(oprimer.melting_temperature)
assert round(oprimer.melting_temperature[MeltingTemperature.BASIC],1) == 12
basic_melt_temp = oprimer.melting_temperature(method=MeltingTemperature.BASIC)
assert round(basic_melt_temp,1) == 12

0 comments on commit 75d74d2

Please sign in to comment.