From 03b5133404eb33127f2e444860e2e30482df64c1 Mon Sep 17 00:00:00 2001 From: Evans Girard <54366437+evans-g-crsj@users.noreply.github.com> Date: Mon, 13 Jan 2025 13:50:40 -0500 Subject: [PATCH] :wrench: Upset: Add topN param and change sets naming for elems (#231) --- src/app.ts | 2 +- src/endpoints/upset.test.ts | 10 +++++----- src/endpoints/upset.ts | 9 +++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/app.ts b/src/app.ts index 5ce3415..112516c 100644 --- a/src/app.ts +++ b/src/app.ts @@ -196,7 +196,7 @@ export default (keycloak: Keycloak, getProject: (projectId: string) => ArrangerP app.post('/upset', keycloak.protect(), async (req, res, next) => { try { - const data = await computeUpset(req.body.sqon); + const data = await computeUpset(req.body.sqon, req.body.topN); res.send(data); } catch (e) { next(e); diff --git a/src/endpoints/upset.test.ts b/src/endpoints/upset.test.ts index 1c103e0..95a5ee8 100644 --- a/src/endpoints/upset.test.ts +++ b/src/endpoints/upset.test.ts @@ -263,13 +263,13 @@ describe('Upset', () => { ], op: 'and', }; - const result = await computeUpset(sqon); + const result = await computeUpset(sqon, 5); expect(result).toEqual({ data: [ - { name: 'Abnormality of the eye (HP:0000478)', sets: ['pt-223twf8ytr', 'pt-2282xh6dem'] }, - { name: 'Seizure (HP:0001250)', sets: ['pt-223twf8ytr'] }, - { name: 'Ventricular septal defect (HP:0001629)', sets: ['pt-2282xh6dem'] }, - { name: 'Abnormality of the dentition (HP:0000164)', sets: ['pt-2282xh6dem'] }, + { name: 'Abnormality of the eye (HP:0000478)', elems: ['pt-223twf8ytr', 'pt-2282xh6dem'] }, + { name: 'Seizure (HP:0001250)', elems: ['pt-223twf8ytr'] }, + { name: 'Ventricular septal defect (HP:0001629)', elems: ['pt-2282xh6dem'] }, + { name: 'Abnormality of the dentition (HP:0000164)', elems: ['pt-2282xh6dem'] }, ], participantsCount: 2, }); diff --git a/src/endpoints/upset.ts b/src/endpoints/upset.ts index 5b89508..5f487eb 100644 --- a/src/endpoints/upset.ts +++ b/src/endpoints/upset.ts @@ -5,7 +5,7 @@ import EsInstance from '../ElasticSearchClientInstance'; export type UpsetData = { name: string; - sets: string[]; + elems: string[]; }[]; export const countIt = (xs: string[]): Map => { @@ -48,9 +48,10 @@ const emptySQON = { content: [], }; -const TOP = 20; +const DEFAULT_TOP = 10; export const computeUpset = async ( sqon = emptySQON, + topMax = DEFAULT_TOP, ): Promise<{ data: UpsetData; participantsCount: number; @@ -108,13 +109,13 @@ export const computeUpset = async ( const allQueryPhenotypes: string[] = ps.map(x => x.ph).flat(); //countIt is sorted by descending counts - const top = topN(countIt(allQueryPhenotypes), TOP); + const top = topN(countIt(allQueryPhenotypes), topMax > 0 && topMax <= 25 ? topMax : DEFAULT_TOP); const data = top.map(x => { const pts = ps.reduce((ys, y) => (y.ph.includes(x) ? [...ys, y.patient] : ys), []); return { name: x, - sets: pts, + elems: pts, }; });