Skip to content

Commit

Permalink
feat: SKFP-848 add file manifest for Include
Browse files Browse the repository at this point in the history
  • Loading branch information
celinepelletier committed Nov 6, 2023
1 parent de011be commit b6ace2b
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 4 deletions.
91 changes: 91 additions & 0 deletions src/reports/file-manifest/configInclude.ts
Original file line number Diff line number Diff line change
@@ -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;
File renamed without changes.
18 changes: 14 additions & 4 deletions src/reports/file-manifest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
console.time('fileManifestReport');
Expand All @@ -17,6 +19,14 @@ const fileManifestReport = async (req: Request, res: Response): Promise<void> =>
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();
Expand All @@ -26,10 +36,10 @@ const fileManifestReport = async (req: Request, res: Response): Promise<void> =>
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);
Expand Down

0 comments on commit b6ace2b

Please sign in to comment.