-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptBuilder.py
More file actions
executable file
·106 lines (90 loc) · 3.68 KB
/
ScriptBuilder.py
File metadata and controls
executable file
·106 lines (90 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python
import json
import sys
import csv
# Python function
def runScriptBuilder(filename, protocolFilePath):
# Reading parameter file
with open(filename, 'r') as f:
lines = f.read()
lines = lines.split("\n\n")
tips_raw = str(lines[0].split("\n"))
tuberack_raw = str(lines[1].split("\n"))
instr_raw = str(lines[2].split("\n"))
plates_raw = str(lines[3].split("\n"))
screens_raw = lines[4].split('\n')
if screens_raw[-1] == '':
screens_raw = str(screens_raw[:-1])
else:
screens_raw = str(screens_raw)
# Reading compound library
with open('compLibrary.txt', 'r') as l:
reader = csv.reader(l, delimiter="\t")
lines = [entry for line in reader for entry in line]
labels = str(lines[0::3])
types = str(lines[1::3])
stockConc = str(lines[2::3])
# Writing the script from the template
template = open("template.py", "r")
with open(protocolFilePath, 'w') as main:
main.write('tips_raw = ' + tips_raw + "\n")
main.write('tuberack_raw = ' + tuberack_raw + "\n")
main.write('instr_raw = ' + instr_raw + "\n")
main.write('plates_raw = ' + plates_raw + "\n")
main.write('screens_raw = ' + screens_raw + "\n\n")
main.write('labels = ' + labels + '\n')
main.write('types = ' + types + '\n')
main.write('stockConc = ' + stockConc + '\n\n')
main.write(template.read())
template.close()
def BuildWithMetadata(filename, protocolFilePath,protocolname,description,author):
# Reading parameter file
with open(filename, 'r') as f:
lines = f.read()
lines = lines.split("\n\n")
tips_raw = str(lines[0].split("\n"))
tuberack_raw = str(lines[1].split("\n"))
instr_raw = str(lines[2].split("\n"))
plates_raw = str(lines[3].split("\n"))
screens_raw = lines[4].split('\n')
if screens_raw[-1] == '':
screens_raw = str(screens_raw[:-1])
else:
screens_raw = str(screens_raw)
# Reading compound library
with open('compLibrary.txt', 'r') as l:
reader = csv.reader(l, delimiter="\t")
lines = [entry for line in reader for entry in line]
labels = str(lines[0::3])
types = str(lines[1::3])
stockConc = str(lines[2::3])
# Writing the script from the template
template = open("template.py", "r")
with open(protocolFilePath, 'w') as main:
main.write(template.readline())
main.write("metadata = ")
main.write(json.dumps({"apiLevel":"2.9",'protocolName':protocolname,'description':description,'author':author}) + "\n")
main.write('tips_raw = ' + tips_raw + "\n")
main.write('tuberack_raw = ' + tuberack_raw + "\n")
main.write('instr_raw = ' + instr_raw + "\n")
main.write('plates_raw = ' + plates_raw + "\n")
main.write('screens_raw = ' + screens_raw + "\n\n")
main.write('labels = ' + labels + '\n')
main.write('types = ' + types + '\n')
main.write('stockConc = ' + stockConc + '\n\n')
for _ in range(9):
next(template)
main.write(template.read())
template.close()
# bash command-line support
if __name__ == "__main__":
# calling without arguments triggers default file paths
if len(sys.argv) == 1:
filename = "params.txt"
protocolpath = "protocol.py"
elif len(sys.argv) == 3:
filename = sys.argv[1]
protocolpath = sys.argv[2]
else:
raise Exception("Wrong number of arguments! Expected a parameter file path and a protocol file path.")
runScriptBuilder(filename, protocolpath)