Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 Upset: Add topN param and change sets naming for elems #231

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading