From b75d72ebdc7d15d9aeb68d4cd50f3462e10336b8 Mon Sep 17 00:00:00 2001 From: John Conroy Date: Mon, 11 Jan 2021 16:00:54 -0500 Subject: [PATCH 1/7] Add checkParameters method --- src/internal.ts | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/internal.ts diff --git a/src/internal.ts b/src/internal.ts new file mode 100644 index 0000000..cf2c4c3 --- /dev/null +++ b/src/internal.ts @@ -0,0 +1,76 @@ +interface InputTypes { + cell: string[]; + organ: string[]; + gene: string[]; + cluster: string[]; +} + +class Client { + constructor(baseUrl) { + // https://cells.dev.hubmapconsortium.org/api/' + this.basePath = baseUrl; + } + + static checkParameters( + inputType: string, + outputType: string, + inputSet: string[], + genomicModality: string, + pValue: number = 0.05, + ): void { + const outputTypes: string[] = ['cell', 'organ', 'gene', 'cluster']; + + if (!outputTypes.includes(outputType)) { + throw new Error(`${outputType} not in ${outputTypes}`); + } + + const inputTypes: InputTypes = { + // Allowed input types vary depending on output type + cell: ['gene', 'organ', 'protein', 'dataset'], + organ: ['cell', 'gene'], + gene: ['organ', 'cluster'], + cluster: ['gene'], + }; + + if (!inputTypes[outputType].includes(inputType)) { + throw new Error(`${inputType} not in ${inputTypes[outputType]}`); + } + + const genomicModalities: string[] = ['rna', 'atac']; // Used for quantitative gene->cell queries + if (inputType === 'gene' && outputType === 'cell' && !genomicModalities.includes(genomicModality)) { + throw new Error(`${genomicModality} not in ${genomicModalities}`); + } + + if ( + (((inputType === 'organ' && outputType === 'gene') || (inputType === 'gene' && outputType === 'organ')) && + pValue < 0) || + pValue > 1 + ) { + throw new Error(`p_value ${pValue} should be in [0,1]`); + } + } + + /* + fillRequestObject() {} + + hubmapQuery() {} + + setIntersection() {} + + setUnion() {} + + setDifference() {} + + operation() {} + + checkDetailParameters() {} + + setCount() {} + + setListEvaluation() {} + + setDetailEvaluation() {} + */ +} + +export default Client; From 65a72872b1eb3f485dc7e3d8f397067023732f7b Mon Sep 17 00:00:00 2001 From: John Conroy Date: Mon, 11 Jan 2021 17:06:07 -0500 Subject: [PATCH 2/7] Stash --- src/__tests__/checkParameters.spec.ts | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/__tests__/checkParameters.spec.ts diff --git a/src/__tests__/checkParameters.spec.ts b/src/__tests__/checkParameters.spec.ts new file mode 100644 index 0000000..a66020e --- /dev/null +++ b/src/__tests__/checkParameters.spec.ts @@ -0,0 +1,7 @@ +import Client from '../internal'; + +test('Dummy unit test', () => { + it('should throw an error', () => { + expect(Client.checkParameters()).toThrowError('my error'); + }); +}); From 79982c23f39176f59f1a3d9efdec108f57edb543 Mon Sep 17 00:00:00 2001 From: John Conroy Date: Tue, 12 Jan 2021 15:27:28 -0500 Subject: [PATCH 3/7] Update jest config to isolate typescript tests --- jest.config.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jest.config.js b/jest.config.js index 35556f3..efd3d7e 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,4 +4,9 @@ module.exports = { transform: { '^.+\\.(ts)$': 'ts-jest', }, + globals: { + 'ts-jest': { + isolatedModules: true, + }, + }, }; From 6875504e1ba78a36b73aec5527391ea640212593 Mon Sep 17 00:00:00 2001 From: John Conroy Date: Tue, 12 Jan 2021 15:28:35 -0500 Subject: [PATCH 4/7] Pull out internal consts and types into separate files --- src/{internal.ts => internal/index.ts} | 39 +++++++++----------------- src/internal/internal.config.ts | 15 ++++++++++ src/internal/internal.types.ts | 16 +++++++++++ 3 files changed, 44 insertions(+), 26 deletions(-) rename src/{internal.ts => internal/index.ts} (57%) create mode 100644 src/internal/internal.config.ts create mode 100644 src/internal/internal.types.ts diff --git a/src/internal.ts b/src/internal/index.ts similarity index 57% rename from src/internal.ts rename to src/internal/index.ts index cf2c4c3..8bcccec 100644 --- a/src/internal.ts +++ b/src/internal/index.ts @@ -1,42 +1,29 @@ -interface InputTypes { - cell: string[]; - organ: string[]; - gene: string[]; - cluster: string[]; -} +import { CheckParametersTypes } from './internal.types'; +import { outputTypes, inputTypes, genomicModalities } from './internal.config'; class Client { - constructor(baseUrl) { + baseUrl: string; + + constructor(baseUrl: string) { // https://cells.dev.hubmapconsortium.org/api/' - this.basePath = baseUrl; + this.baseUrl = baseUrl; } - static checkParameters( - inputType: string, - outputType: string, - inputSet: string[], - genomicModality: string, - pValue: number = 0.05, - ): void { - const outputTypes: string[] = ['cell', 'organ', 'gene', 'cluster']; - + static checkParameters({ + inputType, + outputType, + // inputSet, + genomicModality, + pValue = 0.05, + }: CheckParametersTypes): void { if (!outputTypes.includes(outputType)) { throw new Error(`${outputType} not in ${outputTypes}`); } - const inputTypes: InputTypes = { - // Allowed input types vary depending on output type - cell: ['gene', 'organ', 'protein', 'dataset'], - organ: ['cell', 'gene'], - gene: ['organ', 'cluster'], - cluster: ['gene'], - }; - if (!inputTypes[outputType].includes(inputType)) { throw new Error(`${inputType} not in ${inputTypes[outputType]}`); } - const genomicModalities: string[] = ['rna', 'atac']; // Used for quantitative gene->cell queries if (inputType === 'gene' && outputType === 'cell' && !genomicModalities.includes(genomicModality)) { throw new Error(`${genomicModality} not in ${genomicModalities}`); } diff --git a/src/internal/internal.config.ts b/src/internal/internal.config.ts new file mode 100644 index 0000000..0abd1a4 --- /dev/null +++ b/src/internal/internal.config.ts @@ -0,0 +1,15 @@ +import { InputTypes } from './internal.types'; + +const outputTypes: string[] = ['cell', 'organ', 'gene', 'cluster']; + +const inputTypes: InputTypes = { + // Allowed input types vary depending on output type + cell: ['gene', 'organ', 'protein', 'dataset'], + organ: ['cell', 'gene'], + gene: ['organ', 'cluster'], + cluster: ['gene'], +}; + +const genomicModalities: string[] = ['rna', 'atac']; // Used for quantitative gene->cell queries + +export { outputTypes, inputTypes, genomicModalities }; diff --git a/src/internal/internal.types.ts b/src/internal/internal.types.ts new file mode 100644 index 0000000..d072c14 --- /dev/null +++ b/src/internal/internal.types.ts @@ -0,0 +1,16 @@ +interface InputTypes { + cell: string[]; + organ: string[]; + gene: string[]; + cluster: string[]; +} + +interface CheckParametersTypes { + inputType: string; + outputType: keyof InputTypes; + // inputSet: string[]; + genomicModality: string; + pValue?: number; +} + +export { InputTypes, CheckParametersTypes }; From 65282f4e3ec30051343ba65783c6dcc18fb19d35 Mon Sep 17 00:00:00 2001 From: John Conroy Date: Tue, 12 Jan 2021 15:28:55 -0500 Subject: [PATCH 5/7] Add check parameters tests --- src/__tests__/checkParameters.spec.ts | 109 +++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 4 deletions(-) diff --git a/src/__tests__/checkParameters.spec.ts b/src/__tests__/checkParameters.spec.ts index a66020e..46177b8 100644 --- a/src/__tests__/checkParameters.spec.ts +++ b/src/__tests__/checkParameters.spec.ts @@ -1,7 +1,108 @@ import Client from '../internal'; +import { InputTypes } from '../internal/internal.types'; +import { inputTypes, outputTypes, genomicModalities } from '../internal/internal.config'; -test('Dummy unit test', () => { - it('should throw an error', () => { - expect(Client.checkParameters()).toThrowError('my error'); - }); +interface CheckParametersArguments { + inputType: string; + outputType: keyof InputTypes; + // inputSet: string[]; + genomicModality: string; + pValue?: number; +} + +it('should not throw an error', () => { + const testObj: CheckParametersArguments = { + inputType: 'cell', + outputType: 'organ', + // inputSet: [], + genomicModality: 'fake', + }; + expect(() => Client.checkParameters(testObj)).not.toThrow(); +}); + +it('should throw an error when output type is not in output types', () => { + interface FakeCheckParametersArguments { + inputType: string; + outputType: string; + // inputSet: string[]; + genomicModality: string; + pValue?: number; + } + + const outputType: string = 'fake'; + const testObj: FakeCheckParametersArguments = { + inputType: 'cell', + outputType, + // inputSet: [], + genomicModality: 'fake', + }; + expect(() => Client.checkParameters(testObj)).toThrow(`${outputType} not in ${outputTypes}`); +}); + +it('should throw an error when input type does correspond to output type', () => { + const inputType: string = 'protein'; + const outputType: string = 'organ'; + const testObj: CheckParametersArguments = { + inputType, + outputType, + // inputSet: [], + genomicModality: 'fake', + }; + expect(() => Client.checkParameters(testObj)).toThrow(`${inputType} not in ${inputTypes[outputType]}`); +}); + +it('should not throw an error when input type is gene and output type is cell', () => { + const testObj: CheckParametersArguments = { + inputType: 'gene', + outputType: 'cell', + // inputSet: [], + genomicModality: 'rna', + }; + expect(() => Client.checkParameters(testObj)).not.toThrow(); +}); + +it('should throw an error when input type is gene and output type is cell and genomic modality is not rna or atac', () => { + const genomicModality: string = 'fake'; + const testObj: CheckParametersArguments = { + inputType: 'gene', + outputType: 'cell', + // inputSet: [], + genomicModality, + }; + expect(() => Client.checkParameters(testObj)).toThrow(`${genomicModality} not in ${genomicModalities}`); +}); + +it('should not throw an error when input type is gene and output type is organ and p value within bounds', () => { + const testObj: CheckParametersArguments = { + inputType: 'gene', + outputType: 'cell', + // inputSet: [], + genomicModality: 'atac', + pValue: 0.2, + }; + expect(() => Client.checkParameters(testObj)).not.toThrow(); +}); + +it('should throw an error when input type is gene and output type is cell and p value is less than 0', () => { + const pValue: number = -0.1; + const testObj: CheckParametersArguments = { + inputType: 'gene', + outputType: 'organ', + // inputSet: [], + genomicModality: 'atac', + pValue, + }; + expect(() => Client.checkParameters(testObj)).toThrow(`p_value ${pValue} should be in [0,1]`); +}); + +it('should throw an error when input type is cell and output type is gene and p value is greater than 0', () => { + const pValue: number = 1.2; + const testObj: CheckParametersArguments = { + inputType: 'organ', + outputType: 'gene', + // inputSet: [], + genomicModality: 'atac', + pValue, + }; + expect(() => Client.checkParameters(testObj)).toThrow(`p_value ${pValue} should be in [0,1]`); }); From 860ecdd09934bf271ec7bfe5187413abc10ff59a Mon Sep 17 00:00:00 2001 From: John Conroy Date: Tue, 12 Jan 2021 15:31:00 -0500 Subject: [PATCH 6/7] Remove example code --- src/__tests__/example.spec.ts | 6 ------ src/example.ts | 5 ----- src/index.ts | 6 ++++-- 3 files changed, 4 insertions(+), 13 deletions(-) delete mode 100644 src/__tests__/example.spec.ts delete mode 100644 src/example.ts diff --git a/src/__tests__/example.spec.ts b/src/__tests__/example.spec.ts deleted file mode 100644 index 076d588..0000000 --- a/src/__tests__/example.spec.ts +++ /dev/null @@ -1,6 +0,0 @@ -import sum from '../example'; - -test('Dummy unit test', () => { - const actual: number = sum(1, 2); - expect(actual).toBe(3); -}); diff --git a/src/example.ts b/src/example.ts deleted file mode 100644 index 3cc090d..0000000 --- a/src/example.ts +++ /dev/null @@ -1,5 +0,0 @@ -const sum = (a: number, b: number) => { - return a + b; -}; - -export default sum; diff --git a/src/index.ts b/src/index.ts index 5091123..655bdbb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,4 @@ -// eslint-disable-next-line -export const greet = () => console.log('Hello, world!'); +import Client from './internal'; + +// eslint-disable-next-line import/prefer-default-export +export { Client }; From f0babc8200d738a62f59f88c6d2dbf44fbe81299 Mon Sep 17 00:00:00 2001 From: John Conroy Date: Tue, 12 Jan 2021 15:32:36 -0500 Subject: [PATCH 7/7] Fix CheckParametersArguments interface --- src/__tests__/checkParameters.spec.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/__tests__/checkParameters.spec.ts b/src/__tests__/checkParameters.spec.ts index 46177b8..2073e46 100644 --- a/src/__tests__/checkParameters.spec.ts +++ b/src/__tests__/checkParameters.spec.ts @@ -1,10 +1,9 @@ import Client from '../internal'; -import { InputTypes } from '../internal/internal.types'; import { inputTypes, outputTypes, genomicModalities } from '../internal/internal.config'; interface CheckParametersArguments { inputType: string; - outputType: keyof InputTypes; + outputType: string; // inputSet: string[]; genomicModality: string; pValue?: number;