Skip to content

Commit

Permalink
chore(scripts): add logging to metadata-to-json script
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Jan 9, 2024
1 parent d3a0339 commit aecd4db
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions scripts/metadata-to-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

0 comments on commit aecd4db

Please sign in to comment.