Skip to content

Commit

Permalink
new from_dsiupac method
Browse files Browse the repository at this point in the history
  • Loading branch information
BjornFJohansson committed Nov 12, 2024
1 parent 43e3173 commit fd5f16b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/pydna/dseq.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,30 @@ def from_string(
obj._data = bytes(dna, encoding="ASCII")
return obj

@classmethod
def from_dsiupac(cls, dsdna: str, *args, **kwargs):
obj = cls.__new__(cls) # Does not call __init__
obj.circular = False
ds_to_ss_dct = {"P": "G", "E": "A", "X": "T", "I": "C"}
ds_to_ss_dct.update(dict((k.lower(), v.lower()) for k, v in ds_to_ss_dct.items()))
ds_to_ss_table = str.maketrans(ds_to_ss_dct)
keys = "".join(ds_to_ss_dct.keys())
if ovhg := len(dsdna) - len(dsdna.lstrip(keys)):
watson = dsdna.rstrip("FQJZfqjz")
crick = _rc(dsdna).rstrip("FQJZfqjz")
elif ovhg := -len(dsdna) + len(dsdna.lstrip("FQJZfqjz")):
watson = dsdna.lstrip("FQJZfqjz")
crick = _rc(dsdna).lstrip("FQJZfqjz")
obj.watson = _pretty_str(watson.translate(ds_to_ss_table))
obj.crick = _pretty_str(crick.translate(ds_to_ss_table))
obj.pos = 0
obj.ovhg = -ovhg
obj.length = max(len(watson) + max(0, ovhg), len(crick) + max(0, -ovhg))
wb = bytes(watson, encoding="ASCII")
cb = bytes(crick, encoding="ASCII")
obj._data = _rc(cb[-max(0, ovhg) or len(cb) :]) + wb + _rc(cb[: max(0, len(cb) - ovhg - len(wb))])
return obj

@classmethod
def from_representation(cls, dsdna: str, *args, **kwargs):
obj = cls.__new__(cls) # Does not call __init__
Expand Down

0 comments on commit fd5f16b

Please sign in to comment.