mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-25 23:28:11 +08:00
* Disabled @blueprintjs/classes-constants. #2288. * thuang-eslint-bp-off (#2344) * Disabled @blueprintjs/classes-constants on webpack dev and shared. #2288. * Added TS recommended, suppress lint errors codemod. * Added per-error/warning ignore for tests. * Added per-error/warning ignore for configuration. * Added per-error/warning ignore for src. Removed suppress package. * Minor linting. Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com>
81 lines
3.1 KiB
TypeScript
81 lines
3.1 KiB
TypeScript
import cloneDeep from "lodash.clonedeep";
|
|
|
|
import calcCentroid from "../../src/util/centroid";
|
|
import quantile from "../../src/util/quantile";
|
|
import { matrixFBSToDataframe } from "../../src/util/stateManager/matrix";
|
|
import * as REST from "./stateManager/sampleResponses";
|
|
import { indexEntireSchema } from "../../src/util/stateManager/schemaHelpers";
|
|
import { _normalizeCategoricalSchema } from "../../src/annoMatrix/schema";
|
|
|
|
describe("centroid", () => {
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
|
let schema: any;
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
|
let obsAnnotations: any;
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
|
let obsLayout: any;
|
|
|
|
beforeAll(() => {
|
|
schema = indexEntireSchema(cloneDeep(REST.schema.schema));
|
|
obsAnnotations = matrixFBSToDataframe(REST.annotationsObs);
|
|
obsLayout = matrixFBSToDataframe(REST.layoutObs);
|
|
|
|
_normalizeCategoricalSchema(
|
|
schema.annotations.obsByName.field3,
|
|
obsAnnotations.col("field3")
|
|
);
|
|
});
|
|
|
|
test("field4 (categorical obsAnnotation)", () => {
|
|
const centroidResult = calcCentroid(
|
|
schema,
|
|
"field4",
|
|
obsAnnotations,
|
|
{ current: "umap", currentDimNames: ["umap_0", "umap_1"] },
|
|
obsLayout
|
|
);
|
|
|
|
// Check to see that a centroid has been calculated for every categorical value
|
|
const keysAsArray = Array.from(centroidResult.keys());
|
|
expect(keysAsArray).toEqual(
|
|
expect.arrayContaining([83, true, "foo", 2.222222])
|
|
);
|
|
|
|
// This expected result assumes that all cells belong in all categorical values inside of sample response
|
|
const expectedResult = [
|
|
quantile([0.5], obsLayout.col("umap_0").asArray())[0],
|
|
quantile([0.5], obsLayout.col("umap_1").asArray())[0],
|
|
];
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
|
centroidResult.forEach((coordinate: any) => {
|
|
expect(coordinate).toEqual(expectedResult);
|
|
});
|
|
});
|
|
|
|
test("field3 (boolean obsAnnotation)", () => {
|
|
const centroidResult = calcCentroid(
|
|
schema,
|
|
"field3",
|
|
obsAnnotations,
|
|
{ current: "umap", currentDimNames: ["umap_0", "umap_1"] },
|
|
obsLayout
|
|
);
|
|
|
|
// Check to see that a centroid has been calculated for every categorical value
|
|
const keysAsArray = Array.from(centroidResult.keys());
|
|
expect(keysAsArray).toEqual(expect.arrayContaining([false, true]));
|
|
|
|
// This expected result assumes that all cells belong in all categorical values inside of sample response
|
|
const expectedResult = [
|
|
quantile([0.5], obsLayout.col("umap_0").asArray())[0],
|
|
quantile([0.5], obsLayout.col("umap_1").asArray())[0],
|
|
];
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
|
centroidResult.forEach((coordinate: any) => {
|
|
expect(coordinate).toEqual(expectedResult);
|
|
});
|
|
});
|
|
});
|