Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug manual experiment creation #188

Merged
merged 3 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions escalate/core/templates/core/create_experiment.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,7 @@ <h6 class="pt-3 pl-3">Reaction Parameters for {{ selected_exp_template.descripti
</div>
<br>
{% endfor %}

{{ robot_file_upload_form|crispy }}
<button class="btn btn-outline-primary" type="submit" name="robot_upload" value="create_exp">Create Experiment</button>


<div class="treeview-animated border mx-3 my-4">
<h6 class="pt-3 pl-3">Vessel Selection for {{ selected_exp_template.description }}</h6>
<hr>
Expand Down Expand Up @@ -192,17 +188,13 @@ <h6 class="pt-3 pl-3">Reaction Parameters for {{ selected_exp_template.descripti
{% endfor %}
</ul>
</div>
<input type="hidden" id="automated" name="automated" value="{{ automated }}">
<div class="text-right">
<button class="btn btn-outline-primary" type="submit" name="create_exp" value="create_exp">Create Experiment</button>
{% endif %}

</div>
{{ robot_file_upload_form|crispy }}
<button class="btn btn-outline-primary" type="submit" name="robot_upload" value="create_exp">Create Experiment</button>

</div>

</div>

{% endif %}
{% endif %}
{% endif %}

Expand Down
2 changes: 1 addition & 1 deletion escalate/core/utilities/calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import requests
from pint import UnitRegistry

from core.models.view_tables.chemistry_data import ReagentMaterial
from core.models.view_tables.chemistry_data import ReagentMaterial, Reagent
from core.models.view_tables import ExperimentInstance

# from core.utilities.experiment_utils import get_action_parameter_querysets
Expand Down
66 changes: 57 additions & 9 deletions escalate/core/utilities/experiment_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,26 +456,56 @@ def generate_experiments_and_save(
return q1


def save_manual_volumes(df, experiment_copy_uuid):
def save_manual_volumes(df, experiment_copy_uuid, dead_volume):
q1 = get_action_parameter_querysets(experiment_copy_uuid, template=False)
experiment = ExperimentInstance.objects.get(uuid=experiment_copy_uuid)
reagents = Reagent.objects.filter(experiment=experiment_copy_uuid)

if "workflow 1" in experiment.parent.description.lower():

reagent_action_map = {
"Reagent1 (ul)": "dispense solvent",
"Reagent7 (ul)": "dispense acid volume 1",
"Reagent8 (ul)": "dispense acid volume 2",
"Reagent2 (ul)": "dispense stock a",
"Reagent3 (ul)": "dispense stock b",
}

reagent_action_map = {
"Reagent1 (ul)": "dispense solvent",
"Reagent7 (ul)": "dispense acid volume 1",
"Reagent8 (ul)": "dispense acid volume 2",
"Reagent2 (ul)": "dispense stock a",
"Reagent3 (ul)": "dispense stock b",
}
reagent_template_robot_map = {
"Reagent 1 - Solvent": "Reagent1 (ul)",
"Reagent 7 - Acid": "Reagent7 (ul)",
"Reagent 2 - Stock A": "Reagent2 (ul)",
"Reagent 3 - Stock B": "Reagent3 (ul)",
}

elif "workflow 3" in experiment.parent.description.lower():
reagent_action_map = {
"Reagent1 (ul)": "dispense solvent",
"Reagent7 (ul)": "dispense acid volume 1",
"Reagent8 (ul)": "dispense acid volume 2",
"Reagent2 (ul)": "dispense stock a",
"Reagent3 (ul)": "dispense stock b",
"Reagent9 (ul)": "dispense antisolvent",
}

reagent_template_robot_map = {
"Reagent 1 - Solvent": "Reagent1 (ul)",
"Reagent 7 - Acid": "Reagent7 (ul)",
"Reagent 2 - Stock A": "Reagent2 (ul)",
"Reagent 3 - Stock B": "Reagent3 (ul)",
"Reagent 9 - Antisolvent": "Reagent9 (ul)",
}

for reagent_name, action_description in reagent_action_map.items():
well_list = []
for well in df["Vial Site"]:
well_list.append(well)

total_volume=0

for i, vial in enumerate(well_list):
# get actions from q1 based on keys in action_reagent_map
if experiment.parent.ref_uid == "workflow_1":
if experiment.parent.ref_uid == "workflow_1" or experiment.parent.ref_uid == "workflow_3":
action = q1.get(
action_unit_description__icontains=action_description,
action_unit_description__endswith=vial,
Expand All @@ -495,3 +525,21 @@ def save_manual_volumes(df, experiment_copy_uuid):
parameter.parameter_val_nominal.value = df[reagent_name][i]
# parameter.parameter_val_nominal.value = desired_volume[reagent_name][i]
parameter.save()
total_volume+=df[reagent_name][i]

for reagent in reagents:
if reagent_name == reagent_template_robot_map[reagent.template.description]:
#if robot_api_map[reagent_name]== reagent.description:

prop = reagent.property_r.get(
property_template__description__icontains="total volume"
)
prop.nominal_value.value = total_volume
prop.nominal_value.unit = "uL"
prop.save()
if dead_volume is not None:
dv_prop = reagent.property_r.get(
property_template__description__icontains="dead volume"
)
dv_prop.nominal_value = dead_volume
dv_prop.save()
46 changes: 44 additions & 2 deletions escalate/core/views/experiment/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
save_manual_volumes,
save_parameter,
)
from core.utilities.calculations import conc_to_amount
from core.utilities.wf1_utils import generate_robot_file_wf1
from core.models.view_tables.generic_data import Parameter

Expand Down Expand Up @@ -391,17 +392,58 @@ def process_robot_formsets(self, exp_uuid, request, context):
exp_concentrations = {}
for reagent_formset in formsets:
if reagent_formset.is_valid():
# vector = self.save_forms_reagent(reagent_formset, experiment_copy_uuid, exp_concentrations)
vector = self.save_forms_reagent(reagent_formset, experiment_copy_uuid, exp_concentrations)
#try:
exp_concentrations = prepare_reagents(
reagent_formset, exp_concentrations
)
#except TypeError as te:
# messages.error(request, str(te))

dead_volume_form = SingleValForm(request.POST, prefix="dead_volume")
if dead_volume_form.is_valid():
dead_volume = dead_volume_form.value
else:
dead_volume = None

# post reaction parameter form
# get label here and get form out of label, use label for description
rp_wfs = get_action_parameter_querysets(exp_template.uuid)
index = 0
for rp in rp_wfs:
rp_label = str(rp.object_description)
if "Dispense" in rp_label:
continue
else:
rp_form = ReactionParameterForm(
request.POST, prefix=f"reaction_parameter_{index}"
)
if rp_form.is_valid:
rp_value = rp_form.data[f"reaction_parameter_{index}-value_0"]
rp_unit = rp_form.data[f"reaction_parameter_{index}-value_1"]
rp_type = rp_form.data[f"reaction_parameter_{index}-value_2"]
rp_uuid = rp_form.data[f"reaction_parameter_{index}-uuid"]
save_reaction_parameters(
exp_template,
rp_value,
rp_unit,
rp_type,
rp_label,
experiment_copy_uuid,
)
# The rp_uuid is not being generated from the loadscript for some parameters
# This issue stems from the data being loaded in. This function will work once we fix loading issues
if rp_uuid != "":
save_parameter(rp_uuid, rp_value, rp_unit)
index += 1



df = pd.read_excel(request.FILES["file"])
# self.process_robot_file(df)
save_manual_volumes(df, experiment_copy_uuid)
save_manual_volumes(df, experiment_copy_uuid, dead_volume)

conc_to_amount(experiment_copy_uuid)

context["experiment_link"] = reverse(
"experiment_instance_view", args=[experiment_copy_uuid]
Expand Down