Skip to content

Commit

Permalink
Merge pull request #59 from molgenis/feat/treejson
Browse files Browse the repository at this point in the history
Add decision tree json to api
  • Loading branch information
dennishendriksen authored Jul 1, 2021
2 parents b1254bf + 7a2c294 commit 92d3127
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/ApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface BinaryData extends BinaryDataNode {
fastaGz?: BinaryDataNode;
genesGz?: Buffer;
bam?: BinaryDataNode;
decisionTree?: Buffer;
}

interface BinaryDataNode {
Expand Down Expand Up @@ -97,6 +98,11 @@ export class ApiClient implements Api {
return Promise.resolve(sampleBam !== undefined ? sampleBam : null);
}

getDecisionTree(): Promise<Buffer | null> {
const decisionTree = this.reportData.binary.decisionTree;
return Promise.resolve(decisionTree ? decisionTree : null);
}

private get<T extends Resource>(resource: string, params: Params = {}): Promise<PagedItems<T>> {
return new Promise((resolve, reject) => {
if (!this.reportData.data[resource]) {
Expand Down
1 change: 1 addition & 0 deletions src/ApiData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface EncodedData extends EncodedDataContainer {
fastaGz?: EncodedDataContainer;
genesGz?: string;
bam?: EncodedDataContainer;
decisionTree?: string;
}

export interface Resource {
Expand Down
26 changes: 25 additions & 1 deletion src/__tests__/ApiClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ beforeEach(() => {
)
},
genesGz: new Base85().encode(Buffer.from(gzipSync(fs.readFileSync(__dirname + '/example.gff')))),
bam: { Patient: new Base85().encode(Buffer.from('dummy bam content', 'utf8')) }
bam: { Patient: new Base85().encode(Buffer.from('dummy bam content', 'utf8'))},
decisionTree: new Base85().encode(Buffer.from(fs.readFileSync(__dirname + '/tree.json'))),
}
};
api = new ApiClient(reportData);
Expand Down Expand Up @@ -721,4 +722,27 @@ test('getBam - undefined', async () => {
api = new ApiClient(reportData);
const bam = await api.getBam('Patient');
expect(bam).toBe(null);
}

);

test('getDecisionTree', async () => {
const decisionTree = await api.getDecisionTree();
// null check, because size check differs between local machine and Travis
expect(decisionTree).not.toBe(null);
});

test('getDecisionTree - undefined', async () => {
const reportData = {
metadata: jest.fn() as unknown as Metadata,
data: jest.fn() as unknown as Data,
base85: {
vcfGz: new Base85().encode(Buffer.from(gzipSync(fs.readFileSync(__dirname + '/trio.vcf'))))
}
};

api = new ApiClient(reportData);
const decisionTree = await api.getDecisionTree();
expect(decisionTree).toBe(null);
});

76 changes: 76 additions & 0 deletions src/__tests__/tree.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"rootNode": "filter",
"nodes": {
"filter": {
"type": "BOOL",
"description": "All filters passed",
"query": {
"field": "FILTER",
"operator": "==",
"value": [
"PASS"
]
},
"outcomeTrue": {
"nextNode": "vkgl"
},
"outcomeFalse": {
"nextNode": "exit_f"
},
"outcomeMissing": {
"nextNode": "vkgl"
}
},
"vkgl": {
"type": "CATEGORICAL",
"description": "VKGL classification",
"field": "INFO/VKGL",
"outcomeMap": {
"P": {
"nextNode": "exit_t"
},
"LP": {
"nextNode": "exit_t"
},
"LB": {
"nextNode": "exit_f"
},
"B": {
"nextNode": "exit_f"
}
},
"outcomeMissing": {
"nextNode": "capice"
},
"outcomeDefault": {
"nextNode": "capice"
}
},
"capice": {
"type": "BOOL",
"description": "CAPICE score >= 0.02",
"query": {
"field": "INFO/CAP",
"operator": ">=",
"value": 0.02
},
"outcomeTrue": {
"nextNode": "exit_t"
},
"outcomeFalse": {
"nextNode": "exit_f"
},
"outcomeMissing": {
"nextNode": "exit_t"
}
},
"exit_t": {
"type": "LEAF",
"class": "T"
},
"exit_f": {
"type": "LEAF",
"class": "F"
}
}
}

0 comments on commit 92d3127

Please sign in to comment.