spatialquery.js 0.1.0 → 0.1.1

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # spatial-query.js
1
+ # spatialquery.js
2
2
  JavaScript implementation of [Spatial-Query](https://github.com/ShaokunAn/Spatial-Query).
3
3
 
4
4
 
@@ -16,19 +16,47 @@ If you use SpatialQuery in your research, please cite the [preprint](https://doi
16
16
  npm install spatialquery.js
17
17
  ```
18
18
 
19
+ A build with all dependencies bundled in is available at `spatialquery.js/bundled` (e.g., for use from a CDN without import maps):
20
+
21
+ ```js
22
+ import { buildContext } from 'spatialquery.js/bundled';
23
+ ```
24
+
19
25
  ## Usage
20
26
 
21
27
  ### Single field of view
22
28
 
29
+ This example loads an AnnData object from a Zarr store using [zarrita](https://github.com/manzt/zarrita.js) and [anndata.js](https://github.com/ilan-gold/anndata.js) (`npm install zarrita anndata.js`).
30
+
23
31
  ```js
32
+ import * as zarr from 'zarrita';
33
+ import { readZarr, get } from 'anndata.js';
24
34
  import {
25
35
  buildContext,
26
36
  findPatternsGrid,
27
37
  motifEnrichmentDist,
28
38
  motifCompositionDist,
29
- } from 'spatial-query';
39
+ } from 'spatialquery.js';
40
+
41
+ // HuBMAP kidney dataset (AnnData-Zarr).
42
+ const url = 'https://assets.hubmapconsortium.org/0a21f3fa27109790483f2a0729be53de/hubmap_ui/anndata-zarr/secondary_analysis.zarr';
43
+ const store = await zarr.withMaybeConsolidatedMetadata(new zarr.FetchStore(url));
44
+ const adata = await readZarr(store);
45
+
46
+ // Cell IDs.
47
+ const obsIndex = Array.from((await get(await adata.obsNames(), [null])).data);
48
+
49
+ // Cell type label of each cell (a categorical obs column).
50
+ const predictedLabel = await adata.obs.get('predicted_label');
51
+ const codes = (await get(predictedLabel.codes, [null])).data;
52
+ const categories = (await get(predictedLabel.categories, [null])).data;
53
+ const labels = Array.from(codes, code => categories[code]);
54
+
55
+ // Spatial coordinates (an n_obs x 2 obsm array).
56
+ const spatial = await adata.obsm.get('X_spatial');
57
+ const xCoords = Float64Array.from((await get(spatial, [null, 0])).data);
58
+ const yCoords = Float64Array.from((await get(spatial, [null, 1])).data);
30
59
 
31
- // Cell type label of each cell.
32
60
  const obsIdToLabel = new Map(obsIndex.map((obsId, i) => [obsId, labels[i]]));
33
61
 
34
62
  const context = buildContext({
@@ -42,11 +70,12 @@ const context = buildContext({
42
70
 
43
71
  // Frequent cell type patterns around grid points.
44
72
  const patterns = await findPatternsGrid(context, { maxDist: 20, minSupport: 0.5 });
45
- // => [{ itemsets: ['B cell', 'T cell'], support: 0.62 }, ...]
73
+ // => [{ itemsets: ['epithelial cell of proximal tubule segment 1', ...], support: 0.54 }, ...]
46
74
 
47
75
  // Motifs enriched around a center cell type (k-NN version: motifEnrichmentKnn).
76
+ const ct = 'kidney loop of Henle cortical thick ascending limb epithelial cell';
48
77
  const enrichment = await motifEnrichmentDist(context, {
49
- ct: 'T cell',
78
+ ct,
50
79
  maxDist: 20,
51
80
  returnCellIds: true, // adds centerIds / neighborIds (obs IDs) to each result
52
81
  });
@@ -54,7 +83,7 @@ const enrichment = await motifEnrichmentDist(context, {
54
83
 
55
84
  // Composition of a motif in the neighborhoods of the center cells.
56
85
  const composition = motifCompositionDist(context, {
57
- ct: 'T cell',
86
+ ct,
58
87
  motifs: enrichment[0].motifs,
59
88
  maxDist: 20,
60
89
  });
@@ -70,7 +99,7 @@ import {
70
99
  buildMultiContext,
71
100
  multiMotifEnrichmentKnn,
72
101
  differentialAnalysisKnn,
73
- } from 'spatial-query';
102
+ } from 'spatialquery.js';
74
103
 
75
104
  // One entry per FOV, with a unique dataset ID and a class (e.g., condition) shared by related FOVs.
76
105
  const multi = buildMultiContext([
@@ -126,10 +155,8 @@ pnpm test
126
155
  ### Publish to NPM
127
156
 
128
157
  ```sh
129
- pnpm run build
130
-
131
158
  npm login
132
- pnpm publish --no-git-checks --provenance --access public
159
+ pnpm publish --no-git-checks --access public
133
160
  ```
134
161
 
135
162
  ## Related work
@@ -137,3 +164,7 @@ pnpm publish --no-git-checks --provenance --access public
137
164
  Related to:
138
165
  - Initial implementation work in [vitessce#2116](https://github.com/vitessce/vitessce/pull/2116/).
139
166
  - 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))
167
+
168
+ ## AI usage disclosure
169
+
170
+ The initial package structure and initial porting efforts were performed by a human. Then, Claude Code was used to port additional functions from Python to TypeScript, and to assist in generation of unit tests to compare JavaScript outputs to the ground-truth Python outputs.