diff --git a/src/pynanomapper/datamodel/templates/blueprint.py b/src/pynanomapper/datamodel/templates/blueprint.py index 84e1d48..6153c72 100644 --- a/src/pynanomapper/datamodel/templates/blueprint.py +++ b/src/pynanomapper/datamodel/templates/blueprint.py @@ -117,6 +117,21 @@ def get_nmparser_config(json_blueprint): config = json.load(json_file) return config +def add_plate_layout(file_path_xlsx,json_blueprint): + print(json_blueprint.get("data_sheets")) + if "data_platelayout" in json_blueprint.get("data_sheets",[]): + platexlsx = "platelayout_{}well.xlsx".format(json_blueprint.get("data_platelayout",96) ) + current_script_directory = os.path.dirname(os.path.abspath(__file__)) + resource_file = os.path.join(current_script_directory, "../../resource/nmparser",platexlsx) + # Open the existing Excel file for appending + with pd.ExcelWriter(file_path_xlsx, engine='openpyxl', mode='a') as writer: + # Load sheets from the second Excel file + with pd.ExcelFile(resource_file) as another_xls: + for sheet_name in another_xls.sheet_names: + df = pd.read_excel(resource_file, sheet_name=sheet_name) + df.to_excel(writer, sheet_name=sheet_name, index=False) + + def get_template_frame(json_blueprint): if "METADATA_SAMPLE_INFO" in json_blueprint: df_sample = pd.DataFrame(list(get_materials_metadata(json_blueprint).items()), columns=['param_name', 'value']) diff --git a/tests/test_blueprint.py b/tests/test_blueprint.py index 20f8e32..fae79f9 100644 --- a/tests/test_blueprint.py +++ b/tests/test_blueprint.py @@ -26,7 +26,7 @@ def test_doseresponse_template(): def test_doseresponse_rawonly_template(): with open(TEST_JSON_PATH, "r") as file: json_blueprint = json.load(file) - json_blueprint["data_sheets"] = ["data_raw"] + json_blueprint["data_sheets"] = ["data_raw","data_platelayout"] _path = get_template_xlsx(TEMPLATE_UUID,json_blueprint) assert(Path(_path).exists()) xls = pd.ExcelFile(_path) @@ -34,6 +34,10 @@ def test_doseresponse_rawonly_template(): assert not "Results_TABLE" in xls.sheet_names assert "Test_conditions" in xls.sheet_names assert "Materials" in xls.sheet_names + assert "plate_table" in xls.sheet_names + assert "plate_metadata" in xls.sheet_names + assert "plate_readout" in xls.sheet_names + assert "plate_materials" in xls.sheet_names def test_doseresponse_error_template(): with open(TEST_EXCEL_ERROR, "r") as file: @@ -70,6 +74,7 @@ def get_template_xlsx(uuid,json_blueprint): file_path_xlsx = os.path.join(TEMPLATE_DIR, f"{uuid}.xlsx") df_info,df_result,df_raw, df_conditions =bp.get_template_frame(json_blueprint) bp.iom_format_2excel(file_path_xlsx,df_info,df_result,df_raw,df_conditions) + bp.add_plate_layout(file_path_xlsx,json_blueprint) return file_path_xlsx except Exception as err: raise err