mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-07 12:18:12 +08:00
type catchErrorsWrap callsite
This commit is contained in:
@@ -2,7 +2,9 @@
|
|||||||
action creators related to embeddings choice
|
action creators related to embeddings choice
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { Dispatch } from "redux";
|
||||||
import { AnnoMatrixObsCrossfilter } from "../annoMatrix";
|
import { AnnoMatrixObsCrossfilter } from "../annoMatrix";
|
||||||
|
import type { RootState } from "../reducers";
|
||||||
import { _setEmbeddingSubset } from "../util/stateManager/viewStackHelpers";
|
import { _setEmbeddingSubset } from "../util/stateManager/viewStackHelpers";
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
|
||||||
@@ -29,30 +31,24 @@ export async function _switchEmbedding(
|
|||||||
return [annoMatrix, obsCrossfilter];
|
return [annoMatrix, obsCrossfilter];
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
export const layoutChoiceAction =
|
||||||
export const layoutChoiceAction = (newLayoutChoice: any) => async (
|
(newLayoutChoice: string) =>
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
async (dispatch: Dispatch, getState: () => RootState): Promise<void> => {
|
||||||
dispatch: any,
|
/*
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
|
||||||
getState: any
|
|
||||||
) => {
|
|
||||||
/*
|
|
||||||
On layout choice, make sure we have selected all on the previous layout, AND the new
|
On layout choice, make sure we have selected all on the previous layout, AND the new
|
||||||
layout.
|
layout.
|
||||||
*/
|
*/
|
||||||
const {
|
const { annoMatrix: prevAnnoMatrix, obsCrossfilter: prevCrossfilter } =
|
||||||
annoMatrix: prevAnnoMatrix,
|
getState();
|
||||||
obsCrossfilter: prevCrossfilter,
|
const [annoMatrix, obsCrossfilter] = await _switchEmbedding(
|
||||||
} = getState();
|
prevAnnoMatrix,
|
||||||
const [annoMatrix, obsCrossfilter] = await _switchEmbedding(
|
prevCrossfilter,
|
||||||
prevAnnoMatrix,
|
newLayoutChoice
|
||||||
prevCrossfilter,
|
);
|
||||||
newLayoutChoice
|
dispatch({
|
||||||
);
|
type: "set layout choice",
|
||||||
dispatch({
|
layoutChoice: newLayoutChoice,
|
||||||
type: "set layout choice",
|
obsCrossfilter,
|
||||||
layoutChoice: newLayoutChoice,
|
annoMatrix,
|
||||||
obsCrossfilter,
|
});
|
||||||
annoMatrix,
|
};
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|||||||
+82
-78
@@ -1,3 +1,5 @@
|
|||||||
|
import { Dispatch } from "redux";
|
||||||
|
|
||||||
import * as globals from "../globals";
|
import * as globals from "../globals";
|
||||||
import { AnnoMatrixLoader, AnnoMatrixObsCrossfilter } from "../annoMatrix";
|
import { AnnoMatrixLoader, AnnoMatrixObsCrossfilter } from "../annoMatrix";
|
||||||
import {
|
import {
|
||||||
@@ -11,6 +13,8 @@ import * as annoActions from "./annotation";
|
|||||||
import * as viewActions from "./viewStack";
|
import * as viewActions from "./viewStack";
|
||||||
import * as embActions from "./embedding";
|
import * as embActions from "./embedding";
|
||||||
import * as genesetActions from "./geneset";
|
import * as genesetActions from "./geneset";
|
||||||
|
import { LayoutColumn, Schema } from "../common/types/entities";
|
||||||
|
import { RootState } from "../reducers";
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||||
function setGlobalConfig(config: any) {
|
function setGlobalConfig(config: any) {
|
||||||
@@ -36,8 +40,8 @@ async function userColorsFetchAndLoad(dispatch: any) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function schemaFetch() {
|
async function schemaFetch(): Promise<{ schema: Schema }> {
|
||||||
return fetchJson("schema");
|
return (await fetchJson("schema")) as { schema: Schema };
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||||
@@ -104,17 +108,17 @@ function prefetchEmbeddings(annoMatrix: any) {
|
|||||||
/*
|
/*
|
||||||
Application bootstrap
|
Application bootstrap
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
|
const doInitialDataLoad = (): ((
|
||||||
const doInitialDataLoad = () =>
|
dispatch: Dispatch,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
getState: () => RootState
|
||||||
catchErrorsWrap(async (dispatch: any) => {
|
) => void) =>
|
||||||
|
catchErrorsWrap(async (dispatch: Dispatch) => {
|
||||||
dispatch({ type: "initial data load start" });
|
dispatch({ type: "initial data load start" });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const [config, schema] = await Promise.all([
|
const [config, schema] = await Promise.all([
|
||||||
configFetch(dispatch),
|
configFetch(dispatch),
|
||||||
// @ts-expect-error ts-migrate(2554) FIXME: Expected 0 arguments, but got 1.
|
schemaFetch(),
|
||||||
schemaFetch(dispatch),
|
|
||||||
userColorsFetchAndLoad(dispatch),
|
userColorsFetchAndLoad(dispatch),
|
||||||
userInfoFetch(dispatch),
|
userInfoFetch(dispatch),
|
||||||
]);
|
]);
|
||||||
@@ -137,10 +141,9 @@ const doInitialDataLoad = () =>
|
|||||||
const layoutSchema = schema?.schema?.layout?.obs ?? [];
|
const layoutSchema = schema?.schema?.layout?.obs ?? [];
|
||||||
if (
|
if (
|
||||||
defaultEmbedding &&
|
defaultEmbedding &&
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
layoutSchema.some((s: LayoutColumn) => s.name === defaultEmbedding)
|
||||||
layoutSchema.some((s: any) => s.name === defaultEmbedding)
|
|
||||||
) {
|
) {
|
||||||
dispatch(embActions.layoutChoiceAction(defaultEmbedding));
|
embActions.layoutChoiceAction(defaultEmbedding);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
dispatch({ type: "initial data load error", error });
|
dispatch({ type: "initial data load error", error });
|
||||||
@@ -188,84 +191,85 @@ const dispatchDiffExpErrors = (dispatch: any, response: any) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const requestDifferentialExpression = (
|
const requestDifferentialExpression =
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
(
|
||||||
set1: any,
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
set1: any,
|
||||||
set2: any,
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||||
num_genes = 50
|
set2: any,
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
num_genes = 50
|
||||||
) => async (dispatch: any, getState: any) => {
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||||
dispatch({ type: "request differential expression started" });
|
) =>
|
||||||
try {
|
async (dispatch: any, getState: any) => {
|
||||||
/*
|
dispatch({ type: "request differential expression started" });
|
||||||
|
try {
|
||||||
|
/*
|
||||||
Steps:
|
Steps:
|
||||||
1. get the most differentially expressed genes
|
1. get the most differentially expressed genes
|
||||||
2. get expression data for each
|
2. get expression data for each
|
||||||
*/
|
*/
|
||||||
const { annoMatrix } = getState();
|
const { annoMatrix } = getState();
|
||||||
const varIndexName = annoMatrix.schema.annotations.var.index;
|
const varIndexName = annoMatrix.schema.annotations.var.index;
|
||||||
|
|
||||||
// Legal values are null, Array or TypedArray. Null is initial state.
|
// Legal values are null, Array or TypedArray. Null is initial state.
|
||||||
if (!set1) set1 = [];
|
if (!set1) set1 = [];
|
||||||
if (!set2) set2 = [];
|
if (!set2) set2 = [];
|
||||||
|
|
||||||
// These lines ensure that we convert any TypedArray to an Array.
|
// These lines ensure that we convert any TypedArray to an Array.
|
||||||
// This is necessary because JSON.stringify() does some very strange
|
// This is necessary because JSON.stringify() does some very strange
|
||||||
// things with TypedArrays (they are marshalled to JSON objects, rather
|
// things with TypedArrays (they are marshalled to JSON objects, rather
|
||||||
// than being marshalled as a JSON array).
|
// than being marshalled as a JSON array).
|
||||||
set1 = Array.isArray(set1) ? set1 : Array.from(set1);
|
set1 = Array.isArray(set1) ? set1 : Array.from(set1);
|
||||||
set2 = Array.isArray(set2) ? set2 : Array.from(set2);
|
set2 = Array.isArray(set2) ? set2 : Array.from(set2);
|
||||||
|
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`${globals.API.prefix}${globals.API.version}diffexp/obs`,
|
`${globals.API.prefix}${globals.API.version}diffexp/obs`,
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: new Headers({
|
headers: new Headers({
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
}),
|
}),
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
mode: "topN",
|
mode: "topN",
|
||||||
count: num_genes,
|
count: num_genes,
|
||||||
set1: { filter: { obs: { index: set1 } } },
|
set1: { filter: { obs: { index: set1 } } },
|
||||||
set2: { filter: { obs: { index: set2 } } },
|
set2: { filter: { obs: { index: set2 } } },
|
||||||
}),
|
}),
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!res.ok || res.headers.get("Content-Type") !== "application/json") {
|
||||||
|
return dispatchDiffExpErrors(dispatch, res);
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
if (!res.ok || res.headers.get("Content-Type") !== "application/json") {
|
const response = await res.json();
|
||||||
return dispatchDiffExpErrors(dispatch, res);
|
const varIndex = await annoMatrix.fetch("var", varIndexName);
|
||||||
|
const diffexpLists = { negative: [], positive: [] };
|
||||||
|
for (const polarity of Object.keys(diffexpLists)) {
|
||||||
|
// @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||||
|
diffexpLists[polarity] = response[polarity].map((v: any) => [
|
||||||
|
varIndex.at(v[0], varIndexName),
|
||||||
|
...v.slice(1),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* then send the success case action through */
|
||||||
|
return dispatch({
|
||||||
|
type: "request differential expression success",
|
||||||
|
data: diffexpLists,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
return dispatch({
|
||||||
|
type: "request differential expression error",
|
||||||
|
error,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const response = await res.json();
|
function fetchJson(pathAndQuery: string) {
|
||||||
const varIndex = await annoMatrix.fetch("var", varIndexName);
|
|
||||||
const diffexpLists = { negative: [], positive: [] };
|
|
||||||
for (const polarity of Object.keys(diffexpLists)) {
|
|
||||||
// @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
|
||||||
diffexpLists[polarity] = response[polarity].map((v: any) => [
|
|
||||||
varIndex.at(v[0], varIndexName),
|
|
||||||
...v.slice(1),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* then send the success case action through */
|
|
||||||
return dispatch({
|
|
||||||
type: "request differential expression success",
|
|
||||||
data: diffexpLists,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
return dispatch({
|
|
||||||
type: "request differential expression error",
|
|
||||||
error,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
|
||||||
function fetchJson(pathAndQuery: any) {
|
|
||||||
return doJsonRequest(
|
return doJsonRequest(
|
||||||
`${globals.API.prefix}${globals.API.version}${pathAndQuery}`
|
`${globals.API.prefix}${globals.API.version}${pathAndQuery}`
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -26,8 +26,10 @@ export const keepAroundErrorToast = (message: any) =>
|
|||||||
/*
|
/*
|
||||||
a hard network error
|
a hard network error
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
export const postNetworkErrorToast = (
|
||||||
export const postNetworkErrorToast = (message: any, key = undefined) =>
|
message: string,
|
||||||
|
key: string | undefined = undefined
|
||||||
|
): string =>
|
||||||
ToastTopCenter.show(
|
ToastTopCenter.show(
|
||||||
{
|
{
|
||||||
message,
|
message,
|
||||||
|
|||||||
Reference in New Issue
Block a user