Skip to content

Commit

Permalink
🔧 Upset: Add topN param and change sets naming for elems (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
evans-g-crsj authored Jan 13, 2025
1 parent 0c6ed64 commit 03b5133
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/endpoints/upset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
9 changes: 5 additions & 4 deletions src/endpoints/upset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import EsInstance from '../ElasticSearchClientInstance';

export type UpsetData = {
name: string;
sets: string[];
elems: string[];
}[];

export const countIt = (xs: string[]): Map<string, number> => {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
};
});

Expand Down

0 comments on commit 03b5133

Please sign in to comment.