@vitessce/zarr 2.0.1 → 2.0.3-beta.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.
@@ -0,0 +1,70 @@
1
+ import AnnDataSource from './AnnDataSource';
2
+ // If the array path starts with mod/something/rest
3
+ // capture mod/something.
4
+ const regex = /^mod\/([^/]*)\/(.*)$/;
5
+ function getModPrefix(arrPath) {
6
+ if (arrPath) {
7
+ const matches = arrPath.match(regex);
8
+ if (matches && matches.length === 3) {
9
+ return `mod/${matches[1]}/`;
10
+ }
11
+ }
12
+ return '';
13
+ }
14
+ export function getObsPath(arrPath) {
15
+ return `${getModPrefix(arrPath)}obs`;
16
+ }
17
+ export function getVarPath(arrPath) {
18
+ return `${getModPrefix(arrPath)}var`;
19
+ }
20
+ export default class MuDataSource extends AnnDataSource {
21
+ /**
22
+ * Class method for loading the obs index.
23
+ * @returns {Promise} An promise for a zarr array containing the indices.
24
+ */
25
+ loadObsIndex(path = null) {
26
+ if (!this.obsIndex) {
27
+ this.obsIndex = {};
28
+ }
29
+ const obsPath = getObsPath(path);
30
+ if (this.obsIndex[obsPath]) {
31
+ return this.obsIndex[obsPath];
32
+ }
33
+ this.obsIndex[obsPath] = this.getJson(`${obsPath}/.zattrs`)
34
+ .then(({ _index }) => this.getFlatArrDecompressed(`${obsPath}/${_index}`));
35
+ return this.obsIndex[obsPath];
36
+ }
37
+ /**
38
+ * Class method for loading the var index.
39
+ * @returns {Promise} An promise for a zarr array containing the indices.
40
+ */
41
+ loadVarIndex(path = null) {
42
+ if (!this.varIndex) {
43
+ this.varIndex = {};
44
+ }
45
+ const varPath = getVarPath(path);
46
+ if (this.varIndex[varPath]) {
47
+ return this.varIndex[varPath];
48
+ }
49
+ this.varIndex[varPath] = this.getJson(`${varPath}/.zattrs`)
50
+ .then(({ _index }) => this.getFlatArrDecompressed(`${varPath}/${_index}`));
51
+ return this.varIndex[varPath];
52
+ }
53
+ /**
54
+ * Class method for loading the var alias.
55
+ * @returns {Promise} An promise for a zarr array containing the aliased names.
56
+ */
57
+ async loadVarAlias(varPath, matrixPath) {
58
+ if (!this.varAlias) {
59
+ this.varAlias = {};
60
+ }
61
+ if (this.varAlias[varPath]) {
62
+ return this.varAlias[varPath];
63
+ }
64
+ const [varAliasData] = await this.loadVarColumns([varPath]);
65
+ this.varAlias[varPath] = varAliasData;
66
+ const index = await this.loadVarIndex(matrixPath);
67
+ this.varAlias[varPath] = this.varAlias[varPath].map((val, ind) => (val ? val.concat(` (${index[ind]})`) : index[ind]));
68
+ return this.varAlias[varPath];
69
+ }
70
+ }
@@ -0,0 +1,42 @@
1
+ import range from 'lodash/range';
2
+ import MuDataSource, { getObsPath, getVarPath } from './MuDataSource';
3
+ describe('sources/MuDataSource', () => {
4
+ it('loadObsColumns returns ids for location in store, with joint-modality path', async () => {
5
+ const dataSource = new MuDataSource({
6
+ url: 'http://localhost:51204/@fixtures/zarr/mudata-0.2/mudata-dense.zarr',
7
+ });
8
+ const ids = await dataSource.loadObsColumns(['obs/leiden']);
9
+ expect(ids).toEqual([['3', '2', '3']]);
10
+ });
11
+ it('loadObsColumns returns ids for location in store, with modality-specific path', async () => {
12
+ const dataSource = new MuDataSource({
13
+ url: 'http://localhost:51204/@fixtures/zarr/mudata-0.2/mudata-dense.zarr',
14
+ });
15
+ const ids = await dataSource.loadObsColumns(['mod/rna/obs/leiden']);
16
+ expect(ids).toEqual([['1', '1', '2']]);
17
+ });
18
+ it('loadVarIndex supports modality-specific paths', async () => {
19
+ const dataSource = new MuDataSource({
20
+ url: 'http://localhost:51204/@fixtures/zarr/mudata-0.2/mudata-dense.zarr',
21
+ });
22
+ const names = await dataSource.loadVarIndex('mod/atac/X');
23
+ expect(names).toEqual(range(15).map(i => `peak_${i}`));
24
+ });
25
+ it('loadObsIndex returns names', async () => {
26
+ const dataSource = new MuDataSource({
27
+ url: 'http://localhost:51204/@fixtures/zarr/mudata-0.2/mudata-dense.zarr',
28
+ });
29
+ const names = await dataSource.loadObsIndex('mod/atac/X');
30
+ expect(names).toEqual(['CTG', 'GCA', 'CTT']);
31
+ });
32
+ it('getObsPath regex works', async () => {
33
+ expect(getObsPath('mod/rna/obsm/X_umap')).toEqual('mod/rna/obs');
34
+ expect(getObsPath('mod/rna/X')).toEqual('mod/rna/obs');
35
+ expect(getObsPath('obsm/X_umap')).toEqual('obs');
36
+ });
37
+ it('getVarPath regex works', async () => {
38
+ expect(getVarPath('mod/rna/obsm/X_umap')).toEqual('mod/rna/var');
39
+ expect(getVarPath('mod/rna/X')).toEqual('mod/rna/var');
40
+ expect(getVarPath('obsm/X_umap')).toEqual('var');
41
+ });
42
+ });
@@ -22,14 +22,14 @@ export default class FeatureLabelsAnndataLoader extends AbstractTwoStepLoader {
22
22
  * Class method for loading feature string labels.
23
23
  * @returns {Promise} A promise for the array.
24
24
  */
25
- async loadLabels() {
25
+ loadLabels() {
26
26
  const { path } = this.options;
27
27
  if (this.labels) {
28
28
  return this.labels;
29
29
  }
30
30
  if (!this.labels) {
31
31
  // eslint-disable-next-line no-underscore-dangle
32
- this.labels = await this.dataSource._loadColumn(path);
32
+ this.labels = this.dataSource._loadColumn(path);
33
33
  return this.labels;
34
34
  }
35
35
  this.labels = Promise.resolve(null);
@@ -11,13 +11,13 @@ export default class ObsEmbeddingAnndataLoader extends AbstractTwoStepLoader {
11
11
  * Class method for loading embedding coordinates, such as those from UMAP or t-SNE.
12
12
  * @returns {Promise} A promise for an array of columns.
13
13
  */
14
- async loadEmbedding() {
14
+ loadEmbedding() {
15
15
  const { path, dims = [0, 1] } = this.options;
16
16
  if (this.embedding) {
17
17
  return this.embedding;
18
18
  }
19
19
  if (!this.embedding) {
20
- this.embedding = await this.dataSource.loadNumericForDims(path, dims);
20
+ this.embedding = this.dataSource.loadNumericForDims(path, dims);
21
21
  return this.embedding;
22
22
  }
23
23
  this.embedding = Promise.resolve(null);
@@ -11,14 +11,14 @@ export default class ObsLabelsAnndataLoader extends AbstractTwoStepLoader {
11
11
  * Class method for loading observation string labels.
12
12
  * @returns {Promise} A promise for the array.
13
13
  */
14
- async loadLabels() {
14
+ loadLabels() {
15
15
  const { path } = this.options;
16
16
  if (this.labels) {
17
17
  return this.labels;
18
18
  }
19
19
  if (!this.labels) {
20
20
  // eslint-disable-next-line no-underscore-dangle
21
- this.labels = await this.dataSource._loadColumn(path);
21
+ this.labels = this.dataSource._loadColumn(path);
22
22
  return this.labels;
23
23
  }
24
24
  this.labels = Promise.resolve(null);
@@ -11,13 +11,13 @@ export default class ObsLocationsAnndataLoader extends AbstractTwoStepLoader {
11
11
  * Class method for loading embedding coordinates, such as those from UMAP or t-SNE.
12
12
  * @returns {Promise} A promise for an array of columns.
13
13
  */
14
- async loadLocations() {
14
+ loadLocations() {
15
15
  const { path, dims = [0, 1] } = this.options;
16
16
  if (this.locations) {
17
17
  return this.locations;
18
18
  }
19
19
  if (!this.locations) {
20
- this.locations = await this.dataSource.loadNumericForDims(path, dims);
20
+ this.locations = this.dataSource.loadNumericForDims(path, dims);
21
21
  return this.locations;
22
22
  }
23
23
  this.locations = Promise.resolve(null);
@@ -12,13 +12,20 @@ export default class ObsSegmentationsAnndataLoader extends AbstractTwoStepLoader
12
12
  * Class method for loading embedding coordinates, such as those from UMAP or t-SNE.
13
13
  * @returns {Promise} A promise for an array of columns.
14
14
  */
15
- async loadSegmentations() {
15
+ loadSegmentations() {
16
16
  const { path } = this.options;
17
17
  if (this.segmentations) {
18
18
  return this.segmentations;
19
19
  }
20
20
  if (!this.segmentations) {
21
- this.segmentations = await this.dataSource.loadNumeric(path);
21
+ this.segmentations = this.dataSource.loadNumeric(path).then(arr => ({
22
+ ...arr,
23
+ // Bug introduced from DeckGL v8.6.x to v8.8.x:
24
+ // Polygon vertices cannot be passed via Uint32Arrays, which is how they load via Zarr.
25
+ // For now, a workaround is to cast each vertex to a plain Array.
26
+ data: arr.data
27
+ .map(poly => poly.map(vertex => Array.from(vertex))),
28
+ }));
22
29
  return this.segmentations;
23
30
  }
24
31
  this.segmentations = Promise.resolve(null);
package/dist/utils.js ADDED
@@ -0,0 +1,5 @@
1
+ export function dirname(path) {
2
+ const arr = path.split('/');
3
+ arr.pop();
4
+ return arr.join('/');
5
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitessce/zarr",
3
- "version": "2.0.1",
3
+ "version": "2.0.3-beta.0",
4
4
  "author": "Gehlenborg Lab",
5
5
  "homepage": "http://vitessce.io",
6
6
  "repository": {
@@ -16,12 +16,12 @@
16
16
  "d3-array": "^2.4.0",
17
17
  "lodash": "^4.17.21",
18
18
  "zarr": "0.5.1",
19
- "@vitessce/constants-internal": "2.0.1",
20
- "@vitessce/gl": "2.0.1",
21
- "@vitessce/sets-utils": "2.0.1",
22
- "@vitessce/spatial-utils": "2.0.1",
23
- "@vitessce/utils": "2.0.1",
24
- "@vitessce/vit-s": "2.0.1"
19
+ "@vitessce/constants-internal": "2.0.3-beta.0",
20
+ "@vitessce/sets-utils": "2.0.3-beta.0",
21
+ "@vitessce/gl": "2.0.3-beta.0",
22
+ "@vitessce/vit-s": "2.0.3-beta.0",
23
+ "@vitessce/utils": "2.0.3-beta.0",
24
+ "@vitessce/spatial-utils": "2.0.3-beta.0"
25
25
  },
26
26
  "scripts": {
27
27
  "start": "tsc --watch",