mirror of
https://github.com/Lukas0025/POC1-SIMD-DNA.git
synced 2025-04-04 06:41:35 +01:00
POC 1 functional version
This commit is contained in:
parent
8a6e1220f9
commit
04dd00aee0
8
codes/counter.asm
Normal file
8
codes/counter.asm
Normal file
@ -0,0 +1,8 @@
|
||||
define:
|
||||
0 [ABC][DE]
|
||||
1 [AB][CDE]
|
||||
|
||||
data:
|
||||
0001111
|
||||
|
||||
instructions:
|
@ -9,6 +9,6 @@ instructions:
|
||||
{D*E*A*F*} # mark 01
|
||||
{D*E*A*B*C*G*} # mark 11
|
||||
{DEABCG} # remove mark 11
|
||||
{A*B*C*} {D*E*} # write 0
|
||||
{A*B*C*}{D*E*} # write 0
|
||||
{DEAF} # remove mark 01
|
||||
{B*C*D*E*} # write 1
|
@ -1,3 +1,3 @@
|
||||
import ascii as ascii
|
||||
import molecule as molecule
|
||||
import register as register
|
||||
from . import ascii as ascii
|
||||
from . import molecule as molecule
|
||||
from . import register as register
|
@ -3,8 +3,8 @@
|
||||
# @autor Lukáš Plevač <xpleva07@vutbr.cz>
|
||||
# @brief defines function from print structions in ASCII reprezentation
|
||||
|
||||
from molecule import isComplementary
|
||||
from molecule import nothing
|
||||
from .molecule import isComplementary
|
||||
from .molecule import nothing
|
||||
|
||||
##
|
||||
# Return number of bases to bind with main chain 0
|
||||
|
@ -1,9 +1,100 @@
|
||||
import re
|
||||
from . import molecule
|
||||
|
||||
class Assembly:
|
||||
def __init__(self, asm):
|
||||
# remove whitespaces
|
||||
asm = asm.strip()
|
||||
# load macros from file
|
||||
self.macros = self.parseMacros(asm)
|
||||
self.data = self.parseData(asm)
|
||||
self.ins = self.parseInstructions(asm)
|
||||
|
||||
def getMacros(self):
|
||||
return self.macros
|
||||
|
||||
def getData(self):
|
||||
return self.data
|
||||
|
||||
def getInstructions(self):
|
||||
return self.ins
|
||||
|
||||
def parseMacros(self, asm):
|
||||
|
||||
asm = asm.splitlines()
|
||||
|
||||
is_in = False
|
||||
macros = []
|
||||
for ins in asm:
|
||||
ins = re.sub("\s+" , " ", ins.strip()) # remove whitespaces
|
||||
ins = ins.split("#")[0] # remove comments
|
||||
|
||||
if "define:" in ins:
|
||||
is_in = True
|
||||
elif ":" in ins and is_in:
|
||||
break
|
||||
elif is_in:
|
||||
name = ins.split(" ")[0]
|
||||
|
||||
if not name.isspace() and len(name) > 0:
|
||||
val = ins.split(" ")[1]
|
||||
|
||||
macros.append([name, val])
|
||||
|
||||
return macros
|
||||
|
||||
def useMacros(self, text):
|
||||
for macro in self.macros:
|
||||
text = text.replace(macro[0], macro[1])
|
||||
|
||||
return text
|
||||
|
||||
def parseData(self, asm):
|
||||
asm = asm.splitlines()
|
||||
|
||||
is_in = False
|
||||
datas = []
|
||||
for ins in asm:
|
||||
ins = re.sub("\s+" , " ", ins.strip()) # remove whitespaces
|
||||
ins = ins.split("#")[0] # remove comments
|
||||
|
||||
if "data:" in ins:
|
||||
is_in = True
|
||||
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]
|
||||
|
||||
if not reg.isspace() and len(reg) > 0:
|
||||
datas.append(molecule.parse(self.useMacros(reg)))
|
||||
|
||||
return datas
|
||||
|
||||
def parseInstructions(self, asm):
|
||||
asm = asm.splitlines()
|
||||
|
||||
is_in = False
|
||||
gins = []
|
||||
for ins in asm:
|
||||
ins = re.sub("\s+" , " ", ins.strip()) # remove whitespaces
|
||||
ins = ins.split("#")[0] # remove comments
|
||||
|
||||
if "instructions:" in ins:
|
||||
is_in = True
|
||||
elif ":" in ins and is_in:
|
||||
break
|
||||
elif is_in:
|
||||
DNAins = ins.split(" ")
|
||||
|
||||
DNAInsArray = []
|
||||
for DNAin in DNAins:
|
||||
if not DNAin.isspace() and len(DNAin) > 0:
|
||||
DNAInsArray.append(molecule.parse(self.useMacros(DNAin)))
|
||||
|
||||
if len(DNAInsArray) > 0:
|
||||
gins.append(DNAInsArray)
|
||||
|
||||
return gins
|
||||
|
||||
|
@ -3,8 +3,8 @@
|
||||
# @autor Lukáš Plevač <xpleva07@vutbr.cz>
|
||||
# @brief implments REGISTER from SIMD|DNA
|
||||
|
||||
import molecule
|
||||
import ascii
|
||||
from . import molecule
|
||||
from . import ascii
|
||||
|
||||
class Register:
|
||||
##
|
||||
@ -125,11 +125,11 @@ class Register:
|
||||
for pos in range(len(self.mol)):
|
||||
if molecule.isComplementary(self.mol.getBase(chainI, pos), self.mol.getBase(0, pos)) and self.mol.bindedCountAt(pos) == 1: # binde minimaly once
|
||||
bindScore += 1
|
||||
else:
|
||||
bindScore = 0
|
||||
finalBindScore = max(finalBindScore, bindScore)
|
||||
elif not molecule.isComplementary(self.mol.getBase(chainI, pos), self.mol.getBase(0, pos)):
|
||||
finalBindScore = max(bindScore, finalBindScore)
|
||||
bindScore = 0
|
||||
|
||||
if finalBindScore < 2:
|
||||
if max(bindScore, finalBindScore) < 2:
|
||||
self.mol.removeChain(chainI)
|
||||
done = False
|
||||
break
|
||||
|
76
src/main.py
Normal file → Executable file
76
src/main.py
Normal file → Executable file
@ -1,48 +1,72 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from SIMDDNA.register import Register
|
||||
from SIMDDNA import molecule
|
||||
from SIMDDNA.assembly import Assembly
|
||||
from SIMDDNA.ascii import showMolecule
|
||||
import argparse
|
||||
|
||||
asm = Assembly(
|
||||
"""
|
||||
define:
|
||||
0 [ABC][DE]
|
||||
1 {A}[BCDE]
|
||||
parser = argparse.ArgumentParser(description='DNA|SIMD python simulator POC1')
|
||||
parser.add_argument('assembly')
|
||||
parser.add_argument('-s', '--spaceing', default=" ", help='space sentense between ascii char of DNA strands')
|
||||
parser.add_argument('-v', '--verbose', help='show simulation step by step not only final', action='store_true', default=False)
|
||||
parser.add_argument('-d', '--decode', help='use macros to decode final result', action='store_true', default=False)
|
||||
|
||||
data:
|
||||
1001111010
|
||||
args = parser.parse_args()
|
||||
|
||||
instructions:
|
||||
{D*E*A*F*} # mark 01
|
||||
{D*E*A*B*C*G*} # mark 11
|
||||
{DEABCG} # remove mark 11
|
||||
{A*B*C*} {D*E*} # write 0
|
||||
{DEAF} # remove mark 01
|
||||
{B*C*D*E*} # write 1
|
||||
"""
|
||||
)
|
||||
# Open a file
|
||||
file = open(args.assembly, mode='r')
|
||||
asm = file.read()
|
||||
file.close()
|
||||
|
||||
asm = Assembly(asm)
|
||||
|
||||
print("=================================")
|
||||
print("| Inital state |")
|
||||
print("=================================")
|
||||
print("\n")
|
||||
print("")
|
||||
|
||||
regs = []
|
||||
|
||||
for data in asm.getData():
|
||||
regs.append(Register(molecule.parse(data)))
|
||||
regs[-1].asciiShow(spaceing = " ")
|
||||
regs.append(Register(data))
|
||||
regs[-1].asciiShow(spaceing = args.spaceing)
|
||||
|
||||
|
||||
iId = 0
|
||||
for ins in asm.getInstructions():
|
||||
print("=================================")
|
||||
print(f"| Instruction {iId} |")
|
||||
print("=================================")
|
||||
print("\n")
|
||||
|
||||
if args.verbose:
|
||||
print("")
|
||||
print("=================================")
|
||||
print(f"| Instruction {iId} |")
|
||||
print("=================================")
|
||||
print()
|
||||
|
||||
for insc in ins:
|
||||
insc.rawPrint()
|
||||
|
||||
print()
|
||||
print("Registers")
|
||||
print("--------------------------------")
|
||||
print()
|
||||
|
||||
for reg in regs:
|
||||
reg.instruction(ins)
|
||||
reg.asciiShow(spaceing = " ")
|
||||
|
||||
if args.verbose:
|
||||
reg.asciiShow(spaceing = args.spaceing)
|
||||
|
||||
iId += 1
|
||||
iId += 1
|
||||
|
||||
print("")
|
||||
print("=================================")
|
||||
print("| FINAL state |")
|
||||
print("=================================")
|
||||
print("")
|
||||
|
||||
for reg in regs:
|
||||
reg.asciiShow(spaceing = args.spaceing)
|
||||
|
||||
if args.decode:
|
||||
# todo: implement it
|
||||
pass
|
Loading…
x
Reference in New Issue
Block a user