From f47e97ff5e06d8f0a7fab7cb753329d860b1512e Mon Sep 17 00:00:00 2001 From: vedina Date: Thu, 4 Apr 2024 09:12:46 +0300 Subject: [PATCH] fixed regression preventing excel generation (sometimes) added new test files --- src/pynanomapper/datamodel/templates/blueprint.py | 2 ++ tests/resources/teer.json | 1 + tests/resources/templates/fras.json | 1 + tests/test_blueprint.py | 13 +++++++++++++ 4 files changed, 17 insertions(+) create mode 100644 tests/resources/teer.json create mode 100644 tests/resources/templates/fras.json diff --git a/src/pynanomapper/datamodel/templates/blueprint.py b/src/pynanomapper/datamodel/templates/blueprint.py index c7767aa..01fa70a 100644 --- a/src/pynanomapper/datamodel/templates/blueprint.py +++ b/src/pynanomapper/datamodel/templates/blueprint.py @@ -107,6 +107,8 @@ def get_treatment(json_blueprint): tag =item['condition_type'].split('_')[1][0].upper() _start = 0 if isconcentration else 1 tmp.append({'param_name': "{} series labels".format(item[name]), 'type': 'names', 'position' : '0', 'position_label' : 0,'datamodel' : item['condition_type'], "value" : [f"{tag}{i}" if i <= 3 else "" for i in range(1, _maxfields + 1)]}) + else: + _start = 0 tmp.append({'param_name': "{}".format(item[name]), 'type': 'names', 'position' : '0', 'position_label' : 0,'datamodel' : item['condition_type'], "value" : [i if i<=(2+_start) else "" for i in range(_start, _maxfields + _start + 1)]}) if isconcentration: tmp.append({'param_name': "Treatment type series", 'type': 'names', 'position' : '0', 'position_label' : 0,'datamodel' : "c_treatment", "value" : ""}) diff --git a/tests/resources/teer.json b/tests/resources/teer.json new file mode 100644 index 0000000..b9a6353 --- /dev/null +++ b/tests/resources/teer.json @@ -0,0 +1 @@ +{"newtemplate":"create_new","PROTOCOL_TOP_CATEGORY":"TOX","pageNo":0,"user_role":["role_lab"],"templates":"c5dd3ac9-9340-44b0-9be8-6724c5e34c99","METHOD":"TEER","EXPERIMENT":"barier integrity","conditions":[{"conditon_name":"time","condition_unit":"h","condition_type":"c_time"},{"conditon_name":"concentration","condition_unit":"ug/ml","condition_type":"c_concentration"},{"conditon_name":"Replicate","condition_type":"c_replicate_tech"},{"conditon_name":"Experiment","condition_type":"c_replicate_bio"}],"PROTOCOL_CATEGORY_CODE":"ENM_0000044_SECTION","data_sheets":["data_raw","data_processed"],"RESULTS":"Ohms.Area\nbarier integrity\n","raw_data_report":[{"raw_conditions":["concentration","time","Experiment","Replicate","Passage"],"raw_endpoint":"RESISTANCE","raw_aggregate":"RAW_DATA","raw_unit":"Ω","raw_type":"value_num"},{"raw_conditions":["time","concentration","Replicate","Experiment"],"raw_endpoint":"RESISTANCE with subtracted blank values","raw_unit":"Ω","raw_type":"value_num"},{"raw_conditions":["Experiment","Replicate","concentration","time"],"raw_endpoint":"TEER","raw_aggregate":"RAW_DATA","raw_unit":"Ω•cm2","raw_type":"value_num"}],"question3":[{"results_conditions":["concentration","time","Experiment"],"result_name":"TEER (replicate average)","result_aggregate":"MEAN","result_unit":"Ω•cm2","result_type":"value_num"},{"results_conditions":["concentration","time"],"result_name":"TEER","result_unit":"Ω•cm2","result_endpoint_uncertainty":"SD","result_type":"value_num"}],"METADATA_PARAMETERS":[{"param_name":"Detailed cell type/line specification","param_group":"CELL LINE DETAILS","param_type":"value_text"},{"param_name":"Cell line short-name","param_group":"CELL LINE DETAILS","param_type":"value_text"},{"param_name":"Cell line Supplier","param_group":"CELL LINE DETAILS","param_type":"value_text"},{"param_hint":"DMEM","param_name":"Cell culture medium composition in lower compartment","param_group":"CULTURE CONDITIONS","param_type":"value_text ","param_subgroup":"Cell culture medium"},{"param_subgroup":"Cell culture medium","param_name":"Serum concentration in culture medium in lower compartment","param_group":"CULTURE CONDITIONS","param_type":"value_num"},{"param_subgroup":"Cell culture medium","param_name":"Volume of cell culture medium in lower compartment","param_group":"CULTURE CONDITIONS","param_type":"value_num"},{"param_subgroup":"Cell culture medium","param_hint":"air liquid interface OR submerged (to be chosen)","param_name":"Cell culture conditions","param_group":"CULTURE CONDITIONS","param_type":"value_text"},{"param_subgroup":"Cell culture medium","param_hint":"applicable only if submerged conditions were chosen","param_name":"Cell culture medium composition in upper compartment","param_group":"CULTURE CONDITIONS","param_type":"value_text"},{"param_subgroup":"Cell culture medium","param_hint":"applicable only if submerged conditions were chosen","param_name":"Serum concentration in culture medium in upper compartment","param_group":"CULTURE CONDITIONS","param_type":"value_num"},{"param_subgroup":"Cell culture medium","param_hint":"applicable only if submerged conditions were chosen","param_name":"Volume of cell culture medium in upper compartment","param_group":"CULTURE CONDITIONS","param_type":"value_num"},{"param_name":"Was serum heat inactivated","param_group":"MEDIUM","param_type":"value_boolean"},{"param_subgroup":"Plate","param_name":"Plate details","param_group":"MEASUREMENT CONDITIONS","param_type":"value_text","param_hint":"24-well"},{"param_subgroup":"Plate","param_hint":"24-well","param_name":"Plate Make / type","param_group":"MEASUREMENT CONDITIONS","param_type":"value_text"},{"param_hint":"(pore size, material) ","param_subgroup":"culture inserts","param_name":"Type and supplier of cell culture inserts","param_group":"MEASUREMENT CONDITIONS","param_type":"value_text"},{"param_subgroup":"culture inserts","param_name":"Area of cell culture insert","param_unit":"cm2","param_group":"MEASUREMENT CONDITIONS","param_type":"value_num"},{"param_name":"TEER measurement device","param_group":"INSTRUMENT","param_type":"value_text","param_hint":"EVOM 3"},{"param_name":"TEER measurement mode","param_group":"INSTRUMENT","param_type":"value_text"},{"param_name":"Temperature during TEER measurement","param_group":"INSTRUMENT","param_type":"value_num"},{"param_name":"Medium composition during TEER measurement","param_group":"INSTRUMENT","param_type":"value_text"}],"METADATA_SAMPLE_INFO":[{"param_sample_name":"ID","param_sample_group":"ID"},{"param_sample_name":"Name","param_sample_group":"NAME"},{"param_sample_name":"CAS No","param_sample_group":"CASRN"},{"param_sample_name":"Material Supplier","param_sample_group":"SUPPLIER"},{"param_sample_name":"Material State","param_sample_group":"OTHER_METADATA"},{"param_sample_name":"Batch","param_sample_group":"BATCH"},{"param_sample_name":"Vial","param_sample_group":"BATCH"}],"METADATA_SAMPLE_PREP":[{"param_sampleprep_name":"Date of preparation","param_sampleprep_group":"OTHER_SAMPLEPREP","param_type":"value_date"},{"param_sampleprep_name":"Endotoxin confirmed as absent?","param_sampleprep_group":"OTHER_METADATA","param_type":"value_boolean"},{"param_sampleprep_name":"Effective concentration range","param_sampleprep_group":"OTHER_METADATA","param_type":"value_num"},{"param_sampleprep_name":"Dispersion protocol","param_sampleprep_group":"DISPERSION","param_type":"value_text"},{"param_sampleprep_name":"Dispersion agent","param_sampleprep_group":"DISPERSION","param_type":"value_text "},{"param_sampleprep_name":" Additives used","param_sampleprep_group":"DISPERSION","param_type":"value_boolean"},{"param_sampleprep_name":"Dispersed in cell culture medium","param_sampleprep_group":"DISPERSION","param_type":"value_text"},{"param_sampleprep_name":"Aids used to disperse","param_sampleprep_group":"DISPERSION","param_type":"value_boolean","param_sampleprep_subgroup":"Aids used to disperse"},{"param_sampleprep_subgroup":"Aids used to disperse","param_sampleprep_name":"Sonication-Bath","param_sampleprep_group":"DISPERSION","param_type":"value_text"},{"param_sampleprep_hint":"Yes","param_sampleprep_subgroup":"Aids used to disperse","param_sampleprep_name":"Sonication-tip","param_sampleprep_group":"DISPERSION","param_type":"value_text"},{"param_sampleprep_hint":"Yes","param_sampleprep_subgroup":"Aids used to disperse","param_sampleprep_name":"Vortexing","param_sampleprep_group":"DISPERSION","param_type":"value_boolean"},{"param_sampleprep_subgroup":"Aids used to disperse","param_sampleprep_name":"Stirring","param_sampleprep_group":"DISPERSION","param_type":"value_boolean"},{"param_sampleprep_hint":"16 min","param_sampleprep_name":"Specify time-duration","param_sampleprep_group":"DISPERSION","param_type":"value_num","param_sampleprep_subgroup":"Aids used to disperse"},{"param_sampleprep_subgroup":"Aids used to disperse","param_sampleprep_name":"Energy (for sonication)","param_sampleprep_group":"DISPERSION","param_type":"value_num"}],"template_author":"Neža Repar, Sara Michelini","template_name":"TEER (ALI or submerged)","template_acknowledgment":"PLASTICFATE","SOP":"protocol_research","EXPERIMENT_PROTOCOL":"barier integrity\n","controls":["c_control_positive","c_control_negative","c_control_blank"],"plate_format":"96","template_layout":"dose_response","template_author_orcid":"c67e6db2-0551-4d85-99dc-d55c8ecd48f8","template_status":"DRAFT","origin_uuid":"c67e6db2-0551-4d85-99dc-d55c8ecd48f8","question3-Comment":"Triton X100 positive control\nnegative control Replicate of blank values (cell inserts without cells)","provenance_project":"PLASTICFATE"} \ No newline at end of file diff --git a/tests/resources/templates/fras.json b/tests/resources/templates/fras.json new file mode 100644 index 0000000..842a74c --- /dev/null +++ b/tests/resources/templates/fras.json @@ -0,0 +1 @@ +{"newtemplate":"create_new","PROTOCOL_TOP_CATEGORY":"P-CHEM","pageNo":0,"user_role":["role_datamgr"],"templates":"c5dd3ac9-9340-44b0-9be8-6724c5e34c99","METHOD":"FRAS","EXPERIMENT":"SAbyNA 96-wells plate protocol","conditions":[{"conditon_name":"Experiment","condition_type":"c_replicate_bio"},{"conditon_name":"wavelength","condition_unit":"nm","condition_type":"c_time"},{"conditon_name":"Replicate","condition_type":"c_replicate_tech"},{"conditon_name":"concentration","condition_unit":"ug/ml","condition_type":"c_concentration"},{"conditon_name":"TEU calibration","condition_unit":"mM/L TEU","condition_type":"c_other"}],"data_sheets":["data_raw","data_processed"],"RESULTS":"raw data ( absorbance) \nReactivity\nROS generation\nOxidative damage (nmol TEU)/L\n\n","raw_data_report":[{"raw_conditions":["concentration","time","Experiment","Replicate","wavelength"],"raw_endpoint":"Absorbance","raw_aggregate":"RAW_DATA","raw_unit":"A.U.","raw_type":"value_num"}],"question3":[{"results_conditions":["concentration","time","Experiment","TEU calibration"],"result_name":"Absorption at 596nm","result_unit":"AU","result_type":"value_num"},{"results_conditions":["concentration","time","Experiment","TEU calibration"],"result_name":"Oxidative damage","result_unit":"nmol TEU/L","result_type":"value_num"},{"results_conditions":["Experiment","concentration"],"result_name":"Absorption at 596nm","result_aggregate":"MEAN","result_unit":"AU","result_type":"value_num"},{"results_conditions":["concentration"],"result_name":"Oxidative damage","result_aggregate":"MEAN","result_unit":"nmol TEU/L","result_endpoint_uncertainty":"SD","result_type":"value_num"},{"results_conditions":["concentration"],"result_name":"SBOD","result_unit":"nmol TEU / m²","result_endpoint_uncertainty":"SD","result_type":"value_num"},{"results_conditions":["concentration"],"result_name":"MBOD","result_unit":"nmol TEU / mg","result_endpoint_uncertainty":"SD","result_type":"value_num"},{"result_name":"SBOD (highest dose)","result_unit":"nmol TEU / m²","result_endpoint_uncertainty":"SD","result_type":"value_num"},{"result_name":"SBOD","result_aggregate":"MAX","result_unit":"nmol TEU / m²","result_endpoint_uncertainty":"SD","result_type":"value_num"},{"result_name":"MBOD","result_aggregate":"MAX","result_unit":"nmol TEU / mg","result_endpoint_uncertainty":"SD","result_type":"value_num"}],"METADATA_PARAMETERS":[{"param_name":"d (light path UVVis cuvette) / cm","param_group":"INSTRUMENT","param_type":"value_num"},{"param_name":"extinction coefficient generated per TEU","param_unit":"mmol/L TEU /cm","param_group":"MEASUREMENT CONDITIONS","param_type":"value_num"},{"param_name":"dilution 0.1mL_serum @ 2mL_FRASreagent","param_group":"MEASUREMENT CONDITIONS","param_type":"value_num"},{"param_hint":"593","param_subgroup":"wavelength","param_name":"Wavelength start","param_unit":"nm","param_group":"INSTRUMENT","param_type":"value_num"},{"param_subgroup":"wavelength","param_hint":"593","param_name":"Wavelength end","param_unit":"nm","param_group":"INSTRUMENT","param_type":"value_num"}],"METADATA_SAMPLE_INFO":[{"param_sample_name":"ID","param_sample_group":"ID"},{"param_sample_name":"Name","param_sample_group":"NAME"},{"param_sample_name":"CAS No","param_sample_group":"CASRN"},{"param_sample_name":"Nanomaterial Supplier","param_sample_group":"SUPPLIER"},{"param_sample_name":"Material State","param_sample_group":"OTHER_METADATA"},{"param_sample_name":"Batch","param_sample_group":"BATCH"},{"param_sample_name":"Vial","param_sample_group":"BATCH"}],"METADATA_SAMPLE_PREP":[{"param_sampleprep_name":"Date of preparation","param_sampleprep_group":"OTHER_METADATA","param_type":"value_date"},{"param_sampleprep_name":"Dispersion protocol","param_sampleprep_group":"DISPERSION","param_type":"value_text"},{"param_sampleprep_name":"Dispersion agent","param_sampleprep_group":"DISPERSION","param_type":"value_text "},{"param_sampleprep_name":" Additives used","param_sampleprep_group":"DISPERSION","param_type":"value_boolean"},{"param_sampleprep_name":"Dispersed in cell culture medium","param_sampleprep_group":"DISPERSION","param_type":"value_text"},{"param_sampleprep_name":"Aids used to disperse","param_sampleprep_group":"DISPERSION","param_type":"value_text"},{"param_sampleprep_name":"Sonication-Bath","param_sampleprep_group":"DISPERSION","param_type":"value_text"},{"param_sampleprep_name":"Sonication-tip","param_sampleprep_group":"DISPERSION","param_type":"value_text"},{"param_sampleprep_name":"Vortexing","param_sampleprep_group":"DISPERSION","param_type":"value_boolean"},{"param_sampleprep_name":"Stirring","param_sampleprep_group":"DISPERSION","param_type":"value_boolean"},{"param_sampleprep_name":"Specify time-duration","param_sampleprep_group":"DISPERSION","param_type":"value_num"},{"param_sampleprep_name":"Energy (for sonication)","param_sampleprep_group":"DISPERSION","param_type":"value_num"}],"template_author":"Nienke Ruijter","template_name":"Ferric Reduction Ability of Serum (FRAS)","template_acknowledgment":"SABYNA","SOP":"protocol_research","EXPERIMENT_PROTOCOL":"Pending publication\n","controls":["c_control_positive","c_control_negative","c_control_blank"],"plate_format":"96","template_layout":"dose_response","template_author_orcid":"0000-0002-4322-6179","origin_uuid":"26475cb3-a4e8-4b25-844a-87e3b244d73c","confirm_statuschange":["DRAFT"],"template_status":"DRAFT","template_date":"2024-04-03","PROTOCOL_CATEGORY_CODE":"RADICAL_FORMATION_POTENTIAL_SECTION","question3-Comment":"we need a way to denote the TEU calibration is not varied independently, but with experiment","provenance_project":"SABYNA"} \ No newline at end of file diff --git a/tests/test_blueprint.py b/tests/test_blueprint.py index 796fd33..6a81af9 100644 --- a/tests/test_blueprint.py +++ b/tests/test_blueprint.py @@ -8,6 +8,7 @@ TEMPLATE_DIR = Path(__file__).parent / "resources/templates" TEST_JSON_PATH = f"{TEMPLATE_DIR}/dose_response.json" TEST_PCHEM_PATH = f"{TEMPLATE_DIR}/tga.json" +TEST_FRAS_PATH = f"{TEMPLATE_DIR}/fras.json" TEST_EXCEL_ERROR_UUID = "015690ac-b26a-4845-826e-c479a62eef62" TEST_EXCEL_ERROR = f"{TEMPLATE_DIR}/{TEST_EXCEL_ERROR_UUID}.json" @@ -41,6 +42,18 @@ def test_doseresponse_rawonly_template(): assert "plate_readout" in xls.sheet_names assert "plate_materials" in xls.sheet_names +def test_doseresponse_fras_template(): + with open(TEST_FRAS_PATH, "r", encoding='utf-8') as file: + json_blueprint = json.load(file) + _path = get_template_xlsx(TEMPLATE_UUID,json_blueprint) + assert(Path(_path).exists()) + xls = pd.ExcelFile(_path) + assert "Raw_data_TABLE" in xls.sheet_names + assert "Results_TABLE" in xls.sheet_names + assert "Test_conditions" in xls.sheet_names + assert "Materials" in xls.sheet_names + + def test_doseresponse_error_template(): with open(TEST_EXCEL_ERROR, "r", encoding='utf-8') as file: json_blueprint = json.load(file)