From 7078ec092ad83f10855d800a963fbe23aae8d73a Mon Sep 17 00:00:00 2001 From: John Conroy Date: Wed, 13 Jan 2021 10:36:37 -0500 Subject: [PATCH 1/4] Add fillRequestObject method --- src/internal/index.ts | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/internal/index.ts b/src/internal/index.ts index 8bcccec..00e4a85 100644 --- a/src/internal/index.ts +++ b/src/internal/index.ts @@ -1,4 +1,4 @@ -import { CheckParametersTypes } from './internal.types'; +import { CheckParametersTypes, RequestObjectTypes } from './internal.types'; import { outputTypes, inputTypes, genomicModalities } from './internal.config'; class Client { @@ -37,9 +37,27 @@ class Client { } } - /* - fillRequestObject() {} + static fillRequestObject({ + inputType, + outputType, + inputSet, + genomicModality, + pValue, + }: CheckParametersTypes): RequestObjectTypes { + const requestObject = { input_type: inputType, input_set: inputSet }; + + if (['organ', 'gene'].includes(inputType) && outputType === 'gene') { + requestObject.p_value = pValue; + } + + if (genomicModality) { + requestObject.genomic_modality = genomicModality; + } + requestObject.logical_operator = 'and'; + return requestObject; + } + /* hubmapQuery() {} setIntersection() {} From 22684c1dbe7c5a1e7c9d9e312a3b5e3df17ed85c Mon Sep 17 00:00:00 2001 From: John Conroy Date: Wed, 13 Jan 2021 10:36:53 -0500 Subject: [PATCH 2/4] Modify types --- src/internal/internal.types.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/internal/internal.types.ts b/src/internal/internal.types.ts index d072c14..2a296b2 100644 --- a/src/internal/internal.types.ts +++ b/src/internal/internal.types.ts @@ -8,9 +8,18 @@ interface InputTypes { interface CheckParametersTypes { inputType: string; outputType: keyof InputTypes; - // inputSet: string[]; - genomicModality: string; + inputSet?: string[]; + genomicModality?: string; pValue?: number; } +interface RequestObjectTypes { + /* eslint-disable camelcase */ + input_type: string; + input_set: string[]; + genomic_modality?: string; + p_value?: number; + logical_operator: 'and'; + /* eslint-enable camelcase */ +} -export { InputTypes, CheckParametersTypes }; +export { InputTypes, CheckParametersTypes, RequestObjectTypes }; From 63436f3c8f156c138d91dfb2d382665a39ddb2c1 Mon Sep 17 00:00:00 2001 From: John Conroy Date: Wed, 13 Jan 2021 10:37:21 -0500 Subject: [PATCH 3/4] Add fileRequestObject tests --- src/__tests__/fillRequestObject.spec.ts | 59 +++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/__tests__/fillRequestObject.spec.ts diff --git a/src/__tests__/fillRequestObject.spec.ts b/src/__tests__/fillRequestObject.spec.ts new file mode 100644 index 0000000..a9c29da --- /dev/null +++ b/src/__tests__/fillRequestObject.spec.ts @@ -0,0 +1,59 @@ +import Client from '../internal'; +import { CheckParametersTypes } from '../internal/internal.types'; + +it('should return an object with input type, input set, and logical operator when only the required arguments are provided', () => { + const inputType: string = 'cell'; + const outputType: string = 'organ'; + const inputSet: string[] = ['fake']; + + const testObj: CheckParametersTypes = { + inputType, + outputType, + inputSet, + }; + expect(Client.fillRequestObject(testObj)).toEqual({ + input_type: inputType, + input_set: inputSet, + logical_operator: 'and', + }); +}); + +it('should return an object with a p value when input type is organ or gene and output type is gene', () => { + const inputType: string = 'organ'; + const outputType: string = 'gene'; + const inputSet: string[] = ['fake']; + const pValue: number = 0.4; + + const testObj: CheckParametersTypes = { + inputType, + outputType, + pValue, + inputSet, + }; + expect(Client.fillRequestObject(testObj)).toEqual({ + input_type: inputType, + input_set: inputSet, + p_value: pValue, + logical_operator: 'and', + }); +}); + +it('should return an object with a genomic modality if it is defined', () => { + const inputType: string = 'organ'; + const outputType: string = 'cell'; + const inputSet: string[] = ['fake']; + const genomicModality: string = 'fake'; + + const testObj: CheckParametersTypes = { + inputType, + outputType, + genomicModality, + inputSet, + }; + expect(Client.fillRequestObject(testObj)).toEqual({ + input_type: inputType, + input_set: inputSet, + genomic_modality: genomicModality, + logical_operator: 'and', + }); +}); From 2a0e315848d8096be4bebe505226da12b13cf590 Mon Sep 17 00:00:00 2001 From: John Conroy Date: Wed, 13 Jan 2021 10:56:07 -0500 Subject: [PATCH 4/4] Fix request object parameters types --- src/internal/index.ts | 4 ++-- src/internal/internal.types.ts | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/internal/index.ts b/src/internal/index.ts index 00e4a85..bfd4d2f 100644 --- a/src/internal/index.ts +++ b/src/internal/index.ts @@ -1,4 +1,4 @@ -import { CheckParametersTypes, RequestObjectTypes } from './internal.types'; +import { CheckParametersTypes, RequestObjectParametersTypes, RequestObjectTypes } from './internal.types'; import { outputTypes, inputTypes, genomicModalities } from './internal.config'; class Client { @@ -43,7 +43,7 @@ class Client { inputSet, genomicModality, pValue, - }: CheckParametersTypes): RequestObjectTypes { + }: RequestObjectParametersTypes): RequestObjectTypes { const requestObject = { input_type: inputType, input_set: inputSet }; if (['organ', 'gene'].includes(inputType) && outputType === 'gene') { diff --git a/src/internal/internal.types.ts b/src/internal/internal.types.ts index 2a296b2..1ed95ad 100644 --- a/src/internal/internal.types.ts +++ b/src/internal/internal.types.ts @@ -12,6 +12,14 @@ interface CheckParametersTypes { genomicModality?: string; pValue?: number; } + +interface RequestObjectParametersTypes { + inputType: string; + outputType: keyof InputTypes; + inputSet: string[]; + genomicModality?: string; + pValue?: number; +} interface RequestObjectTypes { /* eslint-disable camelcase */ input_type: string; @@ -22,4 +30,4 @@ interface RequestObjectTypes { /* eslint-enable camelcase */ } -export { InputTypes, CheckParametersTypes, RequestObjectTypes }; +export { InputTypes, CheckParametersTypes, RequestObjectParametersTypes, RequestObjectTypes };