@vitessce/zarr 3.3.11 → 3.4.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/dist/{deflate-b162c7aa.js → deflate-12689d34.js} +1 -1
- package/dist/{index-184aee21.js → index-039fe231.js} +5749 -3102
- package/dist/index.js +1 -1
- package/dist/{jpeg-dbb0f9d9.js → jpeg-ceda224f.js} +1 -1
- package/dist/{lerc-e45d57dc.js → lerc-5c5d32d4.js} +1 -1
- package/dist/{lzw-05e88e18.js → lzw-ddb8bb91.js} +1 -1
- package/dist/{packbits-922f4592.js → packbits-c36ade4c.js} +1 -1
- package/dist/{raw-a8de9c08.js → raw-68a120cf.js} +1 -1
- package/dist/{webimage-27013e2d.js → webimage-df6b461e.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
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-039fe231.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-039fe231.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', () => {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function convertBigInt64ArrayToInt32Array(arr: any): Int32Array;
|
|
2
|
+
export class IncorrectDataTypeError extends Error {
|
|
3
|
+
constructor(message: any);
|
|
4
|
+
}
|
|
5
|
+
export function maybeDowncastInt64(data: any): any;
|
|
6
|
+
export function concatenateColumnVectors(arr: any): any;
|
|
7
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/anndata-loaders/utils.js"],"names":[],"mappings":"AAQA,uEAoBC;AA3BD;IACE,0BAGC;CACF;AAyBM,mDASN;AACM,wDAaN"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export class IncorrectDataTypeError extends Error {
|
|
2
|
+
constructor(message) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = 'IncorrectDataTypeError';
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export function convertBigInt64ArrayToInt32Array(arr) {
|
|
8
|
+
if (!(arr instanceof BigInt64Array)) { // eslint-disable-line no-undef
|
|
9
|
+
throw new IncorrectDataTypeError('Expected a BigInt64Array');
|
|
10
|
+
}
|
|
11
|
+
const out = new Int32Array(arr.length);
|
|
12
|
+
// Create a view of the BigInt64Array buffer as a Int32Array (2x elements of out)
|
|
13
|
+
const view = new Int32Array(arr.buffer);
|
|
14
|
+
for (let i = 0; i < arr.length; i++) {
|
|
15
|
+
/**
|
|
16
|
+
* Get the lower 32 bits of each 64-bit value.
|
|
17
|
+
*
|
|
18
|
+
* Since each 64-bit value takes up 2 slots in the Int32Array view, we
|
|
19
|
+
* multiply the index by 2 to get the correct position (assuming
|
|
20
|
+
* little-endian). Note that we are ignoring the upper bits because
|
|
21
|
+
* data will never actually need 64 bits of integer precision.
|
|
22
|
+
* If this comes up someone can open an issue.
|
|
23
|
+
*/
|
|
24
|
+
out[i] = view[i * 2];
|
|
25
|
+
}
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
// eslint-disable-next-line no-undef
|
|
29
|
+
export const maybeDowncastInt64 = (data) => {
|
|
30
|
+
try {
|
|
31
|
+
return convertBigInt64ArrayToInt32Array(data);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (error instanceof IncorrectDataTypeError) {
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export const concatenateColumnVectors = (arr) => {
|
|
41
|
+
const numCols = arr.length;
|
|
42
|
+
const numRows = arr[0].length;
|
|
43
|
+
const { BYTES_PER_ELEMENT } = arr[0];
|
|
44
|
+
const view = new DataView(new ArrayBuffer(numCols * numRows * BYTES_PER_ELEMENT));
|
|
45
|
+
const TypedArray = arr[0].constructor;
|
|
46
|
+
const dtype = TypedArray.name.replace('Array', '');
|
|
47
|
+
for (let i = 0; i < numCols; i += 1) {
|
|
48
|
+
for (let j = 0; j < numRows; j += 1) {
|
|
49
|
+
view[`set${dtype}`](BYTES_PER_ELEMENT * (j * numCols + i), arr[i][j], true);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return new TypedArray(view.buffer);
|
|
53
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../../src/anndata-loaders/utils.test.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { convertBigInt64ArrayToInt32Array, IncorrectDataTypeError } from './utils.js';
|
|
2
|
+
const toArray = typedArr => Array.from(typedArr).map(Number);
|
|
3
|
+
describe('loaders/utils', () => {
|
|
4
|
+
describe('convertBigInt64ArrayToInt32Array', () => {
|
|
5
|
+
it('check data equality', async () => {
|
|
6
|
+
const data = [1n, 2n, 3n, 4n, 5n];
|
|
7
|
+
const bigIntArray = new BigInt64Array(data); // eslint-disable-line no-undef
|
|
8
|
+
expect(new Int32Array(toArray(bigIntArray)))
|
|
9
|
+
.toEqual(convertBigInt64ArrayToInt32Array(bigIntArray));
|
|
10
|
+
});
|
|
11
|
+
it('check error', async () => {
|
|
12
|
+
const array = new Int32Array([1, 2, 3, 4, 5]);
|
|
13
|
+
expect(() => convertBigInt64ArrayToInt32Array(array))
|
|
14
|
+
.toThrow(IncorrectDataTypeError);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenomicProfilesZarrLoader.d.ts","sourceRoot":"","sources":["../../src/genomic-loaders/GenomicProfilesZarrLoader.js"],"names":[],"mappings":"AAEA;IAEO,
|
|
1
|
+
{"version":3,"file":"GenomicProfilesZarrLoader.d.ts","sourceRoot":"","sources":["../../src/genomic-loaders/GenomicProfilesZarrLoader.js"],"names":[],"mappings":"AAEA;IAEO,6EAQuB;IAT5B,iBAMC;IAFC,WAA+C;IAIjD,YASC;CACF;sCArBmD,iBAAiB"}
|
|
@@ -8,8 +8,8 @@ export default class GenomicProfilesZarrLoader extends AbstractTwoStepLoader {
|
|
|
8
8
|
return this.attrs;
|
|
9
9
|
}
|
|
10
10
|
load() {
|
|
11
|
-
const { url } = this;
|
|
11
|
+
const { url, requestInit } = this;
|
|
12
12
|
return this.loadAttrs()
|
|
13
|
-
.then(attrs => Promise.resolve(new LoaderResult(attrs, url)));
|
|
13
|
+
.then(attrs => Promise.resolve(new LoaderResult(attrs, url, null, requestInit)));
|
|
14
14
|
}
|
|
15
15
|
}
|