Skip to content

Commit

Permalink
pchem format
Browse files Browse the repository at this point in the history
  • Loading branch information
vedina committed Mar 31, 2024
1 parent bbb8ceb commit 59cefd1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/pynanomapper/datamodel/templates/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
from datetime import datetime
from xlsxwriter.utility import xl_col_to_name
import openpyxl
import shutil

def iom_format(df,param_name="param_name",param_group="param_group"):
df.fillna(" ",inplace=True)
Expand Down Expand Up @@ -117,6 +117,11 @@ def get_nmparser_config(json_blueprint):
config = json.load(json_file)
return config

def pchem_format_2excel(file_path,json_blueprint):
current_script_directory = os.path.dirname(os.path.abspath(__file__))
resource_file = os.path.join(current_script_directory, "../../resource/nmparser","template_pchem.xlsx")
shutil.copy2(resource_file, file_path)

def add_plate_layout(file_path_xlsx,json_blueprint):
print(json_blueprint.get("data_sheets"))
if "data_platelayout" in json_blueprint.get("data_sheets",[]):
Expand Down Expand Up @@ -240,7 +245,6 @@ def results_table(df_result,df_conditions = None,
return pd.DataFrame(columns=header1)



def iom_format_2excel(file_path, df_info,df_result,df_raw=None,df_conditions=None):
_SHEET_INFO = "Test_conditions"
_SHEET_RAW = "Raw_data_TABLE"
Expand Down
Binary file not shown.
24 changes: 21 additions & 3 deletions tests/test_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ def test_doseresponse_resultsonly_template():
assert "Test_conditions" in xls.sheet_names
assert "Materials" in xls.sheet_names

def test_pchem_template():
with open(TEST_JSON_PATH, "r") as file:
json_blueprint = json.load(file)
json_blueprint["template_layout"] = ["pchem"]
json_blueprint["data_sheets"] = ["data_processed"]
_path = get_template_xlsx(TEMPLATE_UUID,json_blueprint)
assert(Path(_path).exists())
xls = pd.ExcelFile(_path)
#assert not "Raw_data_TABLE" in xls.sheet_names
assert "Results_TABLE" in xls.sheet_names
assert "Provider_informations" in xls.sheet_names
assert "Measuring_conditions" in xls.sheet_names
assert "Materials" in xls.sheet_names

def test_doseresponse_nmparser():
with open(TEST_JSON_PATH, "r") as file:
json_blueprint = json.load(file)
Expand All @@ -72,9 +86,13 @@ def test_doseresponse_nmparser():
def get_template_xlsx(uuid,json_blueprint):
try:
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)
layout = json_blueprint.get("template_layout","dose_response")
if layout == "dose_response":
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)
else:
bp.pchem_format_2excel(file_path_xlsx,json_blueprint)
return file_path_xlsx
except Exception as err:
raise err
Expand Down

0 comments on commit 59cefd1

Please sign in to comment.