Skip to content

Commit

Permalink
test : tests added.
Browse files Browse the repository at this point in the history
  • Loading branch information
sadrasabouri committed Dec 2, 2024
1 parent db83813 commit c343f9d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
13 changes: 9 additions & 4 deletions opr/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .params import A_WEIGHT, T_WEIGHT, C_WEIGHT, G_WEIGHT
from .params import ANHYDROUS_MOLECULAR_WEIGHT_CONSTANT
from .params import CHEMICAL_FORMULA_FORMAT, CHEMICAL_FORMULA_FORMAT_SHORT
from .params import CHEMICAL_FORMULA_BASES, CHEMICAL_FORMULA_WATER
from .params import CHEMICAL_FORMULA_BASES, CHEMICAL_FORMULA_WATER, CHEMICAL_FORMULA_PHOSPHODIESTER


def molecular_weight_calc(sequence):
Expand Down Expand Up @@ -67,14 +67,19 @@ def chemical_formula_calc(sequence):
'C': sequence.count('C'),
'G': sequence.count('G'),
}
n = len(sequence)

carbon_count = sum([count_mapping[x] * y['C'] for x, y in CHEMICAL_FORMULA_BASES.items()])
hydrogen_count = sum([count_mapping[x] * y['H'] for x, y in CHEMICAL_FORMULA_BASES.items()])
hydrogen_count -= (len(sequence) - 1) * CHEMICAL_FORMULA_WATER['H']
nitrogen_count = sum([count_mapping[x] * y['N'] for x, y in CHEMICAL_FORMULA_BASES.items()])
oxygen_count = sum([count_mapping[x] * y['O'] for x, y in CHEMICAL_FORMULA_BASES.items()])
oxygen_count += (len(sequence) - 1) * CHEMICAL_FORMULA_WATER['O']
# A water is removed from the formula for each phosphodiester bond
hydrogen_count -= (n - 1) * CHEMICAL_FORMULA_WATER['H']
hydrogen_count += (n - 1) * CHEMICAL_FORMULA_PHOSPHODIESTER['H']
oxygen_count -= (n - 1) * CHEMICAL_FORMULA_WATER['O']
oxygen_count += (n - 1) * CHEMICAL_FORMULA_PHOSPHODIESTER['O']
phosphor_count = (n - 1) * CHEMICAL_FORMULA_PHOSPHODIESTER['P']

if len(sequence) == 1:
return CHEMICAL_FORMULA_FORMAT_SHORT.format(carbon_count, hydrogen_count, nitrogen_count, oxygen_count)
return CHEMICAL_FORMULA_FORMAT.format(carbon_count, hydrogen_count, nitrogen_count, oxygen_count, len(sequence) - 1)
return CHEMICAL_FORMULA_FORMAT.format(carbon_count, hydrogen_count, nitrogen_count, oxygen_count, phosphor_count)
26 changes: 8 additions & 18 deletions opr/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,23 @@
DNA_COMPLEMENT_MAP = {"A": "T", "C": "G", "G": "C", "T": "A"}
CHEMICAL_FORMULA_BASES = {
'A': {
'C': 10,
'H': 13,
'N': 5,
'O': 3,
'C': 10, 'H': 15, 'N': 5, 'O': 4,
},
'T': {
'C': 10,
'H': 14,
'N': 2,
'O': 5,
'C': 10, 'H': 16, 'N': 2, 'O': 6,
},
'C': {
'C': 9,
'H': 13,
'N': 3,
'O': 4,
'C': 9, 'H': 15, 'N': 3, 'O': 5,
},
'G': {
'C': 10,
'H': 13,
'N': 5,
'O': 4,
'C': 10, 'H': 15, 'N': 5, 'O': 5,
},
}
CHEMICAL_FORMULA_WATER = {
'H': 2,
'O': 1,
'H': 2, 'O': 1,
}
CHEMICAL_FORMULA_PHOSPHODIESTER = {
'H': 3, 'O': 4, 'P': 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}"
Expand Down
6 changes: 6 additions & 0 deletions tests/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def test_complement_3(): #Reference: https://www.qiagen.com/us/applications/enzy
oprimer.complement(inplace=True)
assert oprimer.sequence == "TAGCCGATTTAGCCGATT"


def test_chemical_formula(): #Reference: https://atdbio.com/tools/oligo-calculator
oprimer = Primer("ATCGGCTAAATCGGCTAA")
assert oprimer.chemical_formula == "C176H221N70O104P17"


def test_length():
oprimer = Primer("ATCGGCTAAATCGGCTAA")
assert len(oprimer) == 18
Expand Down

0 comments on commit c343f9d

Please sign in to comment.