From aecd4db594194c7478de71626ba5c55739d97410 Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Tue, 9 Jan 2024 13:24:05 -0500 Subject: [PATCH] chore(scripts): add logging to metadata-to-json script --- scripts/metadata-to-json.js | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/scripts/metadata-to-json.js b/scripts/metadata-to-json.js index ffc70589..9d8fc7b2 100644 --- a/scripts/metadata-to-json.js +++ b/scripts/metadata-to-json.js @@ -22,23 +22,26 @@ const headers = { const metadataPath = process.argv[2] || '/dev/stdin'; const workbook = xlsx.readFileSync(metadataPath); -const items = Object.entries(workbook.Sheets).flatMap(([sheetName, sheet]) => { - if (EXCLUDE_SHEETS.has(sheetName)) { - return []; - } - - return xlsx.utils.sheet_to_json(sheet) - .filter(item => item[headers["ethnicity"]] !== "Exclude sample") - .map(item => Object.fromEntries( - Object.entries(headers) - .filter(([_, oldKey]) => item[oldKey] !== undefined) - .map(([key, oldKey]) => ( - // Preprocess and remove 'Chipmentation' from assay names if necessary - oldKey === "assay.name" - ? [key, item[oldKey].replace("Chipmentation ", "")] - : [key, item[oldKey]] - )) - )); +const sheets = Object.entries(workbook.Sheets).filter(([s, _]) => !EXCLUDE_SHEETS.has(s)); + +process.stderr.write(`Found sheets: ${sheets.map((s) => s[0]).join(', ')}\n`); + +const items = sheets.flatMap(([sheetName, sheet]) => { + const sheetEntries = xlsx.utils.sheet_to_json(sheet) + .filter(item => item[headers["ethnicity"]] !== "Exclude sample"); + + process.stderr.write(` ${sheetName}: found ${sheetEntries.length} rows\n`); + + return sheetEntries.map(item => Object.fromEntries( + Object.entries(headers) + .filter(([_, oldKey]) => item[oldKey] !== undefined) + .map(([key, oldKey]) => ( + // Preprocess and remove 'Chipmentation' from assay names if necessary + oldKey === "assay.name" + ? [key, item[oldKey].replace("Chipmentation ", "")] + : [key, item[oldKey]] + )) + )); }); process.stdout.write(JSON.stringify(items, null, 2) + "\n");