spatialquery.js 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mark Keller
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,139 @@
1
- # Temporary Holding Version
1
+ # spatial-query.js
2
+ JavaScript implementation of [Spatial-Query](https://github.com/ShaokunAn/Spatial-Query).
2
3
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
4
+
5
+ ## Citation
6
+
7
+ If you use SpatialQuery in your research, please cite the [preprint](https://doi.org/10.64898/2026.04.22.720136):
8
+
9
+
10
+ > Shaokun An, Mark Keller, Nils Gehlenborg, Martin Hemberg. **SpatialQuery: scalable discovery and molecular characterization of multicellular motifs from spatial omics data.** bioRxiv. doi: 10.64898/2026.04.22.720136
11
+
12
+
13
+ ## Installation
14
+
15
+ ```sh
16
+ npm install spatialquery.js
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### Single field of view
22
+
23
+ ```js
24
+ import {
25
+ buildContext,
26
+ findPatternsGrid,
27
+ motifEnrichmentDist,
28
+ motifCompositionDist,
29
+ } from 'spatial-query';
30
+
31
+ // Cell type label of each cell.
32
+ const obsIdToLabel = new Map(obsIndex.map((obsId, i) => [obsId, labels[i]]));
33
+
34
+ const context = buildContext({
35
+ obsIndex, // string[] of cell IDs
36
+ xCoords, // Float32Array | Float64Array
37
+ yCoords, // Float32Array | Float64Array
38
+ obsIdToObsSetName: obsId => obsIdToLabel.get(obsId),
39
+ // By default, coordinates are normalized so the mean nearest-neighbor distance is 1.
40
+ normalizeSpatialCoord: true,
41
+ });
42
+
43
+ // Frequent cell type patterns around grid points.
44
+ const patterns = await findPatternsGrid(context, { maxDist: 20, minSupport: 0.5 });
45
+ // => [{ itemsets: ['B cell', 'T cell'], support: 0.62 }, ...]
46
+
47
+ // Motifs enriched around a center cell type (k-NN version: motifEnrichmentKnn).
48
+ const enrichment = await motifEnrichmentDist(context, {
49
+ ct: 'T cell',
50
+ maxDist: 20,
51
+ returnCellIds: true, // adds centerIds / neighborIds (obs IDs) to each result
52
+ });
53
+ // => [{ center, motifs, nCenterMotif, nCenter, nMotif, expectation, pValue, adjPValue, ifSignificant, ... }]
54
+
55
+ // Composition of a motif in the neighborhoods of the center cells.
56
+ const composition = motifCompositionDist(context, {
57
+ ct: 'T cell',
58
+ motifs: enrichment[0].motifs,
59
+ maxDist: 20,
60
+ });
61
+ ```
62
+
63
+ Other functions: `findPatternsRand`, `findFpKnn`, `findFpDist`, `motifEnrichmentKnn`, `motifCompositionKnn`.
64
+ The enrichment functions also accept `motifs` (to test specific motifs) and `mode: 'nested'` (to also test sub-patterns of non-significant motifs).
65
+
66
+ ### Multiple fields of view
67
+
68
+ ```js
69
+ import {
70
+ buildMultiContext,
71
+ multiMotifEnrichmentKnn,
72
+ differentialAnalysisKnn,
73
+ } from 'spatial-query';
74
+
75
+ // One entry per FOV, with a unique dataset ID and a class (e.g., condition) shared by related FOVs.
76
+ const multi = buildMultiContext([
77
+ { datasetId: 'sample-1', datasetClass: 'control', obsIndex: obsIndex1, xCoords: x1, yCoords: y1, obsIdToObsSetName: toLabel1 },
78
+ { datasetId: 'sample-2', datasetClass: 'control', obsIndex: obsIndex2, xCoords: x2, yCoords: y2, obsIdToObsSetName: toLabel2 },
79
+ { datasetId: 'sample-3', datasetClass: 'disease', obsIndex: obsIndex3, xCoords: x3, yCoords: y3, obsIdToObsSetName: toLabel3 },
80
+ // ...
81
+ ]);
82
+
83
+ // Enrichment pooled across the FOVs of the selected classes (all FOVs by default).
84
+ // With returnCellIds: true, cell IDs are keyed by dataset ID.
85
+ const enrichment = await multiMotifEnrichmentKnn(multi, { ct: 'T cell', k: 30, maxDist: 20, datasetClass: 'disease' });
86
+
87
+ // Motifs whose support differs significantly between the FOVs of two classes.
88
+ const differential = await differentialAnalysisKnn(multi, {
89
+ ct: 'T cell',
90
+ datasetClasses: ['control', 'disease'],
91
+ });
92
+ // => { control: [{ itemsets, supportMean, adjPValue }, ...], disease: [...] }
93
+ ```
94
+
95
+ Other functions: `multiFindFpKnn`, `multiFindFpDist`, `findFpKnnFov` / `findFpDistFov` (one FOV, by `datasetId`), `multiMotifEnrichmentDist`, `multiMotifCompositionKnn`, `multiMotifCompositionDist`, `differentialAnalysisDist`, and `differentialTestsKnn` / `differentialTestsDist` (all tested motifs, not only the significant ones).
96
+
97
+
98
+ ## Development
99
+
100
+ ### Setup
101
+
102
+ ```sh
103
+ pnpm install
104
+ ```
105
+
106
+ Download the test fixture files and run the Python fixture conversion/generation scripts:
107
+
108
+ ```sh
109
+ cd fixtures
110
+ # The HuBMAP assets server rejects curl's default User-Agent.
111
+ curl -fL -A "Mozilla/5.0" -o secondary_analysis.h5ad https://assets.hubmapconsortium.org/0a21f3fa27109790483f2a0729be53de/secondary_analysis.h5ad
112
+ CC=/usr/bin/clang CXX=/usr/bin/clang++ uv run test_find_patterns_grid.py
113
+ CC=/usr/bin/clang CXX=/usr/bin/clang++ uv run generate_motif_fixtures.py
114
+ CC=/usr/bin/clang CXX=/usr/bin/clang++ uv run generate_multi_fov_fixtures.py
115
+ cd ..
116
+ ```
117
+
118
+ ### Testing
119
+
120
+ The tests compare the JS outputs to Python reference outputs. See [fixtures/README.md](fixtures/README.md) to download the test data and generate the reference outputs, then:
121
+
122
+ ```sh
123
+ pnpm test
124
+ ```
125
+
126
+ ### Publish to NPM
127
+
128
+ ```sh
129
+ pnpm run build
130
+
131
+ npm login
132
+ pnpm publish --no-git-checks --provenance --access public
133
+ ```
134
+
135
+ ## Related work
136
+
137
+ Related to:
138
+ - Initial implementation work in [vitessce#2116](https://github.com/vitessce/vitessce/pull/2116/).
139
+ - Widget plugin in [vitessce-python](https://github.com/vitessce/vitessce-python/blob/main/src/vitessce/widget_plugins/spatial_query.py) ([example notebook](https://github.com/vitessce/vitessce-python/blob/main/docs/notebooks/widget_plugin_spatial-query.ipynb))
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Error thrown when an assertion fails.
3
+ */
4
+ export declare class AssertionError extends Error {
5
+ /** @param message The error message. */
6
+ constructor(message: string);
7
+ }
8
+ /**
9
+ * Make an assertion. An error is thrown if `expr` does not have truthy value.
10
+ *
11
+ * @param expr The expression to test.
12
+ * @param msg The message to display if the assertion fails.
13
+ */
14
+ export declare function assert(expr: unknown, msg?: string): asserts expr;
15
+ //# sourceMappingURL=assert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":"AACA;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,wCAAwC;gBAC5B,OAAO,EAAE,MAAM;CAI5B;AAGD;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,SAAK,GAAG,OAAO,CAAC,IAAI,CAI5D"}
package/dist/assert.js ADDED
@@ -0,0 +1,23 @@
1
+ // Reference: https://github.com/hms-dbmi/vizarr/blob/82756a8604b1612aa35bb8a292c1451ee9647b70/src/utils.ts#L434
2
+ /**
3
+ * Error thrown when an assertion fails.
4
+ */
5
+ export class AssertionError extends Error {
6
+ /** @param message The error message. */
7
+ constructor(message) {
8
+ super(message);
9
+ this.name = "AssertionError";
10
+ }
11
+ }
12
+ /**
13
+ * Make an assertion. An error is thrown if `expr` does not have truthy value.
14
+ *
15
+ * @param expr The expression to test.
16
+ * @param msg The message to display if the assertion fails.
17
+ */
18
+ export function assert(expr, msg = "") {
19
+ if (!expr) {
20
+ throw new AssertionError(msg);
21
+ }
22
+ }
23
+ //# sourceMappingURL=assert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert.js","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,wCAAwC;IACxC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAGD;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,IAAa,EAAE,GAAG,GAAG,EAAE;IAC5C,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,cAAc,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;AACH,CAAC"}
@@ -0,0 +1,10 @@
1
+ export type FrequentPattern = {
2
+ itemsets: string[];
3
+ support: number;
4
+ neighborIds?: string[];
5
+ };
6
+ export declare function findMaximalPatterns<T extends {
7
+ itemsets: string[];
8
+ }>(patterns: T[]): T[];
9
+ export declare function mineFrequentPatterns(transactions: string[][], minSupport: number, ifMax: boolean): Promise<FrequentPattern[]>;
10
+ //# sourceMappingURL=fpgrowth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fpgrowth.d.ts","sourceRoot":"","sources":["../src/fpgrowth.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,eAAe,GAAG;IAE5B,QAAQ,EAAE,MAAM,EAAE,CAAC;IAEnB,OAAO,EAAE,MAAM,CAAC;IAEhB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB,CAAC;AAIF,wBAAgB,mBAAmB,CAAC,CAAC,SAAS;IAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAOxF;AAMD,wBAAsB,oBAAoB,CACxC,YAAY,EAAE,MAAM,EAAE,EAAE,EACxB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,eAAe,EAAE,CAAC,CAyB5B"}
@@ -0,0 +1,35 @@
1
+ import { FPGrowth } from 'node-fpgrowth';
2
+ // Keep only the maximal patterns: those that are not a proper subset of another pattern.
3
+ // Reference: https://github.com/ShaokunAn/Spatial-Query/blob/9250b61/SpatialQuery/spatial_utils.py#L68
4
+ export function findMaximalPatterns(patterns) {
5
+ const sets = patterns.map(p => new Set(p.itemsets));
6
+ return patterns.filter((p, i) => !sets.some((other, j) => (j !== i
7
+ && other.size > sets[i].size
8
+ && p.itemsets.every(item => other.has(item)))));
9
+ }
10
+ // Mine frequent patterns from transactions of cell type labels.
11
+ // Equivalent to the MultiLabelBinarizer + mlxtend fpgrowth + find_maximal_patterns
12
+ // steps of build_fptree_dist / build_fptree_knn.
13
+ // Reference: https://github.com/ShaokunAn/Spatial-Query/blob/9250b61/SpatialQuery/spatial_utils.py#L454
14
+ export async function mineFrequentPatterns(transactions, minSupport, ifMax) {
15
+ if (transactions.length === 0) {
16
+ return [];
17
+ }
18
+ // Transactions are binarized in Python, so duplicate cell types are collapsed.
19
+ const uniqueTransactions = transactions.map(t => Array.from(new Set(t)));
20
+ const fpgrowth = new FPGrowth(minSupport);
21
+ const itemsets = await fpgrowth.exec(uniqueTransactions);
22
+ // node-fpgrowth reports support as a count; mlxtend reports a fraction.
23
+ const byKey = new Map();
24
+ for (const { items, support } of itemsets) {
25
+ const sorted = items.toSorted();
26
+ byKey.set(JSON.stringify(sorted), { itemsets: sorted, support: support / transactions.length });
27
+ }
28
+ let patterns = Array.from(byKey.values());
29
+ if (ifMax) {
30
+ patterns = findMaximalPatterns(patterns);
31
+ }
32
+ // Sort by descending support, breaking ties by itemsets for a deterministic order.
33
+ return patterns.toSorted((a, b) => (b.support - a.support || JSON.stringify(a.itemsets).localeCompare(JSON.stringify(b.itemsets))));
34
+ }
35
+ //# sourceMappingURL=fpgrowth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fpgrowth.js","sourceRoot":"","sources":["../src/fpgrowth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAWzC,yFAAyF;AACzF,uGAAuG;AACvG,MAAM,UAAU,mBAAmB,CAAmC,QAAa;IACjF,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;IACpD,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,CACxD,CAAC,KAAK,CAAC;WACJ,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI;WACzB,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAC7C,CAAC,CAAC,CAAC;AACN,CAAC;AAED,gEAAgE;AAChE,mFAAmF;AACnF,iDAAiD;AACjD,wGAAwG;AACxG,MAAM,CAAC,KAA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,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAC9F,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { generateObsIdToObsSetName, normalizeSpatialCoords, buildContext, buildGridPoints, findPatternsGrid, findPatternsRand, findFpKnn, findFpDist, computeMotifEnrichment, motifEnrichmentKnn, motifEnrichmentDist, motifCompositionKnn, motifCompositionDist, type InitParams, type SqContext, type MotifsParam, type EnrichmentMode, type MotifEnrichmentResult, type MotifCompositionRow, } from './single-fov.js';
2
+ export { buildMultiContext, multiFindFpKnn, multiFindFpDist, findFpKnnFov, findFpDistFov, multiMotifEnrichmentKnn, multiMotifEnrichmentDist, multiMotifCompositionKnn, multiMotifCompositionDist, differentialAnalysisKnn, differentialAnalysisDist, differentialTestsKnn, differentialTestsDist, type FovInitParams, type SqMultiContext, type MultiFovMotifEnrichmentResult, type MultiFovMotifCompositionRow, type DifferentialResult, type DifferentialTestResult, } from './multi-fov.js';
3
+ export { findMaximalPatterns, type FrequentPattern } from './fpgrowth.js';
4
+ export { nestedMotifDescent } from './nested.js';
5
+ export { applyFdrCorrection } from './stats.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,sBAAsB,EACtB,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,GACzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,YAAY,EACZ,aAAa,EACb,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,oBAAoB,EACpB,qBAAqB,EACrB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,6BAA6B,EAClC,KAAK,2BAA2B,EAChC,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,GAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export { generateObsIdToObsSetName, normalizeSpatialCoords, buildContext, buildGridPoints, findPatternsGrid, findPatternsRand, findFpKnn, findFpDist, computeMotifEnrichment, motifEnrichmentKnn, motifEnrichmentDist, motifCompositionKnn, motifCompositionDist, } from './single-fov.js';
2
+ export { buildMultiContext, multiFindFpKnn, multiFindFpDist, findFpKnnFov, findFpDistFov, multiMotifEnrichmentKnn, multiMotifEnrichmentDist, multiMotifCompositionKnn, multiMotifCompositionDist, differentialAnalysisKnn, differentialAnalysisDist, differentialTestsKnn, differentialTestsDist, } from './multi-fov.js';
3
+ export { findMaximalPatterns } from './fpgrowth.js';
4
+ export { nestedMotifDescent } from './nested.js';
5
+ export { applyFdrCorrection } from './stats.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,sBAAsB,EACtB,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,GAOrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,YAAY,EACZ,aAAa,EACb,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,oBAAoB,EACpB,qBAAqB,GAOtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAwB,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,115 @@
1
+ import { type InitParams, type SqContext, type MotifsParam, type MotifEnrichmentResult, type MotifCompositionRow, type EnrichmentMode } from './single-fov.js';
2
+ import { type FrequentPattern } from './fpgrowth.js';
3
+ export type FovInitParams = InitParams & {
4
+ datasetId: string;
5
+ datasetClass: string;
6
+ };
7
+ export type SqMultiContext = {
8
+ datasetIds: string[];
9
+ datasetClasses: string[];
10
+ contexts: SqContext[];
11
+ };
12
+ export declare function buildMultiContext(fovs: FovInitParams[]): SqMultiContext;
13
+ type DatasetClassParam = {
14
+ datasetClass?: string | string[];
15
+ };
16
+ type MultiFindFpKnnParams = DatasetClassParam & {
17
+ ct: string;
18
+ k?: number;
19
+ minSupport?: number;
20
+ maxDist?: number;
21
+ ifMax?: boolean;
22
+ };
23
+ export declare function multiFindFpKnn(multi: SqMultiContext, params: MultiFindFpKnnParams): Promise<FrequentPattern[]>;
24
+ type MultiFindFpDistParams = DatasetClassParam & {
25
+ ct: string;
26
+ maxDist?: number;
27
+ minSize?: number;
28
+ minSupport?: number;
29
+ ifMax?: boolean;
30
+ };
31
+ export declare function multiFindFpDist(multi: SqMultiContext, params: MultiFindFpDistParams): Promise<FrequentPattern[]>;
32
+ type FindFpFovParams = {
33
+ ct: string;
34
+ datasetId: string;
35
+ };
36
+ export declare function findFpKnnFov(multi: SqMultiContext, params: FindFpFovParams & {
37
+ k?: number;
38
+ minSupport?: number;
39
+ maxDist?: number;
40
+ }): Promise<FrequentPattern[]>;
41
+ export declare function findFpDistFov(multi: SqMultiContext, params: FindFpFovParams & {
42
+ maxDist?: number;
43
+ minSize?: number;
44
+ minSupport?: number;
45
+ }): Promise<FrequentPattern[]>;
46
+ export type MultiFovMotifEnrichmentResult = Omit<MotifEnrichmentResult, 'neighborIds' | 'centerIds'> & {
47
+ neighborIds?: Record<string, string[]>;
48
+ centerIds?: Record<string, string[]>;
49
+ };
50
+ type MultiMotifEnrichmentKnnParams = DatasetClassParam & {
51
+ ct: string;
52
+ motifs?: MotifsParam;
53
+ k?: number;
54
+ minSupport?: number;
55
+ maxDist?: number;
56
+ returnCellIds?: boolean;
57
+ mode?: EnrichmentMode;
58
+ };
59
+ export declare function multiMotifEnrichmentKnn(multi: SqMultiContext, params: MultiMotifEnrichmentKnnParams): Promise<MultiFovMotifEnrichmentResult[]>;
60
+ type MultiMotifEnrichmentDistParams = DatasetClassParam & {
61
+ ct: string;
62
+ motifs?: MotifsParam;
63
+ maxDist?: number;
64
+ minSize?: number;
65
+ minSupport?: number;
66
+ returnCellIds?: boolean;
67
+ mode?: EnrichmentMode;
68
+ };
69
+ export declare function multiMotifEnrichmentDist(multi: SqMultiContext, params: MultiMotifEnrichmentDistParams): Promise<MultiFovMotifEnrichmentResult[]>;
70
+ export type MultiFovMotifCompositionRow = MotifCompositionRow & {
71
+ datasetId: string;
72
+ };
73
+ export declare function multiMotifCompositionKnn(multi: SqMultiContext, params: DatasetClassParam & {
74
+ ct: string;
75
+ motifs: MotifsParam;
76
+ k?: number;
77
+ maxDist?: number;
78
+ }): MultiFovMotifCompositionRow[];
79
+ export declare function multiMotifCompositionDist(multi: SqMultiContext, params: DatasetClassParam & {
80
+ ct: string;
81
+ motifs: MotifsParam;
82
+ maxDist?: number;
83
+ }): MultiFovMotifCompositionRow[];
84
+ export type DifferentialTestResult = {
85
+ itemsets: string[];
86
+ supports: Record<string, number[]>;
87
+ supportMean: Record<string, number>;
88
+ pValue: number;
89
+ adjPValue: number;
90
+ ifSignificant: boolean;
91
+ datasetClassHigherFrequency: string;
92
+ };
93
+ export type DifferentialResult = Pick<DifferentialTestResult, 'itemsets' | 'supportMean' | 'adjPValue'>;
94
+ type DifferentialAnalysisKnnParams = {
95
+ ct: string;
96
+ datasetClasses: string[];
97
+ motifs?: MotifsParam;
98
+ k?: number;
99
+ minSupport?: number;
100
+ maxDist?: number;
101
+ };
102
+ export declare function differentialTestsKnn(multi: SqMultiContext, params: DifferentialAnalysisKnnParams): Promise<DifferentialTestResult[]>;
103
+ export declare function differentialAnalysisKnn(multi: SqMultiContext, params: DifferentialAnalysisKnnParams): Promise<Record<string, DifferentialResult[]>>;
104
+ type DifferentialAnalysisDistParams = {
105
+ ct: string;
106
+ datasetClasses: string[];
107
+ motifs?: MotifsParam;
108
+ maxDist?: number;
109
+ minSupport?: number;
110
+ minSize?: number;
111
+ };
112
+ export declare function differentialTestsDist(multi: SqMultiContext, params: DifferentialAnalysisDistParams): Promise<DifferentialTestResult[]>;
113
+ export declare function differentialAnalysisDist(multi: SqMultiContext, params: DifferentialAnalysisDistParams): Promise<Record<string, DifferentialResult[]>>;
114
+ export {};
115
+ //# sourceMappingURL=multi-fov.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi-fov.d.ts","sourceRoot":"","sources":["../src/multi-fov.ts"],"names":[],"mappings":"AAEA,OAAO,EAgBL,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,cAAc,EAEpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAwB,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAI3E,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG;IAEvC,SAAS,EAAE,MAAM,CAAC;IAElB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAE3B,UAAU,EAAE,MAAM,EAAE,CAAC;IAEr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