Skip to content
This repository was archived by the owner on Jun 11, 2022. It is now read-only.
Open
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
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ module.exports = {
transform: {
'^.+\\.(ts)$': 'ts-jest',
},
globals: {
'ts-jest': {
isolatedModules: true,
},
},
};
107 changes: 107 additions & 0 deletions src/__tests__/checkParameters.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import Client from '../internal';
import { inputTypes, outputTypes, genomicModalities } from '../internal/internal.config';

interface CheckParametersArguments {
inputType: string;
outputType: string;
// 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]`);
});
6 changes: 0 additions & 6 deletions src/__tests__/example.spec.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/example.ts

This file was deleted.

6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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 };
63 changes: 63 additions & 0 deletions src/internal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { CheckParametersTypes } from './internal.types';
import { outputTypes, inputTypes, genomicModalities } from './internal.config';

class Client {
baseUrl: string;

constructor(baseUrl: string) {
// https://cells.dev.hubmapconsortium.org/api/'
this.baseUrl = baseUrl;
}

static checkParameters({
inputType,
outputType,
// inputSet,
genomicModality,
pValue = 0.05,
}: CheckParametersTypes): void {
if (!outputTypes.includes(outputType)) {
throw new Error(`${outputType} not in ${outputTypes}`);
}

if (!inputTypes[outputType].includes(inputType)) {
throw new Error(`${inputType} not in ${inputTypes[outputType]}`);
}

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;
15 changes: 15 additions & 0 deletions src/internal/internal.config.ts
Original file line number Diff line number Diff line change
@@ -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 };
16 changes: 16 additions & 0 deletions src/internal/internal.types.ts
Original file line number Diff line number Diff line change
@@ -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 };