Newer
Older
# Python imports
import json
import logging
import sys
# Django imports
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
# Models imports
from api.models.pipedream_model import GPhLPipedream
from api.models.report_model import Report
from api.models.dpstep_model import DPStep
from api.models.ligandsfitting_model import LigandsFitting
from api.models.reductionscaling_model import ReductionScaling
from api.models.refinement_cycles_model import RefinementCycles
from api.models.post_refinement_cycles_model import PostRefinementCycles
from api.models.ligand_model import Ligand
from api.models.ligand_statistics_model import LigandStatistics
from api.models.ligand_solutions_model import LigandSolutions
from api.models.reference_model import Reference
from api.models.structurefactors_model import StructureFactors
from api.models.mtzfile_model import MTZ
# Activate logger
logger=logging.getLogger('dataproc')
@csrf_exempt
def storeProcInput(request):
"""
Parse JSON data and call store functions for each model
"""
if request.method=='POST':
json_data=json.loads(request.body)
# json_data_ligand=json_data['ligandfitting']['ligands']['1']
# json_data_rc=json_data['refinement']['Cycles']
# json_data_prc=json_data['ligandfitting']['ligands']['1']['postrefinement']['cycles']
# json_data_solutions=json_data['ligandfitting']['ligands']['1']['solutions']
# json_data_statistics=json_data['ligandfitting']['ligands']['1']['validationstatistics']['ligandstatistics']
# json_data_reference=json_data['dataprocessing']['referencedata']['cell']
# ligand=storeParseLigand(json_data_ligand, report)
# storeParseRC(json_data_rc, report)
# storeParsePRC(json_data_prc, ligand)
# storeParseLigandSolutions(json_data_solutions, ligand)
# storeParseLigandStatistics(json_data_statistics, ligand)
return JsonResponse({"STATUS": "INPUT SUCCESSFULLY REGISTERED"})
except :
return JsonResponse({"STATUS":"ERROR OCCURRED"}, safe=False)
@csrf_exempt
def storeParseReport(data):
"""
Creates nodes for each report with relative properties
"""
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
GPhL_pipedream=data['GPhL_pipedream']
autoprocscaling=data['dataprocessing']['processingdata']['AutoProcscaling']
autoprocscalingstatistics=data['dataprocessing']['processingdata']['AutoProcScalingStatistics']
autoproc=data['dataprocessing']['processingdata']['AutoProc']
molprobity=data['ligandfitting']['ligands']['1']['validationstatistics']['molprobity']
report=Report(command=GPhL_pipedream['command'],
jsonversion=GPhL_pipedream['jsonversion'],
runby=GPhL_pipedream['runby'],
runfrom=GPhL_pipedream['runfrom'],
jobid=GPhL_pipedream['jobid'],
gphlpipedream_output=GPhL_pipedream['output'],
version=GPhL_pipedream['version'],
molprobitypercentile=molprobity['molprobitypercentile'],
ramaoutlierpercent=molprobity['ramaoutlierpercent'],
cbetadeviations=molprobity['cbetadeviations'],
ramafavoredpercent=molprobity['ramafavoredpercent'],
poorrotamers=molprobity['poorrotamers'],
rmsbonds=molprobity['rmsbonds'],
rmsangles=molprobity['rmsangles'],
clashpercentile=molprobity['clashpercentile'],
poorrotamerspercent=molprobity['poorrotamerspercent'],
clashscore=molprobity['clashscore'],
ramafavored=molprobity['ramafavored'],
molprobityscore=molprobity['molprobityscore'],
ramaoutliers=molprobity['ramaoutliers'],
recordTimeStamp=autoprocscaling['recordTimeStamp'],
resolutionEllipsoidAxis13=autoprocscaling['resolutionEllipsoidAxis13'],
resolutionEllipsoidAxis33=autoprocscaling['resolutionEllipsoidAxis33'],
resolutionEllipsoidAxis23=autoprocscaling['resolutionEllipsoidAxis23'],
resolutionEllipsoidValue2=autoprocscaling['resolutionEllipsoidValue2'],
resolutionEllipsoidAxis21=autoprocscaling['resolutionEllipsoidAxis21'],
resolutionEllipsoidAxis31=autoprocscaling['resolutionEllipsoidAxis31'],
resolutionEllipsoidAxis22=autoprocscaling['resolutionEllipsoidAxis22'],
resolutionEllipsoidAxis32=autoprocscaling['resolutionEllipsoidAxis32'],
resolutionEllipsoidValue3=autoprocscaling['resolutionEllipsoidValue3'],
resolutionEllipsoidAxis12=autoprocscaling['resolutionEllipsoidAxis12'],
resolutionEllipsoidValue1=autoprocscaling['resolutionEllipsoidValue1'],
resolutionEllipsoidAxis11=autoprocscaling['resolutionEllipsoidAxis11'],
innerShell_multiplicity=autoprocscalingstatistics['innerShell']['multiplicity'],
innerShell_resolutionLimitLow=autoprocscalingstatistics['innerShell']['resolutionLimitLow'],
innerShell_rMeasWithinIPlusIMinus=autoprocscalingstatistics['innerShell']['rMeasWithinIPlusIMinus'],
innerShell_DanoOverSigDano=autoprocscalingstatistics['innerShell']['DanoOverSigDano'],
innerShell_completenessSpherical=autoprocscalingstatistics['innerShell']['completenessSpherical'],
innerShell_nTotalUniqueObservations=autoprocscalingstatistics['innerShell']['nTotalUniqueObservations'],
innerShell_rMerge=autoprocscalingstatistics['innerShell']['rMerge'],
innerShell_rPimWithinIPlusIMinus=autoprocscalingstatistics['innerShell']['rPimWithinIPlusIMinus'],
innerShell_anomalousCompletenessEllipsoidal=autoprocscalingstatistics['innerShell']['anomalousCompletenessEllipsoidal'],
innerShell_nTotalObservations=autoprocscalingstatistics['innerShell']['nTotalObservations'],
innerShell_completenessEllipsoidal=autoprocscalingstatistics['innerShell']['completenessEllipsoidal'],
innerShell_anomalousCompleteness=autoprocscalingstatistics['innerShell']['anomalousCompleteness'],
innerShell_anomalousMultiplicity=autoprocscalingstatistics['innerShell']['anomalousMultiplicity'],
innerShell_resolutionLimitHigh=autoprocscalingstatistics['innerShell']['resolutionLimitHigh'],
innerShell_completeness=autoprocscalingstatistics['innerShell']['completeness'],
innerShell_ccHalf=autoprocscalingstatistics['innerShell']['ccHalf'],
innerShell_rPimAllIPlusIMinus=autoprocscalingstatistics['innerShell']['rPimAllIPlusIMinus'],
innerShell_meanIOverSigI=autoprocscalingstatistics['innerShell']['meanIOverSigI'],
innerShell_anomalousCompletenessSpherical=autoprocscalingstatistics['innerShell']['anomalousCompletenessSpherical'],
innerShell_ccAnomalous=autoprocscalingstatistics['innerShell']['ccAnomalous'],
innerShell_rMeasAllIPlusIMinus=autoprocscalingstatistics['innerShell']['rMeasAllIPlusIMinus'],
outerShell_multiplicity=autoprocscalingstatistics['outerShell']['multiplicity'],
outerShell_resolutionLimitLow=autoprocscalingstatistics['outerShell']['resolutionLimitLow'],
outerShell_rMeasWithinIPlusIMinus=autoprocscalingstatistics['outerShell']['rMeasWithinIPlusIMinus'],
outerShell_DanoOverSigDano=autoprocscalingstatistics['outerShell']['DanoOverSigDano'],
outerShell_completenessSpherical=autoprocscalingstatistics['outerShell']['completenessSpherical'],
outerShell_nTotalUniqueObservations=autoprocscalingstatistics['outerShell']['nTotalUniqueObservations'],
outerShell_rMerge=autoprocscalingstatistics['outerShell']['rMerge'],
outerShell_rPimWithinIPlusIMinus=autoprocscalingstatistics['outerShell']['rPimWithinIPlusIMinus'],
outerShell_anomalousCompletenessEllipsoidal=autoprocscalingstatistics['outerShell']['anomalousCompletenessEllipsoidal'],
outerShell_nTotalObservations=autoprocscalingstatistics['outerShell']['nTotalObservations'],
outerShell_completenessEllipsoidal=autoprocscalingstatistics['outerShell']['completenessEllipsoidal'],
outerShell_anomalousCompleteness=autoprocscalingstatistics['outerShell']['anomalousCompleteness'],
outerShell_anomalousMultiplicity=autoprocscalingstatistics['outerShell']['anomalousMultiplicity'],
outerShell_resolutionLimitHigh=autoprocscalingstatistics['outerShell']['resolutionLimitHigh'],
outerShell_completeness=autoprocscalingstatistics['outerShell']['completeness'],
outerShell_ccHalf=autoprocscalingstatistics['outerShell']['ccHalf'],
outerShell_rPimAllIPlusIMinus=autoprocscalingstatistics['outerShell']['rPimAllIPlusIMinus'],
outerShell_meanIOverSigI=autoprocscalingstatistics['outerShell']['meanIOverSigI'],
outerShell_anomalousCompletenessSpherical=autoprocscalingstatistics['outerShell']['anomalousCompletenessSpherical'],
outerShell_ccAnomalous=autoprocscalingstatistics['outerShell']['ccAnomalous'],
outerShell_rMeasAllIPlusIMinus=autoprocscalingstatistics['outerShell']['rMeasAllIPlusIMinus'],
overall_multiplicity=autoprocscalingstatistics['overall']['multiplicity'],
overall_resolutionLimitLow=autoprocscalingstatistics['overall']['resolutionLimitLow'],
overall_rMeasWithinIPlusIMinus=autoprocscalingstatistics['overall']['rMeasWithinIPlusIMinus'],
overall_DanoOverSigDano=autoprocscalingstatistics['overall']['DanoOverSigDano'],
overall_completenessSpherical=autoprocscalingstatistics['overall']['completenessSpherical'],
overall_nTotalUniqueObservations=autoprocscalingstatistics['overall']['nTotalUniqueObservations'],
overall_rMerge=autoprocscalingstatistics['overall']['rMerge'],
overall_rPimWithinIPlusIMinus=autoprocscalingstatistics['overall']['rPimWithinIPlusIMinus'],
overall_anomalousCompletenessEllipsoidal=autoprocscalingstatistics['overall']['anomalousCompletenessEllipsoidal'],
overall_nTotalObservations=autoprocscalingstatistics['overall']['nTotalObservations'],
overall_completenessEllipsoidal=autoprocscalingstatistics['overall']['completenessEllipsoidal'],
overall_anomalousCompleteness=autoprocscalingstatistics['overall']['anomalousCompleteness'],
overall_anomalousMultiplicity=autoprocscalingstatistics['overall']['anomalousMultiplicity'],
overall_resolutionLimitHigh=autoprocscalingstatistics['overall']['resolutionLimitHigh'],
overall_completeness=autoprocscalingstatistics['overall']['completeness'],
overall_ccHalf=autoprocscalingstatistics['overall']['ccHalf'],
overall_rPimAllIPlusIMinus=autoprocscalingstatistics['overall']['rPimAllIPlusIMinus'],
overall_meanIOverSigI=autoprocscalingstatistics['overall']['meanIOverSigI'],
overall_anomalousCompletenessSpherical=autoprocscalingstatistics['overall']['anomalousCompletenessSpherical'],
overall_ccAnomalous=autoprocscalingstatistics['overall']['ccAnomalous'],
overall_rMeasAllIPlusIMinus=autoprocscalingstatistics['overall']['rMeasAllIPlusIMinus'],
refinedCell_beta=autoproc['refinedCell_beta'],
refinedCell_b=autoproc['refinedCell_b'],
wavelength=autoproc['wavelength'],
refinedCell_a=autoproc['refinedCell_a'],
refinedCell_alpha=autoproc['refinedCell_alpha'],
spaceGroup=autoproc['spaceGroup'],
refinedCell_c=autoproc['refinedCell_c'],
refinedCell_gamma=autoproc['refinedCell_gamma'])
except:
print(sys.exc_info()[0])
return ({"STATUS": "ERROR OCCURRED WHILE REGISTERING REPORT"})
@csrf_exempt
def storeParseStructureFactors(data):
"""
Creates nodes for
"""
try:
structurefactors=StructureFactors(
# uuid=data['uuid'],
# datatype=data['datatype'],
# processingtype=data['processingtype'],
gamma=data['gamma'],
a=data['a'],
alpha=data['alpha'],
c=data['c'])
# rsf_source=data['rsf_source'],
# rsf_filesize=data['rsf_filesize'],
# rsf_filepath=data['rsf_filepath'])
structurefactors.save()
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# structurefactors2=structurefactors.serialize
# connectStructureFactorsRef(structurefactors2['structurefactors_node_properties']['uuid'], ref['ref_node_properties']['uuid'])
return ({"STATUS": "STRUCTURE FACTORS REGISTERED"})
except:
print(sys.exc_info()[0])
return ({"STATUS": "ERROR OCCURRED WHILE REGISTERING RC"})
@csrf_exempt
def storeParseMTZ(data, structurefactors):
"""
Creates nodes for
"""
try:
mtz=MTZ(datatype=data['datatype'])
mtz.save()
mtz2=mtz.serialize
# connectStructureFactorsMTZ(structurefactors['structurefactors_node_properties']['uuid'], mtz2['mtz_node_properties']['uuid'])
return ({"STATUS": "MTZ DATATYPE REGISTERED"})
except:
print(sys.exc_info()[0])
return ({"STATUS": "ERROR OCCURRED WHILE REGISTERING RC"})
@csrf_exempt
def storeParseRC(data, report):
"""
Creates nodes for each RC (Refinement Cycle) with relative properties
"""
try:
for input_rc in data:
rc=RefinementCycles(cycle_number=input_rc['cycle_number'],
WilsonB=input_rc['WilsonB'],
Rfree=input_rc['Rfree'],
MeanB=input_rc['MeanB'],
rc_type=input_rc['type'],
step=input_rc['step'],
RMSbonds=input_rc['RMSbonds'],
RMSangles=input_rc['RMSangles'],
R=input_rc['R'])
# WatersPresent=input_rc['WatersPresent'])
rc.save()
rc2=rc.serialize
connectReportRC(report['report_node_properties']['jobid'], rc2['rc_node_properties']['uuid'])
return ({"STATUS": "RC REGISTERED"})
except:
print(sys.exc_info()[0])
return ({"STATUS": "ERROR OCCURRED WHILE REGISTERING RC"})
@csrf_exempt
def storeParseLigand(data, report):
"""
Creates nodes for each ligand with relative properties
"""
try:
ligand=Ligand(ligand_id=data['id'])
ligand.save()
ligand2=ligand.serialize
connectReportLigand(report['report_node_properties']['jobid'], ligand2['ligand_node_properties']['uuid'])
return ligand2
except:
print(sys.exc_info()[0])
return ({"STATUS": "ERROR OCCURRED WHILE REGISTERING LIGAND"})
@csrf_exempt
def storeParsePRC(data, ligand):
"""
Creates nodes for each PRC (Post-Refinement Cycle) with relative properties
"""
try:
for input_prc in data:
prc=PostRefinementCycles(cycle_number=input_prc['cycle_number'],
WilsonB=input_prc['WilsonB'],
Rfree=input_prc['Rfree'],
MeanB=input_prc['MeanB'],
prc_type=input_prc['type'],
step=input_prc['step'],
RMSbonds=input_prc['RMSbonds'],
RMSangles=input_prc['RMSangles'],
R=input_prc['R'])
# WatersPresent=input_prc['WatersPresent']
prc.save()
prc2=prc.serialize
connectLigandPRC(prc2['prc_node_properties']['uuid'], ligand['ligand_node_properties']['uuid'])
return ({"STATUS": "PRC REGISTERED"})
except:
print(sys.exc_info()[0])
return ({"STATUS": "ERROR OCCURRED WHILE REGISTERING PRC"})
@csrf_exempt
def storeParseLigandSolutions(data, ligand):
"""
Creates nodes for each ligand solutions with relative properties
"""
try:
for input_solutions in data:
solutions=LigandSolutions(closecontacts=input_solutions['closecontacts'],
chain=input_solutions['chain'],
contactscore=input_solutions['contactscore'],
ligandstrain=input_solutions['ligandstrain'],
poorfit=input_solutions['poorfit'],
output=input_solutions['output'],
correlationcoefficient=input_solutions['correlationcoefficient'],
rhofitscore=input_solutions['rhofitscore'],
solution_number=input_solutions['solution_number'])
# WatersPresent=input_rc['WatersPresent'])
solutions.save()
solutions2=solutions.serialize
connectLigandLigandSolutions(ligand['ligand_node_properties']['ligand_id'], solutions2['ligand_solutions_node_properties']['uuid'])
return ({"STATUS": "LIGANDS SOLUTIONS REGISTERED"})
except:
print(sys.exc_info()[0])
return ({"STATUS": "ERROR OCCURRED WHILE REGISTERING LIGANDS SOLUTIONS"})
@csrf_exempt
def storeParseLigandStatistics(data, ligand):
"""
Creates nodes for each ligand solutions with relative properties
"""
try:
for input_statistics in data:
statistics=LigandStatistics(ligandomin=input_statistics['ligandomin'],
mogulzbond=input_statistics['mogulzbond'],
ligandbmin=input_statistics['ligandbmin'],
mogulring=input_statistics['mogulring'],
moguldihe=input_statistics['moguldihe'],
ligandbavg=input_statistics['ligandbavg'],
mogulangl=input_statistics['mogulangl'],
mogulbond=input_statistics['mogulbond'],
ligandbmax=input_statistics['ligandbmax'],
ligandid=input_statistics['ligandid'],
ligandomax=input_statistics['ligandomax'],
ligandcc=input_statistics['ligandcc'],
mogulzangl=input_statistics['mogulzangl'])
statistics.save()
statistics2=statistics.serialize
connectLigandLigandStatistics(ligand['ligand_node_properties']['ligand_id'], statistics2['ligand_statistics_node_properties']['uuid'])
return ({"STATUS": "LIGANDS SOLUTIONS REGISTERED"})
except:
print(sys.exc_info()[0])
return ({"STATUS": "ERROR OCCURRED WHILE REGISTERING LIGANDS SOLUTIONS"})
@csrf_exempt
def connectReportLigand(data1, data2):
"""
Create a relationship between a report and a ligand
"""
try:
report=Report.nodes.get(jobid=data1)
ligand=Ligand.nodes.get(uuid=data2)
return JsonResponse({"STATUS": report.has_ligand.connect(ligand)}, safe=False)
except:
return JsonResponse({"STATUS": "ERROR OCCURRED WHILE CONNECTING REPORT TO LIGAND"}, safe=False)
@csrf_exempt
def connectReportRC(data1, data2):
"""
Create a relationship between a report and a rc
"""
try:
report=Report.nodes.get(jobid=data1)
rc=RefinementCycles.nodes.get(uuid=data2)
return JsonResponse({"STATUS": report.has_refinement_cycles.connect(rc)}, safe=False)
except:
return JsonResponse({"STATUS": "ERROR OCCURRED WHILE CONNECTING REPORT TO RCs"}, safe=False)
@csrf_exempt
def connectLigandLigandSolutions(data1, data2):
"""
Create a relationship between a ligand and relative solutions
"""
try:
ligand=Ligand.nodes.get(ligand_id=data1)
solutions=LigandSolutions.nodes.get(uuid=data2)
return JsonResponse({"STATUS": ligand.has_solutions.connect(solutions)}, safe=False)
except:
return JsonResponse({"STATUS": "ERROR OCCURRED WHILE CONNECTING LIGAND TO SOLUTIONS"}, safe=False)
@csrf_exempt
def connectLigandLigandStatistics(data1, data2):
"""
Create a relationship between a ligand and relative statistics
"""
try:
ligand=Ligand.nodes.get(ligand_id=data1)
statistics=LigandStatistics.nodes.get(uuid=data2)
return JsonResponse({"STATUS": ligand.has_statistics.connect(statistics)}, safe=False)
except:
return JsonResponse({"STATUS": "ERROR OCCURRED WHILE CONNECTING LIGAND TO PRCs"}, safe=False)
@csrf_exempt
def connectLigandPRC(data1, data2):
"""
Create a relationship between a report and a prc
"""
try:
ligand=Ligand.nodes.get(uuid=data2)
prc=PostRefinementCycles.nodes.get(uuid=data1)
return JsonResponse({"STATUS": ligand.has_postrefinement_cycles.connect(prc)}, safe=False)
except:
return JsonResponse({"STATUS": "ERROR OCCURRED WHILE CONNECTING LIGAND TO PRCs"}, safe=False)
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
@csrf_exempt
def connectStructureFactorsRef(data1, data2):
"""
Create a relationship between a SF (Structure factors) and Reference node.
"""
try:
structurefactors=StructureFactors.nodes.get(uuid=data1)
ref=Reference.nodes.get(uuid=data2)
return JsonResponse({"STATUS": structurefactors.labelled.connect(ref)}, safe=False)
except:
return JsonResponse({"STATUS": "ERROR OCCURRED WHILE CONNECTING STRUCTURE FACTORS TO REFERENCE"}, safe=False)
@csrf_exempt
def connectStructureFactorsMTZ(data1, data2):
"""
Create a relationship between a SF (Structure factors) and MTZ node.
"""
try:
structurefactors=StructureFactors.nodes.get(uuid=data1)
mtz=MTZ.nodes.get(uuid=data2)
return JsonResponse({"STATUS": structurefactors.is_mtz.connect(mtz)}, safe=False)
except:
return JsonResponse({"STATUS": "ERROR OCCURRED WHILE CONNECTING STRUCTURE FACTORS TO MTZ"}, safe=False)