Skip to content

Commit

Permalink
plate layout in a template
Browse files Browse the repository at this point in the history
  • Loading branch information
vedina committed Mar 31, 2024
1 parent 1225c9e commit bbb8ceb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/pynanomapper/datamodel/templates/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
7 changes: 6 additions & 1 deletion tests/test_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ 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)
assert "Raw_data_TABLE" in xls.sheet_names
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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bbb8ceb

Please sign in to comment.