-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc_weight_json.py
More file actions
29 lines (25 loc) · 1.33 KB
/
Copy pathcalc_weight_json.py
File metadata and controls
29 lines (25 loc) · 1.33 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
#Calcular peso de molesculas
import jsonFileHandler
#Recuperamos el valor del json
data = jsonFileHandler.readJsonFile('files/insulin.json')
if data != "" :
bInsulin = data['molecules']['bInsulin']
aInsulin = data['molecules']['aInsulin']
insulin = bInsulin + aInsulin
molecularWeightInsulinActual = data['molecularWeightInsulinActual']
print('bInsulin: ' + bInsulin)
print('aInsulin: ' + aInsulin)
print('molecularWeightInsulinActual: ' + str(molecularWeightInsulinActual))
# Calculating the molecular weight of insulin
# Getting a list of the amino acid (AA) weights
aaWeights = data['weights']
# Count the number of each amino acids
aaCountInsulin = ({x: float(insulin.upper().count(x)) for x in ['A','C','D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'P', 'Q', 'R','S', 'T','V', 'W', 'Y']})
# Multiply the count by the weights
molecularWeightInsulin = sum({x: (aaCountInsulin[x]*aaWeights[x]) for x in
['A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'P', 'Q', 'R','S', 'T', 'V', 'W', 'Y']}.values())
print("The rough molecular weight of insulin: " +
str(molecularWeightInsulin))
print("Percent error: " + str(((molecularWeightInsulin - molecularWeightInsulinActual)/molecularWeightInsulinActual)*100))
else:
print("Error. Exiting program")