From 83372a4b0538b45415c657f2c43be4409f8f2e42 Mon Sep 17 00:00:00 2001 From: Celine Pelletier Date: Mon, 6 Nov 2023 11:18:37 -0500 Subject: [PATCH] feat: SKFP-848 add file manifest for Include --- src/reports/file-manifest/configInclude.ts | 91 +++++++++++++++++++ .../file-manifest/{config.ts => configKf.ts} | 0 src/reports/file-manifest/index.ts | 18 +++- 3 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 src/reports/file-manifest/configInclude.ts rename src/reports/file-manifest/{config.ts => configKf.ts} (100%) diff --git a/src/reports/file-manifest/configInclude.ts b/src/reports/file-manifest/configInclude.ts new file mode 100644 index 0000000..f944673 --- /dev/null +++ b/src/reports/file-manifest/configInclude.ts @@ -0,0 +1,91 @@ +import { formatFileSize } from '../../utils/formatFileSize'; +import { SheetConfig } from '../types'; + +type BiospecimenData = { + family?: { family_id?: string }; + sample_id?: string; + external_sample_id?: string; + container_id?: string; + external_collection_sample_id?: string; +}; +type ParticipantsData = { + biospecimens: BiospecimenData[]; +}[]; +const processBiospecimens = (participants: ParticipantsData, key: keyof BiospecimenData): string[] => + Array.from( + new Set( + (participants || []) + .map(x => x?.biospecimens || []) + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + //@ts-ignore + .flat() + .map(x => x[key]) + .filter(x => !!x), + ), + ); + +const config: SheetConfig = { + sheetName: 'Files', + root: null, + columns: [ + { field: 'access_urls', header: 'Access URL' }, + { + field: 'file_id', + header: 'File ID', + }, + { field: 'file_name', header: 'File Name' }, + { field: 'size', header: 'File Size', transform: value => formatFileSize(value, { output: 'string' }) }, + { field: 'data_category', header: 'Data Category' }, + { field: 'data_type', header: 'Data Type' }, + { field: 'file_format', header: 'File Format' }, + { field: 'sequencing_experiment.experiment_strategy', header: 'Experimental Strategy' }, + { field: 'hashes.md5', header: 'Hash' }, + { field: 'study.study_name', header: 'Study Name' }, + { field: 'participants.participant_id', header: 'Participant ID' }, + { + fieldExtraSuffix: '_sample_id', + field: 'participants', + header: 'Sample ID', + transform: participants => processBiospecimens(participants, 'sample_id'), + }, + { + fieldExtraSuffix: '_container_id', + field: 'participants', + header: 'INCLUDE Container ID', + transform: participants => processBiospecimens(participants, 'container_id'), + }, + { + fieldExtraSuffix: '_down_syndrome_status', + field: 'participants', + header: 'Down Syndrome Status', + transform: participants => (participants || []).map(x => x?.down_syndrome_status ?? ''), + }, + { + fieldExtraSuffix: '_family', + field: 'participants', + header: 'Family ID', + transform: participants => (participants || []).map(x => x?.family?.family_id ?? ''), + }, + { + fieldExtraSuffix: '_external_id', + field: 'participants', + header: 'External Participant ID', + transform: participants => (participants || []).map(x => x?.external_id ?? ''), + }, + { + fieldExtraSuffix: '_external_sample_id', + field: 'participants', + header: 'External Sample ID', + transform: participants => processBiospecimens(participants, 'external_sample_id'), + }, + { + fieldExtraSuffix: '_external_collection_sample_id', + field: 'participants', + header: 'External Collection ID', + transform: participants => processBiospecimens(participants, 'external_collection_sample_id'), + }, + ], + sort: [{ file_id: { order: 'asc' } }], +}; + +export default config; diff --git a/src/reports/file-manifest/config.ts b/src/reports/file-manifest/configKf.ts similarity index 100% rename from src/reports/file-manifest/config.ts rename to src/reports/file-manifest/configKf.ts diff --git a/src/reports/file-manifest/index.ts b/src/reports/file-manifest/index.ts index 28a84b9..fc723e6 100644 --- a/src/reports/file-manifest/index.ts +++ b/src/reports/file-manifest/index.ts @@ -7,8 +7,10 @@ import generateTsvReport from '../utils/generateTsvReport'; import getFamilyIds from '../utils/getFamilyIds'; import getFilesFromSqon from '../utils/getFilesFromSqon'; import getInfosByConfig from '../utils/getInfosByConfig'; -import config from './config'; -import { esFileIndex } from '../../env'; +import configKf from './configKf'; +import configInclude from './configInclude'; +import { PROJECT, esFileIndex } from '../../env'; +import { ProjectType } from '../types'; const fileManifestReport = async (req: Request, res: Response): Promise => { console.time('fileManifestReport'); @@ -17,6 +19,14 @@ const fileManifestReport = async (req: Request, res: Response): Promise => const userId = req['kauth']?.grant?.access_token?.content?.sub; const accessToken = req.headers.authorization; + let reportConfig; + const p = PROJECT.toLowerCase().trim(); + if (p === ProjectType.include) { + reportConfig = configInclude; + } else { + reportConfig = configKf; + } + const wantedFields = ['file_id']; const esClient = EsInstance.getInstance(); @@ -26,10 +36,10 @@ const fileManifestReport = async (req: Request, res: Response): Promise => const fileIds = files?.map(f => f.file_id); const newFileIds = withFamily ? await getFamilyIds(esClient, fileIds) : fileIds; - const filesInfos = await getInfosByConfig(esClient, config, newFileIds, 'file_id', esFileIndex); + const filesInfos = await getInfosByConfig(esClient, reportConfig, newFileIds, 'file_id', esFileIndex); const path = `/tmp/${filename}.tsv`; - await generateTsvReport(filesInfos, path, config); + await generateTsvReport(filesInfos, path, reportConfig); res.setHeader('Content-Disposition', `attachment; filename="${filename}.tsv"`); res.sendFile(path);