-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTools.py
More file actions
223 lines (180 loc) · 6.71 KB
/
Tools.py
File metadata and controls
223 lines (180 loc) · 6.71 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import pickle
class unit_function:
"""dissolves floating and unit of inputs"""
def mol(self):
"""dissolves molarity unit"""
unit = ""
if self >= 1:
unit = "M"
molarity = self
if 1 > self >= 1e-3:
molarity = self * 1e3
unit = "mM"
if 1e-3 > self >= 1e-6:
molarity = self * 1e6
unit = "uM"
if 1e-6 > self >= 1e-9:
molarity = self * 1e9
unit = "nM"
else:
pass
return molarity, unit
def mass(self):
unit = ""
if self >= 1:
unit = "g"
mass = round(self, 2)
if 1 > self >= 1e-3:
unit = "mg"
mass = int(round(self * 1e3, 0))
return mass, unit
def vol(self):
unit = ""
if self >= 1:
unit = "L"
volume = round(self, 2)
if 1 > self >= 1e-3:
unit = "mL"
volume = round(self * 1e3, 2)
if 1e-3 > self >= 1e-6:
unit = "uL"
volume = int(round(self * 1e6, 0))
return volume, unit
class Buf:
"""Gives the buffer the storage, load and save with pickle"""
def __init__(self, name, use, ingredients, molarity, unit, info):
self.name = name
self.use = use
self.ingredients = ingredients
self.molarity = molarity
self.unit = unit
self.info = info
@staticmethod
def load():
"""Loads the storage. one output as list of buffer class objects"""
with open("Buffer.pickle", "rb") as f:
buffer = pickle.load(f)
return buffer
def save(self):
"""Saves the bufferlist to a pickle file. self = name input"""
with open("Buffer.pickle", "wb") as handle:
pickle.dump(self, handle, protocol=pickle.HIGHEST_PROTOCOL)
def dic_to_list(self):
BufferList = []
for i, j in enumerate(self):
self[i]["name"] = Buf(self[i]["name"], self[i]["use"], self[i]["ingredients"], self[i]["molarity"], self[i]["unit"], self[i]["info"])
BufferList.append(self[i]["name"])
return BufferList
def list_to_dic(self):
"""converts list of chem typ objects to a list of dict"""
BufferDic = []
for i, j in enumerate(self):
BufferDic.append(self[i].__dict__)
return BufferDic
class Chemical:
"""Gives the chemicals the storage, load and save with pickle"""
def __init__(self, name, mass, aggregation, density):
self.name = name
self.mass = mass
self.aggregation = aggregation
self.density = density
def dic_to_list(self):
"""converts a dic in chem class format to list of class type objects"""
ChemList = []
for i, j in enumerate(self):
self[i]["name"] = Chemical(self[i]["name"], self[i]["mass"], self[i]["aggregation"], self[i]["density"])
ChemList.append(self[i]["name"])
return ChemList
def list_to_dic(self):
"""converts list of chem typ objects to a list of dict"""
ChemDic = []
for i, j in enumerate(self):
ChemDic.append(self[i].__dict__)
return ChemDic
@staticmethod
def load():
"""Loads the storage. one output as list of buffer class objects"""
with open("Chemicals.pickle", "rb") as f:
Chem = pickle.load(f)
return Chem
def save(self):
"""Saves the bufferlist to a pickle file. self = name input"""
with open(f"Chemicals.pickle", "wb") as handle:
pickle.dump(self, handle, protocol=pickle.HIGHEST_PROTOCOL)
def extract_unit(unit, amount):
"""extracts float and unit out data set. input Unit, amount. (Mol and %)"""
if unit == "M":
Amount = amount
unit_data = "M"
elif unit == "mM":
Amount = float(amount) * 1e-3
unit_data = "M"
elif unit == "uM":
Amount = float(amount) * 1e-6
unit_data = "M"
elif unit == "%":
Amount = amount
unit_data = "%"
return Amount, unit_data
#-------------------- datatables
columns_recipe = [
{"id": "number", "name": "Number"},
{"id": "chem", "name": "Chemical"},
{"id": "amount", "name": "Amount"},
]
#-------------------- units
options_units_volume = [
{"label": "L", "value" : 1},
{"label": "mL", "value" : 1e-3},
{"label": "uL", "value" : 1e-6},
]
#-------------------- options menus
options_buffer = [
{"label": "Protein Buffer", "value": "Protein"},
{"label": "DNA Buffer", "value": "DNA"},
{"label": "HPLC Buffer", "value": "HPLC"},
{"label": "Experiment Buffer", "value": "EXP"},
{"label": "Other Buffer", "value": "Other"},
]
#--------------- infos
info_buffer = [
{"value": "Protein", "info": "Buffer that are used to run in vitro experiments with proteins"},
{"value": "DNA", "info": "Buffer to work with DNA"},
{"value": "HPLC", "info": "HPLC eluents etc."},
{"value": "EXP", "info": "Buffers for experiments eg. Lysis etc"},
{"value": "Other", "info": "Buffer that do not contain to anything else"},
]
#--------------- Editing
Col_Buffer = [
{"id": "name", 'name': 'Chemical'},
{"id": "use", 'name': 'Use'},
{"id": "ingredients", 'name': 'Ingredients'},
{"id": "molarity", 'name': 'Molarity'},
{"id": "unit", 'name': 'unit'},
{"id": "info", 'name': 'Information'},
]
Col_Chem = [
{"id": "name", 'name': 'Chemical'},
{"id": "mass", 'name': 'Molecular Mass'},
{"id": "aggregation", 'name': 'Aggregation', "presentation": "dropdown"},
{"id": "density", 'name': 'Density'},
]
Data_empty_recipe = [
{"name": "", "amount": "", "unit": ""}
]
Data_empty = [
{"name": "", "amount": "", "unit": "", "Molecular Mass": "", "aggregation": "", "density": ""}
]
Col_recipe = [
{"id": "name", 'name': 'Chemical'},
{"id": "amount", 'name': 'Concentration'},
{"id": "unit", 'name': 'Unit', "presentation": "dropdown"},
]
Col = [
{"id": "name", 'name': 'Chemical'},
{"id": "amount", 'name': 'Concentration'},
{"id": "unit", 'name': 'Unit', "presentation": "dropdown"},
{"id": "mass", 'name': 'Molecular Mass'},
{"id": "aggregation", 'name': 'Aggregation', "presentation": "dropdown"},
{"id": "density", 'name': 'Density'},
]