mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-08 06:28:11 +08:00
chore: extract schema types (#2375)
* chore: extract schema types * address comments
This commit is contained in:
@@ -34,7 +34,7 @@ function makeMockColumn(s: any, length: any) {
|
|||||||
return new Array(length).fill(s.categories[0]);
|
return new Array(length).fill(s.categories[0]);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Error("unkonwn type");
|
throw new Error("unknown type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { RawSchema } from "../../../../src/common/types/entities";
|
import { RawSchema } from "../../../../src/common/types/schema";
|
||||||
|
|
||||||
export const schema: { schema: RawSchema } = {
|
export const schema: { schema: RawSchema } = {
|
||||||
schema: {
|
schema: {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import zip from "lodash.zip";
|
|||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { flatbuffers } from "flatbuffers";
|
import { flatbuffers } from "flatbuffers";
|
||||||
import { NetEncoding } from "../../../src/util/stateManager/matrix_generated";
|
import { NetEncoding } from "../../../src/util/stateManager/matrix_generated";
|
||||||
import { RawSchema } from "../../../src/common/types/entities";
|
import { RawSchema } from "../../../src/common/types/schema";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
test data mocking REST 0.2 API responses. Used in several tests.
|
test data mocking REST 0.2 API responses. Used in several tests.
|
||||||
|
|||||||
@@ -1,60 +1,3 @@
|
|||||||
// If a globally shared type or interface doesn't have a clear owner, put it here
|
// If a globally shared type or interface doesn't have a clear owner, put it here
|
||||||
|
|
||||||
export type Category = number | string | boolean;
|
export {};
|
||||||
|
|
||||||
export interface AnnotationColumn {
|
|
||||||
categories?: Category[];
|
|
||||||
name: string;
|
|
||||||
type: "string" | "float32" | "int32" | "categorical" | "boolean";
|
|
||||||
writable: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface DataFrame {
|
|
||||||
nObs: number;
|
|
||||||
nVar: number;
|
|
||||||
// TODO(thuang): Not sure what other types are available
|
|
||||||
type: "float32";
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LayoutColumn {
|
|
||||||
dims: string[];
|
|
||||||
name: string;
|
|
||||||
// TODO(thuang): Not sure what other types are available
|
|
||||||
type: "float32";
|
|
||||||
}
|
|
||||||
interface RawLayout {
|
|
||||||
obs: LayoutColumn[];
|
|
||||||
var?: LayoutColumn[];
|
|
||||||
}
|
|
||||||
|
|
||||||
interface RawAnnotations {
|
|
||||||
obs: {
|
|
||||||
columns: AnnotationColumn[];
|
|
||||||
index: string;
|
|
||||||
};
|
|
||||||
var: {
|
|
||||||
columns: AnnotationColumn[];
|
|
||||||
index: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface RawSchema {
|
|
||||||
annotations: RawAnnotations;
|
|
||||||
dataframe: DataFrame;
|
|
||||||
layout: RawLayout;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Annotations extends RawAnnotations {
|
|
||||||
obsByName: { [name: string]: AnnotationColumn };
|
|
||||||
varByName: { [name: string]: AnnotationColumn };
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Layout extends RawLayout {
|
|
||||||
obsByName: { [name: string]: LayoutColumn };
|
|
||||||
varByName: { [name: string]: LayoutColumn };
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Schema extends RawSchema {
|
|
||||||
annotations: Annotations;
|
|
||||||
layout: Layout;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
type Category = number | string | boolean;
|
||||||
|
|
||||||
|
export interface AnnotationColumnSchema {
|
||||||
|
categories?: Category[];
|
||||||
|
name: string;
|
||||||
|
type: "string" | "float32" | "int32" | "categorical" | "boolean";
|
||||||
|
writable: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface XMatrixSchema {
|
||||||
|
nObs: number;
|
||||||
|
nVar: number;
|
||||||
|
// TODO(thuang): Not sure what other types are available
|
||||||
|
type: "float32";
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EmbeddingSchema {
|
||||||
|
dims: string[];
|
||||||
|
name: string;
|
||||||
|
// TODO(thuang): Not sure what other types are available
|
||||||
|
type: "float32";
|
||||||
|
}
|
||||||
|
interface RawLayoutSchema {
|
||||||
|
obs: EmbeddingSchema[];
|
||||||
|
var?: EmbeddingSchema[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RawAnnotationsSchema {
|
||||||
|
obs: {
|
||||||
|
columns: AnnotationColumnSchema[];
|
||||||
|
index: string;
|
||||||
|
};
|
||||||
|
var: {
|
||||||
|
columns: AnnotationColumnSchema[];
|
||||||
|
index: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RawSchema {
|
||||||
|
annotations: RawAnnotationsSchema;
|
||||||
|
dataframe: XMatrixSchema;
|
||||||
|
layout: RawLayoutSchema;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AnnotationsSchema extends RawAnnotationsSchema {
|
||||||
|
obsByName: { [name: string]: AnnotationColumnSchema };
|
||||||
|
varByName: { [name: string]: AnnotationColumnSchema };
|
||||||
|
}
|
||||||
|
|
||||||
|
interface LayoutSchema extends RawLayoutSchema {
|
||||||
|
obsByName: { [name: string]: EmbeddingSchema };
|
||||||
|
varByName: { [name: string]: EmbeddingSchema };
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Schema extends RawSchema {
|
||||||
|
annotations: AnnotationsSchema;
|
||||||
|
layout: LayoutSchema;
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ Helper functions for user-editable annotations state management.
|
|||||||
See also reducers/annotations.js
|
See also reducers/annotations.js
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Schema } from "../../common/types/entities";
|
import { Schema } from "../../common/types/schema";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
There are a number of state constraints assumed throughout the
|
There are a number of state constraints assumed throughout the
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ import catLabelSort from "../catLabelSort";
|
|||||||
import {
|
import {
|
||||||
RawSchema,
|
RawSchema,
|
||||||
Schema,
|
Schema,
|
||||||
LayoutColumn,
|
EmbeddingSchema,
|
||||||
AnnotationColumn,
|
AnnotationColumnSchema,
|
||||||
} from "../../common/types/entities";
|
} from "../../common/types/schema";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
System wide schema assumptions:
|
System wide schema assumptions:
|
||||||
@@ -86,7 +86,7 @@ export function removeObsAnnoColumn(schema: Schema, name: string): Schema {
|
|||||||
export function addObsAnnoColumn(
|
export function addObsAnnoColumn(
|
||||||
schema: Schema,
|
schema: Schema,
|
||||||
_: string,
|
_: string,
|
||||||
defn: AnnotationColumn
|
defn: AnnotationColumnSchema
|
||||||
): Schema {
|
): Schema {
|
||||||
const newSchema = _copyObsAnno(schema);
|
const newSchema = _copyObsAnno(schema);
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ export function addObsAnnoCategory(schema: any, name: any, category: any) {
|
|||||||
return newSchema;
|
return newSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addObsLayout(schema: Schema, layout: LayoutColumn): Schema {
|
export function addObsLayout(schema: Schema, layout: EmbeddingSchema): Schema {
|
||||||
/* add or replace a layout */
|
/* add or replace a layout */
|
||||||
const newSchema = _copyObsLayout(schema);
|
const newSchema = _copyObsLayout(schema);
|
||||||
newSchema.layout.obs.push(layout);
|
newSchema.layout.obs.push(layout);
|
||||||
|
|||||||
Reference in New Issue
Block a user