Skip to content

Commit

Permalink
add : chemical_formula attribute added.
Browse files Browse the repository at this point in the history
  • Loading branch information
sadrasabouri committed Dec 2, 2024
1 parent 85ffee6 commit db83813
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
32 changes: 32 additions & 0 deletions opr/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,38 @@
OPR_VERSION = "0.1"
VALID_BASES = set('ATCG')
DNA_COMPLEMENT_MAP = {"A": "T", "C": "G", "G": "C", "T": "A"}
CHEMICAL_FORMULA_BASES = {
'A': {
'C': 10,
'H': 13,
'N': 5,
'O': 3,
},
'T': {
'C': 10,
'H': 14,
'N': 2,
'O': 5,
},
'C': {
'C': 9,
'H': 13,
'N': 3,
'O': 4,
},
'G': {
'C': 10,
'H': 13,
'N': 5,
'O': 4,
},
}
CHEMICAL_FORMULA_WATER = {
'H': 2,
'O': 1,
}
CHEMICAL_FORMULA_FORMAT = "C{0}H{1}N{2}O{3}P{4}"
CHEMICAL_FORMULA_FORMAT_SHORT = "C{0}H{1}N{2}O{3}"

PRIMER_LOWER_LENGTH = 18
PRIMER_HIGHEST_LENGTH = 30
Expand Down
23 changes: 22 additions & 1 deletion opr/primer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .params import DNA_COMPLEMENT_MAP

from .functions import molecular_weight_calc, basic_melting_temperature_calc
from .functions import gc_content_calc
from .functions import gc_content_calc, chemical_formula_calc


class MeltingTemperature(Enum):
Expand Down Expand Up @@ -49,6 +49,7 @@ def __init__(self, sequence):
MeltingTemperature.SALT_ADJUSTED: None,
MeltingTemperature.NEAREST_NEIGHBOR: None,
}
self._chemical_formula = None

def __len__(self):
"""
Expand Down Expand Up @@ -200,6 +201,26 @@ def gc_content(self, _):
@gc_content.deleter
def gc_content(self, _):
raise OPRBaseError(PRIMER_NOT_REMOVABLE_ATTRIBUTE_ERROR)

@property
def chemical_formula(self):
"""
Calculate the chemical formula.
:return: chemical formula
"""
if self._chemical_formula is not None:
return self._chemical_formula
self._chemical_formula = chemical_formula_calc(self._sequence)
return self._chemical_formula

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

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

def melting_temperature(self, method=MeltingTemperature.BASIC):
"""
Expand Down

0 comments on commit db83813

Please sign in to comment.