Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix header generation for `METADATA_LAB` and `DATA_VALIDATION`: now "CAMPO" is the first row, "REQUIRED" last [#849](https://github.com/BU-ISCIII/relecov-tools/pull/849)
- Now Metadatalab validation sheets (DATA_VALIDATION and DROPDOWNS) only generate the included fields, not all of them [#849](https://github.com/BU-ISCIII/relecov-tools/pull/849)
- Fixed datetime recognition for schema example generation and validation [#854](https://github.com/BU-ISCIII/relecov-tools/pull/854)
- Restore formatting and validation behavior after header reordering + add Excel warnings for MEPRAM [#856] (https://github.com/BU-ISCIII/relecov-tools/pull/856)

#### Changed

Expand Down
27 changes: 24 additions & 3 deletions relecov_tools/assets/schema_utils/metadatalab_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ def excel_formater(df, writer, sheet, out_file, have_index=True, have_header=Tru
}
)

# First column format
no_fill_formater = workbook.add_format(
{
"bold": True,
"text_wrap": False,
"valign": "center",
"fg_color": "#D4D3D3", # Light gray
"locked": True,
}
)

cell_formater = workbook.add_format(
{
"border": 1, # Apply border to every cell
Expand Down Expand Up @@ -193,7 +204,7 @@ def excel_formater(df, writer, sheet, out_file, have_index=True, have_header=Tru
stderr.print(
f"Error writing first column at row {row_num}: {e}"
)
if row_num == 0 and col_num >= 0 and sheet == "METADATA_LAB":
if row_num == 3 and col_num >= 0 and sheet == "METADATA_LAB":
try:
worksheet.write(
row_num,
Expand All @@ -211,6 +222,16 @@ def excel_formater(df, writer, sheet, out_file, have_index=True, have_header=Tru
worksheet.write(index_num, 0, index_val, first_col_formater)
except Exception as e:
stderr.print(f"Error writing first column at row {row_num}: {e}")

if sheet == "METADATA_LAB":
# Format the first column for all data rows (from row 5 onwards)
max_rows = 1000 # Maximum number of rows to format
for row_num in range(len(df), max_rows):
try:
worksheet.write(row_num, 0, "", no_fill_formater)
except Exception as e:
stderr.print(f"Error formatting first column at row {row_num}: {e}")

except Exception as e:
stderr.print(f"Error in excel_formater: {e}")

Expand All @@ -220,7 +241,7 @@ def create_condition(ws_metadata, conditions, df_filtered):
label_to_property = dict(zip(df_filtered["label"], df_filtered["property_id"]))
column_map = {}

for cell in ws_metadata[4]:
for cell in ws_metadata[1]:
property_id = label_to_property.get(cell.value)
if property_id in conditions:
column_map[property_id] = cell.column_letter
Expand Down Expand Up @@ -277,7 +298,7 @@ def add_conditional_format_age_check(
label_to_property = dict(zip(df_filtered["label"], df_filtered["property_id"]))

column_map = {}
for cell in ws_metadata[4]:
for cell in ws_metadata[1]:
property_id = label_to_property.get(cell.value)
if property_id:
column_map[property_id] = cell.column_letter
Expand Down
58 changes: 49 additions & 9 deletions relecov_tools/conf/build_schema_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"projects" : {
"relecov": {
"host_age_years": {
"header_row_idx": 5,
"header_row_idx": 1,
"max_rows": 1000,
"validation_type": "whole",
"operator": "between",
Expand All @@ -12,7 +12,7 @@
"error_title": "Valor no permitido"
},
"host_age_months": {
"header_row_idx": 5,
"header_row_idx": 1,
"max_rows": 1000,
"validation_type": "whole",
"operator": "between",
Expand All @@ -22,7 +22,7 @@
"error_title": "Valor no permitido"
},
"sample_collection_date": {
"header_row_idx": 5,
"header_row_idx": 1,
"max_rows": 1000,
"validation_type": "custom",
"formula1": "=ISNUMBER({col_letter}5)",
Expand All @@ -31,7 +31,7 @@
"format_cells_as_date": true
},
"sample_received_date": {
"header_row_idx": 5,
"header_row_idx": 1,
"max_rows": 1000,
"validation_type": "custom",
"formula1": "=ISNUMBER({col_letter}5)",
Expand All @@ -40,7 +40,7 @@
"format_cells_as_date": true
},
"sequencing_date": {
"header_row_idx": 5,
"header_row_idx": 1,
"max_rows": 1000,
"validation_type": "custom",
"formula1": "=ISNUMBER({col_letter}5)",
Expand All @@ -50,15 +50,43 @@
}
},
"mepram": {
"host_age_test": {
"header_row_idx": 5,
"host_age_years": {
"header_row_idx": 1,
"max_rows": 1000,
"validation_type": "whole",
"operator": "between",
"formula1": "3",
"formula2": "110",
"error_message": "El valor debe estar entre 3 y 110 años.",
"error_message": "El valor debe estar entre 3 y 110 años. Si es inferior a 3 años, debe rellenar la siguiente columna: [Host Age Months].",
"error_title": "Valor no permitido"
},
"host_age_months": {
"header_row_idx": 1,
"max_rows": 1000,
"validation_type": "whole",
"operator": "between",
"formula1": "0",
"formula2": "35",
"error_message": "El valor debe estar entre 0 y 35 meses.",
"error_title": "Valor no permitido"
},
"patient_birth_date": {
"header_row_idx": 1,
"max_rows": 1000,
"validation_type": "custom",
"formula1": "=ISNUMBER({col_letter}5)",
"error_message": "Ingrese la fecha en formato correcto YYYY-MM-DD (ejemplo: 2024-02-12).",
"error_title": "Formato de fecha incorrecto",
"format_cells_as_date": true
},
"sample_collection_date": {
"header_row_idx": 1,
"max_rows": 1000,
"validation_type": "custom",
"formula1": "=ISNUMBER({col_letter}5)",
"error_message": "Ingrese la fecha en formato correcto YYYY-MM-DD (ejemplo: 2024-02-12).",
"error_title": "Formato de fecha incorrecto",
"format_cells_as_date": true
}
}
},
Expand All @@ -76,7 +104,19 @@
"Public databases",
"Bioinformatics and QC metrics fields"
],
"mepram": []
"mepram": [
"Database Identifiers",
"Sample collection and processing",
"Public databases",
"Sequencing",
"Host information",
"Host exposure information",
"Files info",
"Bioinformatics and QC metrics fields",
"Contributor Acknowledgement",
"Strain characterization",
"Other"
]
},
"database_mapping_features": {
"enum": "enum",
Expand Down
Loading