mirror of
https://github.com/Lukas0025/POC1-SIMD-DNA.git
synced 2025-04-05 07:11:32 +01:00
Added support for decode
This commit is contained in:
parent
dba8571de6
commit
2bedb2a82f
@ -60,15 +60,10 @@ class Assembly:
|
||||
elif ":" in ins and is_in:
|
||||
break
|
||||
elif is_in:
|
||||
reg = ins.split(" ")
|
||||
|
||||
if len(reg) > 1:
|
||||
print("WARNING: ASM parsing data molecule with space. All after space is ignored!")
|
||||
|
||||
reg = reg[0]
|
||||
reg = self.useMacros(ins).replace(" ", "")
|
||||
|
||||
if not reg.isspace() and len(reg) > 0:
|
||||
datas.append(molecule.parse(self.useMacros(reg)))
|
||||
datas.append(molecule.parse(reg))
|
||||
|
||||
return datas
|
||||
|
||||
@ -97,4 +92,14 @@ class Assembly:
|
||||
gins.append(DNAInsArray)
|
||||
|
||||
return gins
|
||||
|
||||
def decode(self, reg):
|
||||
mol = molecule.encode(reg.mol)
|
||||
|
||||
for macro in self.macros:
|
||||
mol = mol.replace(macro[1], macro[0])
|
||||
|
||||
return mol
|
||||
|
||||
|
||||
|
||||
|
@ -326,4 +326,42 @@ def parse(notationStr):
|
||||
|
||||
newMolecule.endPad()
|
||||
|
||||
return newMolecule
|
||||
return newMolecule
|
||||
|
||||
##
|
||||
# Encode molecule to ASCII reprezentation
|
||||
# @param mol moleculte to encode
|
||||
# @retun STR of ascii reprezentation
|
||||
# @todo support for overhangs
|
||||
#
|
||||
def encode(mol):
|
||||
outstr = ""
|
||||
lastClose = ""
|
||||
lastChain = -1
|
||||
lastBounded = None
|
||||
|
||||
for basePos in range(len(mol)):
|
||||
bounded = False
|
||||
for chainID in range(1, mol.chainsCount()):
|
||||
if isComplementary(mol.getBase(chainID, basePos), mol.getBase(0, basePos)):
|
||||
if not lastBounded or lastBounded is None or lastChain != chainID:
|
||||
lastBounded = True
|
||||
lastChain = chainID
|
||||
outstr += lastClose + "["
|
||||
lastClose = "]"
|
||||
|
||||
bounded = True
|
||||
break
|
||||
|
||||
if (not bounded and lastBounded) or lastBounded is None:
|
||||
lastBounded = False
|
||||
outstr += lastClose + "{"
|
||||
lastClose = "}"
|
||||
|
||||
if mol.getBase(0, basePos) == nothing:
|
||||
break
|
||||
|
||||
outstr += mol.getBase(0, basePos)
|
||||
|
||||
return (outstr + lastClose).replace("{}", "").replace("[]", "")
|
||||
|
@ -69,4 +69,9 @@ for reg in regs:
|
||||
|
||||
if args.decode:
|
||||
# todo: implement it
|
||||
pass
|
||||
print()
|
||||
print("Decoded")
|
||||
print("--------------------------------")
|
||||
print()
|
||||
for reg in regs:
|
||||
print(asm.decode(reg))
|
Loading…
x
Reference in New Issue
Block a user