Skip to content

Commit

Permalink
survey.json in a hidden sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
vedina committed Apr 2, 2024
1 parent a8beb78 commit fdcf156
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
46 changes: 39 additions & 7 deletions src/pynanomapper/datamodel/templates/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from xlsxwriter.utility import xl_col_to_name
import shutil
from openpyxl.utils import get_column_letter
from openpyxl.styles import PatternFill
from openpyxl.styles import PatternFill, NamedStyle
from openpyxl import load_workbook
def iom_format(df,param_name="param_name",param_group="param_group"):
df.fillna(" ",inplace=True)
Expand Down Expand Up @@ -181,32 +181,64 @@ def pchem_format_2excel(file_path_xlsx,json_blueprint):
resource_file = os.path.join(current_script_directory, "../../resource/nmparser","template_pchem.xlsx")
shutil.copy2(resource_file, file_path_xlsx)
with pd.ExcelWriter(file_path_xlsx, engine='openpyxl', mode='a') as writer:
sheet = writer.book["Provider_informations"]
sheet["E7"] = json_blueprint.get("METHOD","")
sheet["C2"] = json_blueprint.get("EXPERIMENT","")
sheet["B10"] = json_blueprint.get("template_name","")
sheet["B11"] = json_blueprint.get("template_status","")
sheet["B12"] = json_blueprint.get("template_author","")
sheet["B13"] = json_blueprint.get("template_acknowledgment","")
sheet["B15"] = datetime.now().strftime("%Y-%m-%d")
df = create_nested_headers_dataframe(json_blueprint,keys=
{"raw_data_report" : {'name' : 'raw_endpoint','type' : 'raw_aggregate', 'unit' : 'raw_unit'},
"question3" : {'name' : 'result_name','type' : 'result_aggregate','unit' : 'result_unit'}},
levels = ['name','type','unit'],
lookup = {"raw_data_report" : "Raw data","question3" : "Results"}
)
df.insert(0, 'Material ID',None)
df.insert(1, 'Position_ID',None)
#df.insert(0, 'Material ID',None)
df.insert(0, 'Position_ID',None)
df.to_excel(writer,sheet_name="Results_TABLE")
sheet = writer.book["Results_TABLE"]
sheet["A1"] = "Material ID"
sheet["A2"] = ""
sheet["A3"] = ""
sheet["A4"] = ""
autofit_columns(writer.book["Results_TABLE"],df.columns)

df = create_nested_headers_dataframe(json_blueprint,keys={"METADATA_PARAMETERS" : {'group' : 'param_group', 'name' : 'param_name', 'unit' : 'param_unit'}})
df.insert(0, 'Position_ID',None)
#df.insert(0, 'Position_ID',None)
df.to_excel(writer,sheet_name="Measuring_conditions")
sheet = writer.book["Measuring_conditions"]
sheet["A1"] = "Position_ID"
sheet["A2"] = ""
sheet["A3"] = ""
sheet["A4"] = ""
autofit_columns(writer.book["Measuring_conditions"],df.columns)

df = create_nested_headers_dataframe(json_blueprint,keys=
{"METADATA_SAMPLE_INFO" : {'group' : 'param_sample_group', 'name' : 'param_sample_name'},
"METADATA_SAMPLE_PREP" : {'group' : 'param_sampleprep_group', 'name' : 'param_sampleprep_name'}},
levels = ['group','name'], lookup = {'METADATA_SAMPLE_INFO' : "Sample", "METADATA_SAMPLE_PREP" : "Sample preparation"})
levels = ['group','name'],
lookup = {'METADATA_SAMPLE_INFO' : "Sample", "METADATA_SAMPLE_PREP" : "Sample preparation", "group" : ""})
df.insert(0, 'Material ID',None)
df.to_excel(writer,sheet_name="SAMPLES")
autofit_columns(writer.book["SAMPLES"],df.columns)


add_hidden_jsondef(file_path_xlsx,json_blueprint)

def add_hidden_jsondef(file_path_xlsx,json_blueprint):
try:
workbook = load_workbook(file_path_xlsx)
hidden_sheet = workbook.create_sheet("TemplateDesigner")
hidden_sheet.sheet_state = 'hidden'
hidden_sheet['A1'] = "uuid"
hidden_sheet['B1'] = "surveyjs"
hidden_sheet['A2'] = json_blueprint.get("template_uuid","")
hidden_sheet['B2'] = str(json_blueprint)
hidden_sheet['B2'].style = NamedStyle(name='hidden', hidden=True) # Hide the cell
workbook.save(file_path_xlsx)
except Exception as err:
print(err)

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
Binary file modified src/pynanomapper/resource/nmparser/template_pchem.xlsx
Binary file not shown.
1 change: 1 addition & 0 deletions tests/resources/templates/ache.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"SOP":"protocol_research","conditions":[{"conditon_name":"Concentration","condition_unit":"mg/mol","condition_type":"c_concentration"},{"conditon_name":"Replicate","condition_type":"c_replicate"},{"conditon_name":"Experiment","condition_type":"c_experiment"}],"PROTOCOL_TOP_CATEGORY":"TOX","data_sheets":["data_raw","data_processed"],"METADATA_SAMPLE_INFO":[{"param_sample_name":"Material ID","param_sample_group":"ID"},{"param_sample_name":"Material name","param_sample_group":"NAME"},{"param_sample_name":"Material supplier","param_sample_group":"SUPPLIER"}],"template_date":"2024-03-25","template_status":"DRAFT","template_layout":"dose_response","template_name":"Acetylcholineesterase - inhibition, absorbance","template_author":"DD","template_acknowledgment":"PLASTICFATE","user_role":["role_lab"],"METHOD":"Acetylcholineesterase - inhibition, absorbance","EXPERIMENT":"Acetylcholinesterase inhibition and adsorption assays for biological characterization of micro- and nanomaterials","EXPERIMENT_PROTOCOL":"PlasticFate SOP","controls":["c_control_negative","c_control_positive"],"PROTOCOL_CATEGORY_CODE":"NPO_1339_SECTION","raw_data_report":[{"raw_conditions":["Concentration","Time","Replicate","Experiment"],"raw_endpoint":"Average absorbance ","raw_aggregate":"MEAN","raw_type":"value_num"},{"raw_conditions":["Concentration","Replicate","Experiment"],"raw_endpoint":"Background absorbance (Ellman control)","raw_aggregate":"RAW_DATA","raw_type":"value_num"},{"raw_conditions":["Concentration","Replicate","Experiment"],"raw_endpoint":"Absorbance (subtracted background)","raw_aggregate":"RAW_DATA","raw_type":"value_num"},{"raw_conditions":["Concentration","Replicate","Experiment"],"raw_endpoint":"% of enzyme activity","raw_aggregate":"RAW_DATA","raw_unit":"%","raw_type":"value_num"},{"raw_conditions":["Experiment","Replicate","Concentration"],"raw_endpoint":"% of enzyme inhibition caused by NP/MP","raw_aggregate":"RAW_DATA","raw_unit":"%","raw_type":"value_num"}],"question3":[{"results_conditions":["Concentration"],"result_name":"% of enzyme inhibition","result_aggregate":"MEAN","result_unit":"%","result_endpoint_uncertainty":"SD","result_type":"value_num"}],"RESULTS":"biological characterization of nano/micro material\nINHIBITION\t& ADSORPTION\nReplicate 1\tAverage absorbance \tBackground absorbance (Ellman control)\tAbsorbance (subtracted background)\t% of enzyme activity\t% of enzyme inhibition caused by NP/MP\nResults\nINHIBITION\t& ADSORPTION\n% of enzyme inhibition\tStDev\n","raw_data_report-Comment":"INHIBITION / ADSORPTION","question3-Comment":"INHIBITION / ADSORPTION","METADATA_PARAMETERS":[{"param_hint":"Acetylcholinesterase from Electrophorus electricus (electric eel)","param_subgroup":"ENZYME DETAILS","param_name":"Enzyme specification","param_group":"OTHER_METADATA","param_type":"value_text"},{"param_subgroup":"ENZYME DETAILS","param_hint":"Sigma Aldrich","param_name":"Supplier","param_group":"OTHER_METADATA","param_type":"value_text"},{"param_subgroup":"ENZYME DETAILS","param_hint":"0.05","param_name":"Initial enzyme concentration","param_unit":"U/ml","param_group":"OTHER_METADATA","param_type":"value_num"}],"METADATA_SAMPLE_PREP":[{"param_sampleprep_name":"Endotoxin confirmed as absent?","param_sampleprep_group":"OTHER_SAMPLEPREP","param_type":"value_boolean"}],"provenance_project":"PLASTICFATE","provenance_workpackage":"WP3","template_author_orcid":"0000-0002-5970-7460"}
3 changes: 3 additions & 0 deletions tests/test_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ def get_template_xlsx(uuid,json_blueprint):
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)
json_blueprint["template_uuid"] = uuid
bp.add_hidden_jsondef(file_path_xlsx,json_blueprint)
else:
json_blueprint["template_uuid"] = uuid
bp.pchem_format_2excel(file_path_xlsx,json_blueprint)
return file_path_xlsx
except Exception as err:
Expand Down

0 comments on commit fdcf156

Please sign in to comment.