@vitessce/zarr 2.0.2 → 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
+ });
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.2",
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.2",
20
- "@vitessce/gl": "2.0.2",
21
- "@vitessce/sets-utils": "2.0.2",
22
- "@vitessce/spatial-utils": "2.0.2",
23
- "@vitessce/utils": "2.0.2",
24
- "@vitessce/vit-s": "2.0.2"
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",