Spaces:
Sleeping
Sleeping
Create biological_context_language_orchestrator.py
Browse files
biological_context_language_orchestrator.py
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from databaseengine import DatabaseEngine
|
| 2 |
+
from fetch_fasta import FetchFasta_Uniprot
|
| 3 |
+
from mutant_constructor import ConstructMutant_using_MutationString
|
| 4 |
+
from get_3d_structure import Get3D_Structure_of_Protein
|
| 5 |
+
from domain_detector import Domain_Detector
|
| 6 |
+
from epitope_prediction import Predict_Epitopes
|
| 7 |
+
import requests
|
| 8 |
+
|
| 9 |
+
de=DatabaseEngine()
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class Biological_Context_Orchestrator():
|
| 14 |
+
|
| 15 |
+
def __init__(self):
|
| 16 |
+
self.version="1.0"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def BCL_Orchestrator(self,project_id,id,planned_experiments,target):
|
| 20 |
+
|
| 21 |
+
"""
|
| 22 |
+
Property of xForce
|
| 23 |
+
Proprietary Implementation ,Locked Down Access
|
| 24 |
+
Author : JUNAID BASHIR
|
| 25 |
+
"""
|
| 26 |
+
experiments=planned_experiments.get("experiments")
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
if not isinstance(experiments, list):
|
| 30 |
+
print("Error: 'planned_experiments' must be a list of dictionaries.")
|
| 31 |
+
return
|
| 32 |
+
|
| 33 |
+
Experiment_to_Implementation_Mapper={
|
| 34 |
+
|
| 35 |
+
#"retrieve_uniprot_sequence":FetchFasta_Uniprot,
|
| 36 |
+
"introduce_point_mutation":ConstructMutant_using_MutationString,
|
| 37 |
+
"domain_determination":Domain_Detector,
|
| 38 |
+
"predict_structure":Get3D_Structure_of_Protein,
|
| 39 |
+
"analyze_epitopes":Predict_Epitopes
|
| 40 |
+
|
| 41 |
+
}
|
| 42 |
+
EXPERIMENT_OUTPUTS={}
|
| 43 |
+
|
| 44 |
+
if "retrieve_uniprot_sequence" not in EXPERIMENT_OUTPUTS:
|
| 45 |
+
|
| 46 |
+
EXPERIMENT_OUTPUTS["retrieve_uniprot_sequence"]=FetchFasta_Uniprot(gene_symbol=target)
|
| 47 |
+
de.Insert_IE({
|
| 48 |
+
|
| 49 |
+
"bcl_id":id,
|
| 50 |
+
"operation":"retrieve_uniprot_sequence",
|
| 51 |
+
"output":EXPERIMENT_OUTPUTS["retrieve_uniprot_sequence"]
|
| 52 |
+
|
| 53 |
+
})
|
| 54 |
+
|
| 55 |
+
for experiment_object in experiments:
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
#if experiment_object["operation"] in Experiment_to_Implementation_Mapper and experiment_object["operation"] == "retrieve_uniprot_sequence":
|
| 59 |
+
|
| 60 |
+
#EXPERIMENT_TO_RUN="retrieve_uniprot_sequence"
|
| 61 |
+
#EXPERIMENT_OUTPUTS["retrieve_uniprot_sequence"]=FetchFasta_Uniprot(gene_symbol=target)
|
| 62 |
+
|
| 63 |
+
#''' Database Ops Begin '''
|
| 64 |
+
|
| 65 |
+
#de.Update_Status(id)
|
| 66 |
+
|
| 67 |
+
'''
|
| 68 |
+
de.Insert_IE({
|
| 69 |
+
|
| 70 |
+
"bcl_id":id,
|
| 71 |
+
"operation":"retrieve_uniprot_sequence",
|
| 72 |
+
"output":EXPERIMENT_OUTPUTS["retrieve_uniprot_sequence"]
|
| 73 |
+
|
| 74 |
+
})
|
| 75 |
+
'''
|
| 76 |
+
#'''Database Ops End'''
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
if experiment_object["operation"] in Experiment_to_Implementation_Mapper:
|
| 80 |
+
|
| 81 |
+
EXPERIMENT_TO_RUN=Experiment_to_Implementation_Mapper[experiment_object["operation"]]
|
| 82 |
+
|
| 83 |
+
'''checking for the presence of depends key'''
|
| 84 |
+
|
| 85 |
+
if "depends" in experiment_object and experiment_object["depends"]=="None":
|
| 86 |
+
pass
|
| 87 |
+
|
| 88 |
+
if "depends" in experiment_object and experiment_object["depends"] in EXPERIMENT_OUTPUTS:
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
if "wildtype_sequence" in experiment_object["biological_inputs"]:
|
| 92 |
+
|
| 93 |
+
experiment_object["biological_inputs"]["wildtype_sequence"]=EXPERIMENT_OUTPUTS[experiment_object["depends"]]
|
| 94 |
+
|
| 95 |
+
if "sequence_for_structure" in experiment_object["biological_inputs"]:
|
| 96 |
+
experiment_object["biological_inputs"]["filename"]=id
|
| 97 |
+
|
| 98 |
+
else:
|
| 99 |
+
keys=list( experiment_object["biological_inputs"].keys())
|
| 100 |
+
if keys:
|
| 101 |
+
experiment_object["biological_inputs"][keys[0]]=EXPERIMENT_OUTPUTS[experiment_object["depends"]]
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
EXPERIMENT_OUTPUTS[experiment_object["operation"]]=EXPERIMENT_TO_RUN(**experiment_object["biological_inputs"])
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
''' checking if predict structure operation is executed then replacing its url output with raw content'''
|
| 109 |
+
if "predict_structure" in EXPERIMENT_OUTPUTS:
|
| 110 |
+
predict_structure_output=EXPERIMENT_OUTPUTS["predict_structure"]["sequence_domain_section"]
|
| 111 |
+
|
| 112 |
+
if predict_structure_output.startswith("https"):
|
| 113 |
+
predict_structure_request=requests.get(predict_structure_output)
|
| 114 |
+
if predict_structure_request.status_code == 200:
|
| 115 |
+
pdb_content = predict_structure_request.text
|
| 116 |
+
EXPERIMENT_OUTPUTS["predict_structure"]=pdb_content
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
''' Database Ops Begin '''
|
| 120 |
+
#de.Update_Status(id)
|
| 121 |
+
|
| 122 |
+
de.Insert_IE({
|
| 123 |
+
|
| 124 |
+
"bcl_id":id,
|
| 125 |
+
"operation":experiment_object["operation"],
|
| 126 |
+
"output":EXPERIMENT_OUTPUTS[experiment_object["operation"]]
|
| 127 |
+
|
| 128 |
+
})
|
| 129 |
+
''' Database Ops End '''
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
#return EXPERIMENT_OUTPUTS
|
| 133 |
+
#if not EXPERIMENT_OUTPUTS:
|
| 134 |
+
de.Update_Status(project_id,id)
|
| 135 |
+
|
| 136 |
+
keys=list(EXPERIMENT_OUTPUTS.keys())
|
| 137 |
+
payload={
|
| 138 |
+
"bcl_id":id,
|
| 139 |
+
"executed_operations":keys,
|
| 140 |
+
"executed_operations_results":EXPERIMENT_OUTPUTS
|
| 141 |
+
}
|
| 142 |
+
de.InsertMemory(data=payload)
|