@vitessce/zarr 3.3.10 → 3.3.12
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/dist/{deflate-b162c7aa.js → deflate-86897310.js} +1 -1
- package/dist/{index-184aee21.js → index-6363cec8.js} +61 -21
- package/dist/index.js +1 -1
- package/dist/{jpeg-dbb0f9d9.js → jpeg-4205ad3d.js} +1 -1
- package/dist/{lerc-e45d57dc.js → lerc-8b755240.js} +1 -1
- package/dist/{lzw-05e88e18.js → lzw-3226f3d2.js} +1 -1
- package/dist/{packbits-922f4592.js → packbits-5adb4dc0.js} +1 -1
- package/dist/{raw-a8de9c08.js → raw-3c413002.js} +1 -1
- package/dist/{webimage-27013e2d.js → webimage-fc45faba.js} +1 -1
- package/dist-tsc/AnnDataSource.test.js +30 -57
- package/dist-tsc/SpatialDataTableSource.d.ts.map +1 -1
- package/dist-tsc/SpatialDataTableSource.js +10 -4
- package/dist-tsc/anndata-loaders/ObsFeatureMatrixAnndataLoader.d.ts.map +1 -1
- package/dist-tsc/anndata-loaders/ObsFeatureMatrixAnndataLoader.js +11 -19
- package/dist-tsc/anndata-loaders/ObsFeatureMatrixAnndataLoader.test.js +87 -58
- package/dist-tsc/anndata-loaders/utils.d.ts +7 -0
- package/dist-tsc/anndata-loaders/utils.d.ts.map +1 -0
- package/dist-tsc/anndata-loaders/utils.js +53 -0
- package/dist-tsc/anndata-loaders/utils.test.d.ts +2 -0
- package/dist-tsc/anndata-loaders/utils.test.d.ts.map +1 -0
- package/dist-tsc/anndata-loaders/utils.test.js +17 -0
- package/dist-tsc/genomic-loaders/GenomicProfilesZarrLoader.d.ts.map +1 -1
- package/dist-tsc/genomic-loaders/GenomicProfilesZarrLoader.js +2 -2
- package/dist-tsc/json-fixtures/anndata-0.10/anndata-csc.json +210 -0
- package/dist-tsc/json-fixtures/anndata-0.10/anndata-csr.adata.json +210 -0
- package/dist-tsc/json-fixtures/anndata-0.10/anndata-dense.json +190 -0
- package/dist-tsc/json-fixtures/anndata-0.7/anndata-csc.json +33 -5
- package/dist-tsc/json-fixtures/anndata-0.7/anndata-csr.json +33 -5
- package/dist-tsc/json-fixtures/anndata-0.7/anndata-dense.json +29 -1
- package/dist-tsc/json-fixtures/anndata-0.8/anndata-csc.json +41 -5
- package/dist-tsc/json-fixtures/anndata-0.8/anndata-csr.adata.json +41 -5
- package/dist-tsc/json-fixtures/anndata-0.8/anndata-dense.json +37 -1
- package/dist-tsc/json-fixtures/anndata-0.9/anndata-csc.json +210 -0
- package/dist-tsc/json-fixtures/anndata-0.9/anndata-csr.adata.json +210 -0
- package/dist-tsc/json-fixtures/anndata-0.9/anndata-dense.json +190 -0
- package/package.json +11 -11
- package/src/AnnDataSource.test.js +30 -60
- package/src/SpatialDataTableSource.js +10 -4
- package/src/anndata-loaders/ObsFeatureMatrixAnndataLoader.js +11 -20
- package/src/anndata-loaders/ObsFeatureMatrixAnndataLoader.test.js +118 -95
- package/src/anndata-loaders/utils.js +55 -0
- package/src/anndata-loaders/utils.test.js +21 -0
- package/src/genomic-loaders/GenomicProfilesZarrLoader.js +7 -2
- package/src/json-fixtures/README.md +10 -0
- package/src/json-fixtures/anndata-0.10/anndata-csc.json +210 -0
- package/src/json-fixtures/anndata-0.10/anndata-csr.adata.json +210 -0
- package/src/json-fixtures/anndata-0.10/anndata-dense.json +190 -0
- package/src/json-fixtures/anndata-0.7/anndata-csc.json +33 -5
- package/src/json-fixtures/anndata-0.7/anndata-csr.json +33 -5
- package/src/json-fixtures/anndata-0.7/anndata-dense.json +29 -1
- package/src/json-fixtures/anndata-0.8/anndata-csc.json +41 -5
- package/src/json-fixtures/anndata-0.8/anndata-csr.adata.json +41 -5
- package/src/json-fixtures/anndata-0.8/anndata-dense.json +37 -1
- package/src/json-fixtures/anndata-0.9/anndata-csc.json +210 -0
- package/src/json-fixtures/anndata-0.9/anndata-csr.adata.json +210 -0
- package/src/json-fixtures/anndata-0.9/anndata-dense.json +190 -0
|
@@ -2839,10 +2839,10 @@ class AnnDataSource extends ZarrDataSource {
|
|
|
2839
2839
|
throw new Error("Keys for encoding-type or encoding-version not found in AnnDataSource._loadString");
|
|
2840
2840
|
}
|
|
2841
2841
|
}
|
|
2842
|
-
const regex$
|
|
2842
|
+
const regex$2 = /^mod\/([^/]*)\/(.*)$/;
|
|
2843
2843
|
function getModPrefix(arrPath) {
|
|
2844
2844
|
if (arrPath) {
|
|
2845
|
-
const matches2 = arrPath.match(regex$
|
|
2845
|
+
const matches2 = arrPath.match(regex$2);
|
|
2846
2846
|
if (matches2 && matches2.length === 3) {
|
|
2847
2847
|
return `mod/${matches2[1]}/`;
|
|
2848
2848
|
}
|
|
@@ -2906,12 +2906,17 @@ class MuDataSource extends AnnDataSource {
|
|
|
2906
2906
|
return this.varAlias[varPath];
|
|
2907
2907
|
}
|
|
2908
2908
|
}
|
|
2909
|
-
const
|
|
2909
|
+
const pluralRegex = /^tables\/([^/]*)\/(.*)$/;
|
|
2910
|
+
const singularRegex = /^table\/([^/]*)\/(.*)$/;
|
|
2910
2911
|
function getTablePrefix(arrPath) {
|
|
2911
2912
|
if (arrPath) {
|
|
2912
|
-
const
|
|
2913
|
-
if (
|
|
2914
|
-
return `
|
|
2913
|
+
const pluralMatches = arrPath.match(pluralRegex);
|
|
2914
|
+
if (pluralMatches && pluralMatches.length === 3) {
|
|
2915
|
+
return `tables/${pluralMatches[1]}/`;
|
|
2916
|
+
}
|
|
2917
|
+
const singularMatches = arrPath.match(singularRegex);
|
|
2918
|
+
if (singularMatches && singularMatches.length === 3) {
|
|
2919
|
+
return `table/${singularMatches[1]}/`;
|
|
2915
2920
|
}
|
|
2916
2921
|
}
|
|
2917
2922
|
return "table/table/";
|
|
@@ -3117,7 +3122,33 @@ class MatrixZarrAsObsFeatureMatrixLoader extends AbstractTwoStepLoader {
|
|
|
3117
3122
|
)));
|
|
3118
3123
|
}
|
|
3119
3124
|
}
|
|
3120
|
-
|
|
3125
|
+
class IncorrectDataTypeError extends Error {
|
|
3126
|
+
constructor(message) {
|
|
3127
|
+
super(message);
|
|
3128
|
+
this.name = "IncorrectDataTypeError";
|
|
3129
|
+
}
|
|
3130
|
+
}
|
|
3131
|
+
function convertBigInt64ArrayToInt32Array(arr) {
|
|
3132
|
+
if (!(arr instanceof BigInt64Array)) {
|
|
3133
|
+
throw new IncorrectDataTypeError("Expected a BigInt64Array");
|
|
3134
|
+
}
|
|
3135
|
+
const out = new Int32Array(arr.length);
|
|
3136
|
+
const view = new Int32Array(arr.buffer);
|
|
3137
|
+
for (let i2 = 0; i2 < arr.length; i2++) {
|
|
3138
|
+
out[i2] = view[i2 * 2];
|
|
3139
|
+
}
|
|
3140
|
+
return out;
|
|
3141
|
+
}
|
|
3142
|
+
const maybeDowncastInt64 = (data) => {
|
|
3143
|
+
try {
|
|
3144
|
+
return convertBigInt64ArrayToInt32Array(data);
|
|
3145
|
+
} catch (error2) {
|
|
3146
|
+
if (error2 instanceof IncorrectDataTypeError) {
|
|
3147
|
+
return data;
|
|
3148
|
+
}
|
|
3149
|
+
throw error2;
|
|
3150
|
+
}
|
|
3151
|
+
};
|
|
3121
3152
|
const concatenateColumnVectors = (arr) => {
|
|
3122
3153
|
const numCols = arr.length;
|
|
3123
3154
|
const numRows = arr[0].length;
|
|
@@ -3132,6 +3163,7 @@ const concatenateColumnVectors = (arr) => {
|
|
|
3132
3163
|
}
|
|
3133
3164
|
return new TypedArray2(view.buffer);
|
|
3134
3165
|
};
|
|
3166
|
+
const toObject = (data) => ({ data });
|
|
3135
3167
|
class ObsFeatureMatrixAnndataLoader extends AbstractTwoStepLoader {
|
|
3136
3168
|
getOptions() {
|
|
3137
3169
|
return this.options;
|
|
@@ -3234,9 +3266,10 @@ class ObsFeatureMatrixAnndataLoader extends AbstractTwoStepLoader {
|
|
|
3234
3266
|
const { data: rowIndices } = await get$1(indexArr, [
|
|
3235
3267
|
slice$3(startRowIndex, endRowIndex)
|
|
3236
3268
|
]);
|
|
3237
|
-
|
|
3269
|
+
let { data: cellXGeneData } = await get$1(cellXGeneArr, [
|
|
3238
3270
|
slice$3(startRowIndex, endRowIndex)
|
|
3239
3271
|
]);
|
|
3272
|
+
cellXGeneData = maybeDowncastInt64(cellXGeneData);
|
|
3240
3273
|
for (let rowIndex = 0; rowIndex < rowIndices.length; rowIndex += 1) {
|
|
3241
3274
|
geneData[rowIndices[rowIndex]] = cellXGeneData[rowIndex];
|
|
3242
3275
|
}
|
|
@@ -3274,12 +3307,13 @@ class ObsFeatureMatrixAnndataLoader extends AbstractTwoStepLoader {
|
|
|
3274
3307
|
this._sparseMatrix = this._openSparseArrays().then(async (sparseArrays) => {
|
|
3275
3308
|
const { path: matrix2 } = this.getOptions();
|
|
3276
3309
|
const { shape } = await this.dataSource.getJson(`${matrix2}/.zattrs`);
|
|
3277
|
-
|
|
3310
|
+
let [rows, cols, cellXGene] = await Promise.all(
|
|
3278
3311
|
sparseArrays.map(async (arr) => {
|
|
3279
3312
|
const { data } = await createZarrArrayAdapter(arr).getRaw(null);
|
|
3280
3313
|
return data;
|
|
3281
3314
|
})
|
|
3282
3315
|
);
|
|
3316
|
+
cellXGene = maybeDowncastInt64(cellXGene);
|
|
3283
3317
|
const cellXGeneMatrix = new Float32Array(shape[0] * shape[1]).fill(0);
|
|
3284
3318
|
let row = 0;
|
|
3285
3319
|
rows.forEach((_, index2) => {
|
|
@@ -3307,12 +3341,13 @@ class ObsFeatureMatrixAnndataLoader extends AbstractTwoStepLoader {
|
|
|
3307
3341
|
this._sparseMatrix = this._openSparseArrays().then(async (sparseArrays) => {
|
|
3308
3342
|
const { path: matrix2 } = this.getOptions();
|
|
3309
3343
|
const { shape } = await this.dataSource.getJson(`${matrix2}/.zattrs`);
|
|
3310
|
-
|
|
3344
|
+
let [cols, rows, cellXGene] = await Promise.all(
|
|
3311
3345
|
sparseArrays.map(async (arr) => {
|
|
3312
3346
|
const { data } = await createZarrArrayAdapter(arr).getRaw(null);
|
|
3313
3347
|
return data;
|
|
3314
3348
|
})
|
|
3315
3349
|
);
|
|
3350
|
+
cellXGene = maybeDowncastInt64(cellXGene);
|
|
3316
3351
|
const cellXGeneMatrix = new Float32Array(shape[0] * shape[1]).fill(0);
|
|
3317
3352
|
let col = 0;
|
|
3318
3353
|
cols.forEach((_, index2) => {
|
|
@@ -3355,7 +3390,7 @@ class ObsFeatureMatrixAnndataLoader extends AbstractTwoStepLoader {
|
|
|
3355
3390
|
if (!this.arr) {
|
|
3356
3391
|
this.arr = open(storeRoot.resolve(matrix2), { kind: "array" });
|
|
3357
3392
|
}
|
|
3358
|
-
this.cellXGene = this.arr.then((z2) => createZarrArrayAdapter(z2).getRaw(null)).then(({ data }) => toObject(data));
|
|
3393
|
+
this.cellXGene = this.arr.then((z2) => createZarrArrayAdapter(z2).getRaw(null)).then(({ data }) => toObject(maybeDowncastInt64(data)));
|
|
3359
3394
|
}
|
|
3360
3395
|
} else if (encodingType === "csr_matrix") {
|
|
3361
3396
|
this.cellXGene = this._loadCSRSparseCellXGene().then(
|
|
@@ -3407,7 +3442,7 @@ class ObsFeatureMatrixAnndataLoader extends AbstractTwoStepLoader {
|
|
|
3407
3442
|
}
|
|
3408
3443
|
const indices = await this._getGeneIndices(selection);
|
|
3409
3444
|
genes = await Promise.all(
|
|
3410
|
-
indices.map((index2) => this.arr.then((z2) => get$1(z2, [null, index2])).then(({ data }) => data))
|
|
3445
|
+
indices.map((index2) => this.arr.then((z2) => get$1(z2, [null, index2])).then(({ data }) => maybeDowncastInt64(data)))
|
|
3411
3446
|
);
|
|
3412
3447
|
}
|
|
3413
3448
|
return { data: genes, url: null };
|
|
@@ -123265,16 +123300,16 @@ function addDecoder(cases, importFn) {
|
|
|
123265
123300
|
}
|
|
123266
123301
|
cases.forEach((c) => registry$1.set(c, importFn));
|
|
123267
123302
|
}
|
|
123268
|
-
addDecoder([void 0, 1], () => import("./raw-
|
|
123269
|
-
addDecoder(5, () => import("./lzw-
|
|
123303
|
+
addDecoder([void 0, 1], () => import("./raw-3c413002.js").then((m) => m.default));
|
|
123304
|
+
addDecoder(5, () => import("./lzw-3226f3d2.js").then((m) => m.default));
|
|
123270
123305
|
addDecoder(6, () => {
|
|
123271
123306
|
throw new Error("old style JPEG compression is not supported.");
|
|
123272
123307
|
});
|
|
123273
|
-
addDecoder(7, () => import("./jpeg-
|
|
123274
|
-
addDecoder([8, 32946], () => import("./deflate-
|
|
123275
|
-
addDecoder(32773, () => import("./packbits-
|
|
123276
|
-
addDecoder(34887, () => import("./lerc-
|
|
123277
|
-
addDecoder(50001, () => import("./webimage-
|
|
123308
|
+
addDecoder(7, () => import("./jpeg-4205ad3d.js").then((m) => m.default));
|
|
123309
|
+
addDecoder([8, 32946], () => import("./deflate-86897310.js").then((m) => m.default));
|
|
123310
|
+
addDecoder(32773, () => import("./packbits-5adb4dc0.js").then((m) => m.default));
|
|
123311
|
+
addDecoder(34887, () => import("./lerc-8b755240.js").then((m) => m.default));
|
|
123312
|
+
addDecoder(50001, () => import("./webimage-fc45faba.js").then((m) => m.default));
|
|
123278
123313
|
function decodeRowAcc(row, stride) {
|
|
123279
123314
|
let length2 = row.length - stride;
|
|
123280
123315
|
let offset = 0;
|
|
@@ -150535,8 +150570,13 @@ class GenomicProfilesZarrLoader extends AbstractTwoStepLoader {
|
|
|
150535
150570
|
return this.attrs;
|
|
150536
150571
|
}
|
|
150537
150572
|
load() {
|
|
150538
|
-
const { url } = this;
|
|
150539
|
-
return this.loadAttrs().then((attrs) => Promise.resolve(new LoaderResult(
|
|
150573
|
+
const { url, requestInit: requestInit2 } = this;
|
|
150574
|
+
return this.loadAttrs().then((attrs) => Promise.resolve(new LoaderResult(
|
|
150575
|
+
attrs,
|
|
150576
|
+
url,
|
|
150577
|
+
null,
|
|
150578
|
+
requestInit2
|
|
150579
|
+
)));
|
|
150540
150580
|
}
|
|
150541
150581
|
}
|
|
150542
150582
|
export {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A, F, G, b, M, c, k, O, j, f, e, h, i, d, n, m, l, o, p, r, q, a, S, Z } from "./index-
|
|
1
|
+
import { A, F, G, b, M, c, k, O, j, f, e, h, i, d, n, m, l, o, p, r, q, a, S, Z } from "./index-6363cec8.js";
|
|
2
2
|
import "@vitessce/vit-s";
|
|
3
3
|
import "react";
|
|
4
4
|
export {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as inflate_1 } from "./pako.esm-68f84e2a.js";
|
|
2
|
-
import { g as getDefaultExportFromCjs, B as BaseDecoder } from "./index-
|
|
2
|
+
import { g as getDefaultExportFromCjs, B as BaseDecoder } from "./index-6363cec8.js";
|
|
3
3
|
import "@vitessce/vit-s";
|
|
4
4
|
import "react";
|
|
5
5
|
const LercParameters = {
|
|
@@ -4,67 +4,40 @@ import { createStoreFromMapContents } from '@vitessce/zarr-utils';
|
|
|
4
4
|
import AnnDataSource from './AnnDataSource.js';
|
|
5
5
|
import anndata_0_7_DenseFixture from './json-fixtures/anndata-0.7/anndata-dense.json';
|
|
6
6
|
import anndata_0_8_DenseFixture from './json-fixtures/anndata-0.8/anndata-dense.json';
|
|
7
|
+
import anndata_0_9_DenseFixture from './json-fixtures/anndata-0.9/anndata-dense.json';
|
|
8
|
+
import anndata_0_10_DenseFixture from './json-fixtures/anndata-0.10/anndata-dense.json';
|
|
7
9
|
describe('sources/AnnDataSource', () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
Object.entries({ 0.7: anndata_0_7_DenseFixture, 0.8: anndata_0_8_DenseFixture, 0.9: anndata_0_9_DenseFixture, '0.10': anndata_0_10_DenseFixture }).forEach(([version, fixture]) => {
|
|
11
|
+
describe(`AnnData v${version}`, () => {
|
|
12
|
+
it('getJson returns json', async () => {
|
|
13
|
+
const dataSource = new AnnDataSource({
|
|
14
|
+
url: `@fixtures/zarr/anndata-${version}/anndata-dense.zarr`,
|
|
15
|
+
store: createStoreFromMapContents(fixture),
|
|
16
|
+
});
|
|
17
|
+
const zAttrs = await dataSource.getJson('obs/.zattrs');
|
|
18
|
+
expect(Object.keys(zAttrs)).toEqual([
|
|
19
|
+
'_index',
|
|
20
|
+
'column-order',
|
|
21
|
+
'encoding-type',
|
|
22
|
+
'encoding-version',
|
|
23
|
+
]);
|
|
13
24
|
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
'
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
it('loadObsColumns returns ids for location in store', async () => {
|
|
23
|
-
const dataSource = new AnnDataSource({
|
|
24
|
-
url: '@fixtures/zarr/anndata-0.7/anndata-dense.zarr',
|
|
25
|
-
store: createStoreFromMapContents(anndata_0_7_DenseFixture),
|
|
26
|
-
});
|
|
27
|
-
const ids = await dataSource.loadObsColumns(['obs/leiden']);
|
|
28
|
-
expect(ids).toEqual([['1', '1', '2']]);
|
|
29
|
-
});
|
|
30
|
-
it('loadObsIndex returns names', async () => {
|
|
31
|
-
const dataSource = new AnnDataSource({
|
|
32
|
-
url: '@fixtures/zarr/anndata-0.7/anndata-dense.zarr',
|
|
33
|
-
store: createStoreFromMapContents(anndata_0_7_DenseFixture),
|
|
25
|
+
it('loadObsColumns returns ids for location in store', async () => {
|
|
26
|
+
const dataSource = new AnnDataSource({
|
|
27
|
+
url: `@fixtures/zarr/anndata-${version}/anndata-dense.zarr`,
|
|
28
|
+
store: createStoreFromMapContents(fixture),
|
|
29
|
+
});
|
|
30
|
+
const ids = await dataSource.loadObsColumns(['obs/leiden']);
|
|
31
|
+
expect(ids).toEqual([['1', '1', '2']]);
|
|
34
32
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
url: '@fixtures/zarr/anndata-0.8/anndata-dense.zarr',
|
|
43
|
-
store: createStoreFromMapContents(anndata_0_8_DenseFixture),
|
|
44
|
-
});
|
|
45
|
-
const zAttrs = await dataSource.getJson('obs/.zattrs');
|
|
46
|
-
expect(Object.keys(zAttrs)).toEqual([
|
|
47
|
-
'_index',
|
|
48
|
-
'column-order',
|
|
49
|
-
'encoding-type',
|
|
50
|
-
'encoding-version',
|
|
51
|
-
]);
|
|
52
|
-
});
|
|
53
|
-
it('loadObsColumns returns ids for location in store', async () => {
|
|
54
|
-
const dataSource = new AnnDataSource({
|
|
55
|
-
url: '@fixtures/zarr/anndata-0.8/anndata-dense.zarr',
|
|
56
|
-
store: createStoreFromMapContents(anndata_0_8_DenseFixture),
|
|
57
|
-
});
|
|
58
|
-
const ids = await dataSource.loadObsColumns(['obs/leiden']);
|
|
59
|
-
expect(ids).toEqual([['1', '1', '2']]);
|
|
60
|
-
});
|
|
61
|
-
it('loadObsIndex returns names', async () => {
|
|
62
|
-
const dataSource = new AnnDataSource({
|
|
63
|
-
url: '@fixtures/zarr/anndata-0.8/anndata-dense.zarr',
|
|
64
|
-
store: createStoreFromMapContents(anndata_0_8_DenseFixture),
|
|
33
|
+
it('loadObsIndex returns names', async () => {
|
|
34
|
+
const dataSource = new AnnDataSource({
|
|
35
|
+
url: `@fixtures/zarr/anndata-${version}/anndata-dense.zarr`,
|
|
36
|
+
store: createStoreFromMapContents(fixture),
|
|
37
|
+
});
|
|
38
|
+
const names = await dataSource.loadObsIndex();
|
|
39
|
+
expect(names).toEqual(['CTG', 'GCA', 'CTG']);
|
|
65
40
|
});
|
|
66
|
-
const names = await dataSource.loadObsIndex();
|
|
67
|
-
expect(names).toEqual(['CTG', 'GCA', 'CTG']);
|
|
68
41
|
});
|
|
69
42
|
});
|
|
70
43
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpatialDataTableSource.d.ts","sourceRoot":"","sources":["../src/SpatialDataTableSource.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SpatialDataTableSource.d.ts","sourceRoot":"","sources":["../src/SpatialDataTableSource.js"],"names":[],"mappings":"AAiCA;;;;GAIG;AACH,oCAHW,MAAM,GAAC,SAAS,UAK1B;AAED;;;;GAIG;AACH,oCAHW,MAAM,GAAC,SAAS,UAK1B;AAED;IAOI,iDAAiD;IACjD,YADW;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;KAAE,CACzB;IACpB,iDAAiD;IACjD,YADW;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;KAAE,CACzB;IACpB,wCAAwC;IACxC,YADW;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;KAAE,CAChB;IAGtB;;;;OAIG;IACH,gCAHW,MAAM;;OAKhB;IA2CD;;;;;OAKG;IACH,sBAJW,MAAM,cACN,MAAM,GACJ,OAAO,CAAC,MAAM,EAAE,CAAC,CAa7B;CACF;0BApIyB,oBAAoB"}
|
|
@@ -4,7 +4,8 @@ import AnnDataSource from './AnnDataSource.js';
|
|
|
4
4
|
/** @import { DataSourceParams } from '@vitessce/types' */
|
|
5
5
|
// If the array path starts with table/something/rest
|
|
6
6
|
// capture table/something.
|
|
7
|
-
const
|
|
7
|
+
const pluralRegex = /^tables\/([^/]*)\/(.*)$/;
|
|
8
|
+
const singularRegex = /^table\/([^/]*)\/(.*)$/;
|
|
8
9
|
/**
|
|
9
10
|
*
|
|
10
11
|
* @param {string|undefined} arrPath
|
|
@@ -12,9 +13,14 @@ const regex = /^table\/([^/]*)\/(.*)$/;
|
|
|
12
13
|
*/
|
|
13
14
|
function getTablePrefix(arrPath) {
|
|
14
15
|
if (arrPath) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
// First try the plural "tables/{something}"
|
|
17
|
+
const pluralMatches = arrPath.match(pluralRegex);
|
|
18
|
+
if (pluralMatches && pluralMatches.length === 3) {
|
|
19
|
+
return `tables/${pluralMatches[1]}/`;
|
|
20
|
+
}
|
|
21
|
+
const singularMatches = arrPath.match(singularRegex);
|
|
22
|
+
if (singularMatches && singularMatches.length === 3) {
|
|
23
|
+
return `table/${singularMatches[1]}/`;
|
|
18
24
|
}
|
|
19
25
|
}
|
|
20
26
|
// TODO: what to do here when there are multiple tables?
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObsFeatureMatrixAnndataLoader.d.ts","sourceRoot":"","sources":["../../src/anndata-loaders/ObsFeatureMatrixAnndataLoader.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ObsFeatureMatrixAnndataLoader.d.ts","sourceRoot":"","sources":["../../src/anndata-loaders/ObsFeatureMatrixAnndataLoader.js"],"names":[],"mappings":"AAaA;;GAEG;AACH;IAbE,6EAIF;IAUE,kBAEC;IAED;;;;OAIG;IACH,sCAkBC;IALC,4CAGyC;IAI3C;;;;OAIG;IACH,6CAKC;IAED;;;;OAIG;IACH,yCAGC;IAED;;;OAGG;IACH,uBAIC;IAED;;;;OAIG;IACH,uBAGC;IAED;;;OAGG;IACH,2BAUC;IAJC,8FAEC;IAIH;;;;OAIG;IACH,sDA4BC;IAED;;;;OAIG;IACH,sDAYC;IAED;;;;OAIG;IACH,2BAFa,MAAM,CAgClB;IA1BC,mBAwBE;IAIJ;;;OAGG;IACH,2BAFa,MAAM,CAgClB;IAED;;;OAGG;IACH,8BAoDC;IA1CG,mBAAuE;IAKrE,eAA4E;IAK1E,mFAAiE;IAkCzE;;;;;OAKG;IACH;QAHuB,SAAS;QACnB,MAAM,CA2BlB;IAED;;;;OAIG;IACH,aAFa,MAAM,CAalB;IAED,6CAcC;IAED;;;;QAcC;CACF;sCA9WM,iBAAiB;6BAAjB,iBAAiB"}
|
|
@@ -2,24 +2,11 @@
|
|
|
2
2
|
import { open as zarrOpen, get as zarrGet, slice } from 'zarrita';
|
|
3
3
|
import { createZarrArrayAdapter } from '@vitessce/zarr-utils';
|
|
4
4
|
import { LoaderResult, AbstractTwoStepLoader, AbstractLoaderError, } from '@vitessce/vit-s';
|
|
5
|
+
import { maybeDowncastInt64, concatenateColumnVectors } from './utils.js';
|
|
5
6
|
// Put array of data into an object,
|
|
6
7
|
// to match the expected format of the
|
|
7
8
|
// value returned from the load function.
|
|
8
9
|
const toObject = data => ({ data });
|
|
9
|
-
const concatenateColumnVectors = (arr) => {
|
|
10
|
-
const numCols = arr.length;
|
|
11
|
-
const numRows = arr[0].length;
|
|
12
|
-
const { BYTES_PER_ELEMENT } = arr[0];
|
|
13
|
-
const view = new DataView(new ArrayBuffer(numCols * numRows * BYTES_PER_ELEMENT));
|
|
14
|
-
const TypedArray = arr[0].constructor;
|
|
15
|
-
const dtype = TypedArray.name.replace('Array', '');
|
|
16
|
-
for (let i = 0; i < numCols; i += 1) {
|
|
17
|
-
for (let j = 0; j < numRows; j += 1) {
|
|
18
|
-
view[`set${dtype}`](BYTES_PER_ELEMENT * (j * numCols + i), arr[i][j], true);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return new TypedArray(view.buffer);
|
|
22
|
-
};
|
|
23
10
|
/**
|
|
24
11
|
* Loader for converting zarr into the a cell x gene matrix for use in Genes/Heatmap components.
|
|
25
12
|
*/
|
|
@@ -125,9 +112,10 @@ export default class ObsFeatureMatrixAnndataLoader extends AbstractTwoStepLoader
|
|
|
125
112
|
const { data: rowIndices } = await zarrGet(indexArr, [
|
|
126
113
|
slice(startRowIndex, endRowIndex),
|
|
127
114
|
]);
|
|
128
|
-
|
|
115
|
+
let { data: cellXGeneData } = await zarrGet(cellXGeneArr, [
|
|
129
116
|
slice(startRowIndex, endRowIndex),
|
|
130
117
|
]);
|
|
118
|
+
cellXGeneData = maybeDowncastInt64(cellXGeneData);
|
|
131
119
|
for (let rowIndex = 0; rowIndex < rowIndices.length; rowIndex += 1) {
|
|
132
120
|
geneData[rowIndices[rowIndex]] = cellXGeneData[rowIndex];
|
|
133
121
|
}
|
|
@@ -164,10 +152,12 @@ export default class ObsFeatureMatrixAnndataLoader extends AbstractTwoStepLoader
|
|
|
164
152
|
this._sparseMatrix = this._openSparseArrays().then(async (sparseArrays) => {
|
|
165
153
|
const { path: matrix } = this.getOptions();
|
|
166
154
|
const { shape } = await this.dataSource.getJson(`${matrix}/.zattrs`);
|
|
167
|
-
|
|
155
|
+
// eslint-disable-next-line prefer-const
|
|
156
|
+
let [rows, cols, cellXGene] = await Promise.all(sparseArrays.map(async (arr) => {
|
|
168
157
|
const { data } = await createZarrArrayAdapter(arr).getRaw(null);
|
|
169
158
|
return data;
|
|
170
159
|
}));
|
|
160
|
+
cellXGene = maybeDowncastInt64(cellXGene);
|
|
171
161
|
const cellXGeneMatrix = new Float32Array(shape[0] * shape[1]).fill(0);
|
|
172
162
|
let row = 0;
|
|
173
163
|
rows.forEach((_, index) => {
|
|
@@ -195,10 +185,12 @@ export default class ObsFeatureMatrixAnndataLoader extends AbstractTwoStepLoader
|
|
|
195
185
|
this._sparseMatrix = this._openSparseArrays().then(async (sparseArrays) => {
|
|
196
186
|
const { path: matrix } = this.getOptions();
|
|
197
187
|
const { shape } = await this.dataSource.getJson(`${matrix}/.zattrs`);
|
|
198
|
-
|
|
188
|
+
// eslint-disable-next-line prefer-const
|
|
189
|
+
let [cols, rows, cellXGene] = await Promise.all(sparseArrays.map(async (arr) => {
|
|
199
190
|
const { data } = await createZarrArrayAdapter(arr).getRaw(null);
|
|
200
191
|
return data;
|
|
201
192
|
}));
|
|
193
|
+
cellXGene = maybeDowncastInt64(cellXGene);
|
|
202
194
|
const cellXGeneMatrix = new Float32Array(shape[0] * shape[1]).fill(0);
|
|
203
195
|
let col = 0;
|
|
204
196
|
cols.forEach((_, index) => {
|
|
@@ -242,7 +234,7 @@ export default class ObsFeatureMatrixAnndataLoader extends AbstractTwoStepLoader
|
|
|
242
234
|
}
|
|
243
235
|
this.cellXGene = this.arr
|
|
244
236
|
.then(z => createZarrArrayAdapter(z).getRaw(null))
|
|
245
|
-
.then(({ data }) => toObject(data));
|
|
237
|
+
.then(({ data }) => toObject(maybeDowncastInt64(data)));
|
|
246
238
|
}
|
|
247
239
|
}
|
|
248
240
|
else if (encodingType === 'csr_matrix') {
|
|
@@ -297,7 +289,7 @@ export default class ObsFeatureMatrixAnndataLoader extends AbstractTwoStepLoader
|
|
|
297
289
|
// We can index directly into a normal dense array zarr store via `get`.
|
|
298
290
|
genes = await Promise.all(indices.map(index => this.arr
|
|
299
291
|
.then(z => zarrGet(z, [null, index]))
|
|
300
|
-
.then(({ data }) => data)));
|
|
292
|
+
.then(({ data }) => maybeDowncastInt64(data))));
|
|
301
293
|
}
|
|
302
294
|
return { data: genes, url: null };
|
|
303
295
|
}
|
|
@@ -10,17 +10,22 @@ import anndata_0_7_DenseFixture from '../json-fixtures/anndata-0.7/anndata-dense
|
|
|
10
10
|
import anndata_0_8_CscFixture from '../json-fixtures/anndata-0.8/anndata-csc.json';
|
|
11
11
|
import anndata_0_8_CsrFixture from '../json-fixtures/anndata-0.8/anndata-csr.adata.json';
|
|
12
12
|
import anndata_0_8_DenseFixture from '../json-fixtures/anndata-0.8/anndata-dense.json';
|
|
13
|
+
import anndata_0_9_CscFixture from '../json-fixtures/anndata-0.9/anndata-csc.json';
|
|
14
|
+
import anndata_0_9_CsrFixture from '../json-fixtures/anndata-0.9/anndata-csr.adata.json';
|
|
15
|
+
import anndata_0_9_DenseFixture from '../json-fixtures/anndata-0.9/anndata-dense.json';
|
|
16
|
+
import anndata_0_10_CscFixture from '../json-fixtures/anndata-0.10/anndata-csc.json';
|
|
17
|
+
import anndata_0_10_CsrFixture from '../json-fixtures/anndata-0.10/anndata-csr.adata.json';
|
|
18
|
+
import anndata_0_10_DenseFixture from '../json-fixtures/anndata-0.10/anndata-dense.json';
|
|
13
19
|
import mudata_0_2_CscFixture from '../json-fixtures/mudata-0.2/mudata-csc.json';
|
|
14
20
|
import mudata_0_2_CsrFixture from '../json-fixtures/mudata-0.2/mudata-csr.json';
|
|
15
21
|
import mudata_0_2_DenseFixture from '../json-fixtures/mudata-0.2/mudata-dense.json';
|
|
16
|
-
|
|
22
|
+
const toArray = typedArr => Array.from(typedArr).map(Number);
|
|
23
|
+
function createAnndataLoader(url, mapContents, path = 'X') {
|
|
17
24
|
const store = createStoreFromMapContents(mapContents);
|
|
18
25
|
const config = {
|
|
19
26
|
url,
|
|
20
27
|
fileType: 'obsFeatureMatrix.anndata.zarr',
|
|
21
|
-
options: {
|
|
22
|
-
path: 'X',
|
|
23
|
-
},
|
|
28
|
+
options: { path },
|
|
24
29
|
};
|
|
25
30
|
const source = new AnnDataSource({ ...config, store });
|
|
26
31
|
return new ObsFeatureMatrixAnndataLoader(source, config);
|
|
@@ -38,60 +43,84 @@ const createMudataLoader = (url, mapContents) => {
|
|
|
38
43
|
return new ObsFeatureMatrixAnndataLoader(source, config);
|
|
39
44
|
};
|
|
40
45
|
describe('loaders/ObsFeatureMatrixAnndataLoader', () => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
46
|
+
Object.entries({ 0.7: [anndata_0_7_DenseFixture, anndata_0_7_CsrFixture, anndata_0_7_CscFixture], 0.8: [anndata_0_8_DenseFixture, anndata_0_8_CsrFixture, anndata_0_8_CscFixture], 0.9: [anndata_0_9_DenseFixture, anndata_0_9_CsrFixture, anndata_0_9_CscFixture], '0.10': [anndata_0_10_DenseFixture, anndata_0_10_CsrFixture, anndata_0_10_CscFixture] }).forEach(([version, fixtures]) => {
|
|
47
|
+
describe(`AnnData v${version}`, () => {
|
|
48
|
+
const [denseFixture, csrFixture, cscFixture] = fixtures;
|
|
49
|
+
const loaderCsr = createAnndataLoader(`@fixtures/zarr/anndata-${version}/anndata-csr${version !== '0.7' ? '.adata' : ''}.zarr`, csrFixture);
|
|
50
|
+
const loaderDense = createAnndataLoader(`@fixtures/zarr/anndata-${version}/anndata-dense.zarr`, denseFixture);
|
|
51
|
+
const loaderCsc = createAnndataLoader(`@fixtures/zarr/anndata-${version}/anndata-csc.zarr`, cscFixture);
|
|
52
|
+
it('loadFilteredGeneNames returns gene names', async () => {
|
|
53
|
+
const names = await loaderDense.loadFilteredGeneNames();
|
|
54
|
+
expect(names).toEqual(Array.from({ length: 15 }).map((_, i) => `gene_${i}`));
|
|
55
|
+
});
|
|
56
|
+
it('loadGeneSelection matches across storage methods', async () => {
|
|
57
|
+
const selection = { selection: ['gene_1', 'gene_5'] };
|
|
58
|
+
const csrSelection = await loaderCsr.loadGeneSelection(selection);
|
|
59
|
+
const denseSelection = await loaderDense.loadGeneSelection(selection);
|
|
60
|
+
const cscSelection = await loaderCsc.loadGeneSelection(selection);
|
|
61
|
+
expect(cscSelection).toEqual(denseSelection);
|
|
62
|
+
expect(csrSelection).toEqual(denseSelection);
|
|
63
|
+
});
|
|
64
|
+
it('loadCellXGene matches across storage methods', async () => {
|
|
65
|
+
const csrMatrix = await loaderCsr.loadCellXGene();
|
|
66
|
+
const denseMatrix = await loaderDense.loadCellXGene();
|
|
67
|
+
const cscMatrix = await loaderCsc.loadCellXGene();
|
|
68
|
+
expect(cscMatrix).toEqual(denseMatrix);
|
|
69
|
+
expect(csrMatrix).toEqual(denseMatrix);
|
|
70
|
+
});
|
|
71
|
+
it('loadCellXGene matches across dtypes', async () => {
|
|
72
|
+
const csrMatrix = await loaderCsr.loadCellXGene();
|
|
73
|
+
const denseMatrix = await loaderDense.loadCellXGene();
|
|
74
|
+
const cscMatrix = await loaderCsc.loadCellXGene();
|
|
75
|
+
const getDataFromDtype = async (dtype) => {
|
|
76
|
+
const loaderCsrDtype = createAnndataLoader(`@fixtures/zarr/anndata-${version}/anndata-csr${version !== '0.7' ? '.adata' : ''}.zarr`, csrFixture, `layers/${dtype}`);
|
|
77
|
+
const loaderDenseDtype = createAnndataLoader(`@fixtures/zarr/anndata-${version}/anndata-dense.zarr`, denseFixture, `layers/${dtype}`);
|
|
78
|
+
const loaderCscDtype = createAnndataLoader(`@fixtures/zarr/anndata-${version}/anndata-csc.zarr`, cscFixture, `layers/${dtype}`);
|
|
79
|
+
const csrMatrixDtype = await loaderCsrDtype.loadCellXGene();
|
|
80
|
+
const denseMatrixDtype = await loaderDenseDtype.loadCellXGene();
|
|
81
|
+
const cscMatrixDtype = await loaderCscDtype.loadCellXGene();
|
|
82
|
+
return {
|
|
83
|
+
csrMatrix: csrMatrixDtype,
|
|
84
|
+
denseMatrix: denseMatrixDtype,
|
|
85
|
+
cscMatrix: cscMatrixDtype,
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
const dataInt32 = await getDataFromDtype('int32');
|
|
89
|
+
const dataInt64 = await getDataFromDtype('int64');
|
|
90
|
+
expect(toArray(cscMatrix)).toEqual(toArray(dataInt32.cscMatrix));
|
|
91
|
+
expect(toArray(csrMatrix)).toEqual(toArray(dataInt32.csrMatrix));
|
|
92
|
+
expect(toArray(denseMatrix)).toEqual(toArray(dataInt32.denseMatrix));
|
|
93
|
+
expect(toArray(cscMatrix)).toEqual(toArray(dataInt64.cscMatrix));
|
|
94
|
+
expect(toArray(csrMatrix)).toEqual(toArray(dataInt64.csrMatrix));
|
|
95
|
+
expect(toArray(denseMatrix)).toEqual(toArray(dataInt64.denseMatrix));
|
|
96
|
+
});
|
|
97
|
+
it('loadCellXGeneSelection matches across dtypes', async () => {
|
|
98
|
+
const selection = { selection: ['gene_1', 'gene_5'] };
|
|
99
|
+
const csrMatrix = await loaderCsr.loadGeneSelection(selection);
|
|
100
|
+
const denseMatrix = await loaderDense.loadGeneSelection(selection);
|
|
101
|
+
const cscMatrix = await loaderCsc.loadGeneSelection(selection);
|
|
102
|
+
const getDataFromDtype = async (dtype) => {
|
|
103
|
+
const loaderCsrDtype = createAnndataLoader(`@fixtures/zarr/anndata-${version}/anndata-csr${version !== '0.7' ? '.adata' : ''}.zarr`, csrFixture, `layers/${dtype}`);
|
|
104
|
+
const loaderDenseDtype = createAnndataLoader(`@fixtures/zarr/anndata-${version}/anndata-dense.zarr`, denseFixture, `layers/${dtype}`);
|
|
105
|
+
const loaderCscDtype = createAnndataLoader(`@fixtures/zarr/anndata-${version}/anndata-csc.zarr`, cscFixture, `layers/${dtype}`);
|
|
106
|
+
const csrMatrixDtype = await loaderCsrDtype.loadGeneSelection(selection);
|
|
107
|
+
const denseMatrixDtype = await loaderDenseDtype.loadGeneSelection(selection);
|
|
108
|
+
const cscMatrixDtype = await loaderCscDtype.loadGeneSelection(selection);
|
|
109
|
+
return {
|
|
110
|
+
csrMatrix: csrMatrixDtype,
|
|
111
|
+
denseMatrix: denseMatrixDtype,
|
|
112
|
+
cscMatrix: cscMatrixDtype,
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
const dataInt32 = await getDataFromDtype('int32');
|
|
116
|
+
const dataInt64 = await getDataFromDtype('int64');
|
|
117
|
+
expect(toArray(cscMatrix)).toEqual(toArray(dataInt32.cscMatrix));
|
|
118
|
+
expect(toArray(csrMatrix)).toEqual(toArray(dataInt32.csrMatrix));
|
|
119
|
+
expect(toArray(denseMatrix)).toEqual(toArray(dataInt32.denseMatrix));
|
|
120
|
+
expect(toArray(cscMatrix)).toEqual(toArray(dataInt64.cscMatrix));
|
|
121
|
+
expect(toArray(csrMatrix)).toEqual(toArray(dataInt64.csrMatrix));
|
|
122
|
+
expect(toArray(denseMatrix)).toEqual(toArray(dataInt64.denseMatrix));
|
|
123
|
+
});
|
|
95
124
|
});
|
|
96
125
|
});
|
|
97
126
|
describe('MuData v0.2', () => {
|