@vitessce/zarr 3.5.7 → 3.5.8

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.
Files changed (35) hide show
  1. package/dist/index.js +743 -195
  2. package/dist/zstd-561fda0e.js +778 -0
  3. package/dist-tsc/AnnDataSource.d.ts +3 -4
  4. package/dist-tsc/AnnDataSource.d.ts.map +1 -1
  5. package/dist-tsc/AnnDataSource.js +1 -2
  6. package/dist-tsc/ZarrDataSource.d.ts +3 -4
  7. package/dist-tsc/ZarrDataSource.d.ts.map +1 -1
  8. package/dist-tsc/ZarrDataSource.js +1 -2
  9. package/dist-tsc/anndata-loaders/ComparisonMetadataAnndataLoader.d.ts +20 -0
  10. package/dist-tsc/anndata-loaders/ComparisonMetadataAnndataLoader.d.ts.map +1 -0
  11. package/dist-tsc/anndata-loaders/ComparisonMetadataAnndataLoader.js +29 -0
  12. package/dist-tsc/anndata-loaders/FeatureSetStatsAnndataLoader.d.ts +49 -0
  13. package/dist-tsc/anndata-loaders/FeatureSetStatsAnndataLoader.d.ts.map +1 -0
  14. package/dist-tsc/anndata-loaders/FeatureSetStatsAnndataLoader.js +143 -0
  15. package/dist-tsc/anndata-loaders/FeatureStatsAnndataLoader.d.ts +53 -0
  16. package/dist-tsc/anndata-loaders/FeatureStatsAnndataLoader.d.ts.map +1 -0
  17. package/dist-tsc/anndata-loaders/FeatureStatsAnndataLoader.js +157 -0
  18. package/dist-tsc/anndata-loaders/ObsSetStatsAnndataLoader.d.ts +66 -0
  19. package/dist-tsc/anndata-loaders/ObsSetStatsAnndataLoader.d.ts.map +1 -0
  20. package/dist-tsc/anndata-loaders/ObsSetStatsAnndataLoader.js +183 -0
  21. package/dist-tsc/anndata-loaders/comparative-utils.d.ts +19 -0
  22. package/dist-tsc/anndata-loaders/comparative-utils.d.ts.map +1 -0
  23. package/dist-tsc/anndata-loaders/comparative-utils.js +30 -0
  24. package/dist-tsc/anndata-loaders/index.d.ts +4 -0
  25. package/dist-tsc/anndata-loaders/index.js +4 -0
  26. package/package.json +11 -14
  27. package/src/AnnDataSource.js +1 -2
  28. package/src/ZarrDataSource.js +1 -2
  29. package/src/anndata-loaders/ComparisonMetadataAnndataLoader.js +34 -0
  30. package/src/anndata-loaders/FeatureSetStatsAnndataLoader.js +164 -0
  31. package/src/anndata-loaders/FeatureStatsAnndataLoader.js +177 -0
  32. package/src/anndata-loaders/ObsSetStatsAnndataLoader.js +211 -0
  33. package/src/anndata-loaders/comparative-utils.js +35 -0
  34. package/src/anndata-loaders/index.js +4 -0
  35. package/dist/zstd-ec5a40b8.js +0 -808
@@ -0,0 +1,183 @@
1
+ /* eslint-disable no-underscore-dangle */
2
+ /* eslint-disable camelcase */
3
+ import { LoaderResult, AbstractTwoStepLoader } from '@vitessce/abstract';
4
+ import { isEqual } from 'lodash-es';
5
+ import { isEqualPathPair, loadComparisonMetadata } from './comparative-utils.js';
6
+ /** @import AnnDataSource from '../AnnDataSource.js' */
7
+ /** @import { ObsSetStatsData } from '@vitessce/types' */
8
+ /**
9
+ * Loader for string arrays located in anndata.zarr stores.
10
+ * @template {AnnDataSource} DataSourceType
11
+ * @extends {AbstractTwoStepLoader<DataSourceType>}
12
+ */
13
+ export default class ObsSetStatsAnndataLoader extends AbstractTwoStepLoader {
14
+ /**
15
+ * Class method for loading feature string labels.
16
+ * @returns {Promise<any>} A promise for the array.
17
+ */
18
+ async loadInterceptValues(dfPath) {
19
+ const { interceptExpectedSampleColumn } = this.options;
20
+ // Check the options to determine whether the significance values are pre-transformed
21
+ // or if we still need to compute minus log10 here.
22
+ const values = await this.dataSource.loadNumeric(`${dfPath}/${interceptExpectedSampleColumn}`);
23
+ return values.data;
24
+ }
25
+ /**
26
+ * Class method for loading feature string labels.
27
+ * @returns {Promise<any>} A promise for the array.
28
+ */
29
+ async loadEffectValues(dfPath) {
30
+ const { effectExpectedSampleColumn } = this.options;
31
+ // Check the options to determine whether the significance values are pre-transformed
32
+ // or if we still need to compute minus log10 here.
33
+ const values = await this.dataSource.loadNumeric(`${dfPath}/${effectExpectedSampleColumn}`);
34
+ return values.data;
35
+ }
36
+ /**
37
+ * Class method for loading feature string labels.
38
+ * @returns {Promise<any>} A promise for the array.
39
+ */
40
+ async loadIsCredible(dfPath) {
41
+ const { isCredibleEffectColumn } = this.options;
42
+ // Check the options to determine whether the significance values are pre-transformed
43
+ // or if we still need to compute minus log10 here.
44
+ const values = await this.dataSource.loadNumeric(`${dfPath}/${isCredibleEffectColumn}`);
45
+ return Array.from(values.data);
46
+ }
47
+ /**
48
+ * Class method for loading feature string labels.
49
+ * @returns {Promise<any>} A promise for the array.
50
+ */
51
+ async loadFoldChanges(dfPath) {
52
+ const { foldChangeColumn, foldChangeTransformation } = this.options;
53
+ // Check the options to determine whether the significance values are pre-transformed
54
+ // or if we still need to compute log2 here.
55
+ const values = await this.dataSource.loadNumeric(`${dfPath}/${foldChangeColumn}`);
56
+ // Invert the transformation
57
+ if (foldChangeTransformation === 'log2') {
58
+ values.data = values.data.map(val => (2 ** val));
59
+ }
60
+ return values.data;
61
+ }
62
+ async loadCovariate(dfPath) {
63
+ const { covariateColumn } = this.options;
64
+ return this.dataSource._loadColumn(`${dfPath}/${covariateColumn}`);
65
+ }
66
+ async loadObsSetNames(dfPath) {
67
+ const { indexColumn } = this.options;
68
+ if (indexColumn) {
69
+ return this.dataSource._loadColumn(`${dfPath}/${indexColumn}`);
70
+ }
71
+ // Use the default dataframe index column in this case.
72
+ return this.dataSource.loadDataFrameIndex(dfPath);
73
+ }
74
+ async loadDataFrame(dfPath) {
75
+ const [obsSetId, obsSetFoldChange, interceptExpectedSample, effectExpectedSample, isCredibleEffect,
76
+ // TODO: rather than passing this down,
77
+ // do the fold change direction swapping in the loader
78
+ // (as opposed to in the view).
79
+ // TODO: also, see https://github.com/keller-mark/compasce/issues/30
80
+ // which would allow not loading this column altogether.
81
+ covariate,] = await Promise.all([
82
+ this.loadObsSetNames(dfPath),
83
+ this.loadFoldChanges(dfPath),
84
+ this.loadInterceptValues(dfPath),
85
+ this.loadEffectValues(dfPath),
86
+ this.loadIsCredible(dfPath),
87
+ this.loadCovariate(dfPath),
88
+ ]);
89
+ return {
90
+ obsSetId,
91
+ obsSetFoldChange,
92
+ interceptExpectedSample,
93
+ effectExpectedSample,
94
+ isCredibleEffect,
95
+ covariate,
96
+ };
97
+ }
98
+ /**
99
+ *
100
+ * @returns {Promise<StatsMeta[]>}
101
+ */
102
+ async loadMetadata() {
103
+ const { metadataPath } = this.options;
104
+ if (this.metadata) {
105
+ return this.metadata;
106
+ }
107
+ if (!this.metadata) {
108
+ this.metadata = await loadComparisonMetadata(this.dataSource, metadataPath);
109
+ return this.metadata;
110
+ }
111
+ return this.metadata;
112
+ }
113
+ /**
114
+ * Load data from multiple dataframes, merged.
115
+ * @param {object} volcanoOptions
116
+ * @param {string[]|null} [volcanoOptions.sampleFacet]
117
+ * @param {string[]|null} [volcanoOptions.obsSetFacet]
118
+ * @param {number|null} [volcanoOptions.topK]
119
+ * @param {string[][]|null} [volcanoOptions.sampleSetSelection]
120
+ * @returns {Promise<LoaderResult<ObsSetStatsData>>}
121
+ */
122
+ async loadMulti(volcanoOptions) {
123
+ const { analysisType: targetAnalysisType = 'sccoda_df' } = this.options;
124
+ const { sampleSetSelection, obsSetSelection } = volcanoOptions || {};
125
+ // We expect these set paths to have already been transformed
126
+ // to use the "raw" column names,
127
+ // according to the mappings defined in obsSets and sampleSets loader options.
128
+ // The values in the comparison_metadata have the "raw" column names.
129
+ const rawObsSetSelection = obsSetSelection;
130
+ const rawSampleSetSelection = sampleSetSelection;
131
+ if (!sampleSetSelection || sampleSetSelection?.length !== 2) {
132
+ return Promise.reject(new Error('Expected exactly two sample sets for cell type composition analysis plot.'));
133
+ }
134
+ if (!obsSetSelection) {
135
+ return Promise.reject(new Error('Expected obsSetSelection to be present.'));
136
+ }
137
+ const metadata = await this.loadMetadata();
138
+ // For cell type composition analysis,
139
+ // results have `obsSetSelection: [['cell_type']]`
140
+ // to indicate that the analysis was performed using this obsSet grouping.
141
+ // Here, we obtain the unique obsSet groupings from the obsSetSelection paths.
142
+ const rawObsSetGroups = Array.from(new Set(rawObsSetSelection.map(setPath => setPath?.[0])));
143
+ // Match metadata against to get paths to dataframe(s) of interest.
144
+ const matchingComparisons = [];
145
+ Object.values(metadata.comparisons).forEach((comparisonGroupObject) => {
146
+ const { results } = comparisonGroupObject;
147
+ results.forEach((resultObject) => {
148
+ const { analysis_type,
149
+ // analysis_params,
150
+ coordination_values,
151
+ // path,
152
+ } = resultObject;
153
+ if (analysis_type === targetAnalysisType) {
154
+ // This is a diff. exp. result.
155
+ if (sampleSetSelection) {
156
+ // Comparing two sample groups.
157
+ if (isEqual([rawObsSetGroups], coordination_values.obsSetSelection)) {
158
+ // The obsSetSelection matches.
159
+ // Now check whether the sampleSetSelection matches.
160
+ if (isEqualPathPair(rawSampleSetSelection, coordination_values.sampleSetFilter)) {
161
+ matchingComparisons.push(resultObject);
162
+ }
163
+ }
164
+ }
165
+ }
166
+ });
167
+ });
168
+ // Using this matchingComparisons list,
169
+ // load the relevant columns of each matching dataframe and concatenate them together.
170
+ const result = await Promise.all(matchingComparisons.map(async (comparisonObject) => {
171
+ const df = await this.loadDataFrame(comparisonObject.path);
172
+ return {
173
+ df,
174
+ metadata: comparisonObject,
175
+ };
176
+ }));
177
+ return new LoaderResult({ obsSetStats: result }, null);
178
+ }
179
+ // eslint-disable-next-line class-methods-use-this
180
+ async load() {
181
+ throw new Error('The load() method is not implemented for ObsSetStatsAnndataLoader.');
182
+ }
183
+ }
@@ -0,0 +1,19 @@
1
+ /** @import AnnDataSource from '../AnnDataSource.js' */
2
+ /**
3
+ * Do two pairs of paths contain the same two elements,
4
+ * potentially swapped in their order?
5
+ * @param {[string[], string[]]} pathPairA A pair of paths like
6
+ * [["Disease", "Healthy"], ["Disease", "CKD"]]
7
+ * @param {[string[], string[]]} pathPairB A pair of paths like
8
+ * [["Disease", "CKD"], ["Disease", "Healthy"]]
9
+ * @returns {boolean} Whether the two pairs contain the same two paths.
10
+ */
11
+ export function isEqualPathPair(pathPairA: [string[], string[]], pathPairB: [string[], string[]]): boolean;
12
+ /**
13
+ * @param {AnnDataSource} dataSource
14
+ * @param {string} metadataPath
15
+ * @returns {Promise<any>}
16
+ */
17
+ export function loadComparisonMetadata(dataSource: AnnDataSource, metadataPath: string): Promise<any>;
18
+ import type AnnDataSource from '../AnnDataSource.js';
19
+ //# sourceMappingURL=comparative-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comparative-utils.d.ts","sourceRoot":"","sources":["../../src/anndata-loaders/comparative-utils.js"],"names":[],"mappings":"AAIA,uDAAuD;AAEvD;;;;;;;;GAQG;AACH,2CANW,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,aAEpB,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,GAElB,OAAO,CAOnB;AAED;;;;GAIG;AACH,mDAJW,aAAa,gBACb,MAAM,GACJ,OAAO,CAAC,GAAG,CAAC,CASxB;+BA9B8B,qBAAqB"}
@@ -0,0 +1,30 @@
1
+ /* eslint-disable no-underscore-dangle */
2
+ /* eslint-disable camelcase */
3
+ import { isEqual } from 'lodash-es';
4
+ /** @import AnnDataSource from '../AnnDataSource.js' */
5
+ /**
6
+ * Do two pairs of paths contain the same two elements,
7
+ * potentially swapped in their order?
8
+ * @param {[string[], string[]]} pathPairA A pair of paths like
9
+ * [["Disease", "Healthy"], ["Disease", "CKD"]]
10
+ * @param {[string[], string[]]} pathPairB A pair of paths like
11
+ * [["Disease", "CKD"], ["Disease", "Healthy"]]
12
+ * @returns {boolean} Whether the two pairs contain the same two paths.
13
+ */
14
+ export function isEqualPathPair(pathPairA, pathPairB) {
15
+ return ((isEqual(pathPairA[0], pathPairB[0]) && isEqual(pathPairA[1], pathPairB[1]))
16
+ || (isEqual(pathPairA[0], pathPairB[1]) && isEqual(pathPairA[1], pathPairB[0])));
17
+ }
18
+ /**
19
+ * @param {AnnDataSource} dataSource
20
+ * @param {string} metadataPath
21
+ * @returns {Promise<any>}
22
+ */
23
+ export async function loadComparisonMetadata(dataSource, metadataPath) {
24
+ // eslint-disable-next-line no-underscore-dangle
25
+ const metadata = JSON.parse(await dataSource._loadString(metadataPath));
26
+ if (!(metadata.schema_version === '0.0.1' || metadata.schema_version === '0.0.2')) {
27
+ throw new Error('Unsupported comparison_metadata schema version.');
28
+ }
29
+ return metadata;
30
+ }
@@ -10,4 +10,8 @@ export { default as FeatureLabelsAnndataLoader } from "./FeatureLabelsAnndataLoa
10
10
  export { default as ObsFeatureColumnsAnndataLoader } from "./ObsFeatureColumnsAnndataLoader.js";
11
11
  export { default as SampleEdgesAnndataLoader } from "./SampleEdgesAnndataLoader.js";
12
12
  export { default as SampleSetsAnndataLoader } from "./SampleSetsAnndataLoader.js";
13
+ export { default as ComparisonMetadataAnndataLoader } from "./ComparisonMetadataAnndataLoader.js";
14
+ export { default as FeatureStatsAnndataLoader } from "./FeatureStatsAnndataLoader.js";
15
+ export { default as FeatureSetStatsAnndataLoader } from "./FeatureSetStatsAnndataLoader.js";
16
+ export { default as ObsSetStatsAnndataLoader } from "./ObsSetStatsAnndataLoader.js";
13
17
  //# sourceMappingURL=index.d.ts.map
@@ -10,3 +10,7 @@ export { default as FeatureLabelsAnndataLoader } from './FeatureLabelsAnndataLoa
10
10
  export { default as ObsFeatureColumnsAnndataLoader } from './ObsFeatureColumnsAnndataLoader.js';
11
11
  export { default as SampleEdgesAnndataLoader } from './SampleEdgesAnndataLoader.js';
12
12
  export { default as SampleSetsAnndataLoader } from './SampleSetsAnndataLoader.js';
13
+ export { default as ComparisonMetadataAnndataLoader } from './ComparisonMetadataAnndataLoader.js';
14
+ export { default as FeatureStatsAnndataLoader } from './FeatureStatsAnndataLoader.js';
15
+ export { default as FeatureSetStatsAnndataLoader } from './FeatureSetStatsAnndataLoader.js';
16
+ export { default as ObsSetStatsAnndataLoader } from './ObsSetStatsAnndataLoader.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitessce/zarr",
3
- "version": "3.5.7",
3
+ "version": "3.5.8",
4
4
  "author": "HIDIVE Lab at HMS",
5
5
  "homepage": "http://vitessce.io",
6
6
  "repository": {
@@ -18,24 +18,21 @@
18
18
  "dependencies": {
19
19
  "d3-array": "^2.4.0",
20
20
  "lodash-es": "^4.17.21",
21
- "zarrita": "0.4.0-next.16",
21
+ "zarrita": "0.4.0",
22
22
  "apache-arrow": "^17.0.0",
23
23
  "parquet-wasm": "^0.6.1",
24
24
  "ol": "^10.2.1",
25
- "@vitessce/abstract": "3.5.7",
26
- "@vitessce/constants-internal": "3.5.7",
27
- "@vitessce/sets-utils": "3.5.7",
28
- "@vitessce/image-utils": "3.5.7",
29
- "@vitessce/utils": "3.5.7",
30
- "@vitessce/zarr-utils": "3.5.7",
31
- "@vitessce/config": "3.5.7",
32
- "@vitessce/globals": "3.5.7"
25
+ "@vitessce/abstract": "3.5.8",
26
+ "@vitessce/constants-internal": "3.5.8",
27
+ "@vitessce/sets-utils": "3.5.8",
28
+ "@vitessce/image-utils": "3.5.8",
29
+ "@vitessce/utils": "3.5.8",
30
+ "@vitessce/zarr-utils": "3.5.8",
31
+ "@vitessce/config": "3.5.8",
32
+ "@vitessce/globals": "3.5.8"
33
33
  },
34
34
  "devDependencies": {
35
- "@zarrita/core": "0.1.0-next.14",
36
- "@zarrita/storage": "0.1.0-next.6",
37
- "@zarrita/typedarray": "0.1.0-next.3",
38
- "@vitessce/types": "3.5.7"
35
+ "@vitessce/types": "3.5.8"
39
36
  },
40
37
  "scripts": {
41
38
  "bundle": "pnpm exec vite build -c ../../../scripts/vite.config.js",
@@ -5,8 +5,7 @@ import { log } from '@vitessce/globals';
5
5
  import { dirname } from './utils.js';
6
6
  import ZarrDataSource from './ZarrDataSource.js';
7
7
  /** @import { DataSourceParams } from '@vitessce/types' */
8
- /** @import { ByteStringArray } from '@zarrita/typedarray' */
9
- /** @import { TypedArray as ZarrTypedArray, Chunk } from '@zarrita/core' */
8
+ /** @import { TypedArray as ZarrTypedArray, Chunk, ByteStringArray } from 'zarrita' */
10
9
 
11
10
  /**
12
11
  * A base AnnData loader which has all shared methods for more comlpex laoders,
@@ -2,8 +2,7 @@
2
2
  import { zarrOpenRoot } from '@vitessce/zarr-utils';
3
3
  import { open as zarrOpen, root as zarrRoot } from 'zarrita';
4
4
 
5
- /** @import { Location as ZarrLocation } from '@zarrita/core' */
6
- /** @import { Readable } from '@zarrita/storage' */
5
+ /** @import { Location as ZarrLocation, Readable } from 'zarrita' */
7
6
  /** @import { DataSourceParams } from '@vitessce/types' */
8
7
 
9
8
  /**
@@ -0,0 +1,34 @@
1
+ // @ts-check
2
+ import { LoaderResult, AbstractTwoStepLoader, AbstractLoaderError } from '@vitessce/abstract';
3
+ import { loadComparisonMetadata } from './comparative-utils.js';
4
+
5
+ /** @import AnnDataSource from '../AnnDataSource.js' */
6
+ /** @import { ComparisonMetadata } from '@vitessce/types' */
7
+
8
+ /**
9
+ * Loader for string arrays located in anndata.zarr stores.
10
+ * @template {AnnDataSource} DataSourceType
11
+ * @extends {AbstractTwoStepLoader<DataSourceType>}
12
+ */
13
+ export default class ComparisonMetadataAnndataLoader extends AbstractTwoStepLoader {
14
+ /**
15
+ *
16
+ * @returns {Promise<LoaderResult<ComparisonMetadata>>}
17
+ */
18
+ async load() {
19
+ const { path } = this.options;
20
+ const superResult = await super.load().catch(reason => Promise.resolve(reason));
21
+ if (superResult instanceof AbstractLoaderError) {
22
+ return Promise.reject(superResult);
23
+ }
24
+ const metadata = await loadComparisonMetadata(this.dataSource, path);
25
+ return Promise.resolve(new LoaderResult(
26
+ {
27
+ // Should a more complex class be wrapping this
28
+ // JSON object to help with downstream querying?
29
+ comparisonMetadata: metadata,
30
+ },
31
+ null,
32
+ ));
33
+ }
34
+ }
@@ -0,0 +1,164 @@
1
+ /* eslint-disable no-underscore-dangle */
2
+ /* eslint-disable camelcase */
3
+ import { LoaderResult, AbstractTwoStepLoader } from '@vitessce/abstract';
4
+ import { isEqual } from 'lodash-es';
5
+ import { isEqualPathPair, loadComparisonMetadata } from './comparative-utils.js';
6
+
7
+ /** @import AnnDataSource from '../AnnDataSource.js' */
8
+ /** @import { FeatureStatsData } from '@vitessce/types' */
9
+
10
+
11
+ /**
12
+ * Loader for string arrays located in anndata.zarr stores.
13
+ * @template {AnnDataSource} DataSourceType
14
+ * @extends {AbstractTwoStepLoader<DataSourceType>}
15
+ */
16
+ export default class FeatureStatsAnndataLoader extends AbstractTwoStepLoader {
17
+ /**
18
+ * Class method for loading feature string labels.
19
+ * @returns {Promise<any>} A promise for the array.
20
+ */
21
+ async loadSignificances(dfPath) {
22
+ const { pValueColumn } = this.options;
23
+ // Check the options to determine whether the significance values are pre-transformed
24
+ // or if we still need to compute minus log10 here.
25
+ const values = await this.dataSource.loadNumeric(`${dfPath}/${pValueColumn}`);
26
+ return values.data;
27
+ }
28
+
29
+ async loadFeatureSetNames(dfPath) {
30
+ const { indexColumn } = this.options;
31
+ if (indexColumn) {
32
+ return this.dataSource._loadColumn(`${dfPath}/${indexColumn}`);
33
+ }
34
+ // Use the default dataframe index column in this case.
35
+ return this.dataSource.loadDataFrameIndex(dfPath);
36
+ }
37
+
38
+ async loadFeatureSetTerms(dfPath) {
39
+ const { termColumn } = this.options;
40
+ return this.dataSource._loadColumn(`${dfPath}/${termColumn}`);
41
+ }
42
+
43
+ async loadDataFrame(dfPath) {
44
+ const [
45
+ featureSetName,
46
+ featureSetTerm,
47
+ featureSetSignificance,
48
+ ] = await Promise.all([
49
+ this.loadFeatureSetNames(dfPath),
50
+ this.loadFeatureSetTerms(dfPath),
51
+ this.loadSignificances(dfPath),
52
+ ]);
53
+ return {
54
+ featureSetName,
55
+ featureSetTerm,
56
+ featureSetSignificance,
57
+ };
58
+ }
59
+
60
+ /**
61
+ *
62
+ * @returns {Promise<StatsMeta[]>}
63
+ */
64
+ async loadMetadata() {
65
+ const { metadataPath } = this.options;
66
+ if (this.metadata) {
67
+ return this.metadata;
68
+ }
69
+ if (!this.metadata) {
70
+ this.metadata = await loadComparisonMetadata(this.dataSource, metadataPath);
71
+ return this.metadata;
72
+ }
73
+ return this.metadata;
74
+ }
75
+
76
+
77
+ /**
78
+ * Load data from multiple dataframes, merged.
79
+ * @param {object} volcanoOptions
80
+ * @param {string[]|null} [volcanoOptions.sampleFacet]
81
+ * @param {string[]|null} [volcanoOptions.obsSetFacet]
82
+ * @param {number|null} [volcanoOptions.topK]
83
+ * @param {string[][]|null} [volcanoOptions.sampleSetSelection]
84
+ * @returns {Promise<LoaderResult<FeatureStatsData>>}
85
+ */
86
+ async loadMulti(volcanoOptions) {
87
+ const { analysisType: targetAnalysisType = 'pertpy_hypergeometric' } = this.options;
88
+ const { sampleSetSelection, obsSetSelection } = volcanoOptions || {};
89
+
90
+ // TODO: should this also depend on a "featureSetType" such as "pathway"
91
+ // or an ontology id/name such as "GO" vs. "CHEMBL"?
92
+
93
+ // We expect these set paths to have already been transformed
94
+ // to use the "raw" column names,
95
+ // according to the mappings defined in obsSets and sampleSets loader options.
96
+ // The values in the comparison_metadata have the "raw" column names.
97
+ const rawObsSetSelection = obsSetSelection;
98
+ const rawSampleSetSelection = sampleSetSelection;
99
+
100
+ if (sampleSetSelection) {
101
+ if (sampleSetSelection.length !== 2) {
102
+ return Promise.reject(new Error('Expected exactly two sample sets for volcano plot.'));
103
+ }
104
+ }
105
+
106
+ if (!obsSetSelection) {
107
+ return Promise.reject(new Error('Expected obsSetSelection to be present.'));
108
+ }
109
+
110
+ const metadata = await this.loadMetadata();
111
+
112
+ // Match metadata against to get paths to dataframe(s) of interest.
113
+ const matchingComparisons = [];
114
+ Object.values(metadata.comparisons).forEach((comparisonGroupObject) => {
115
+ const { results } = comparisonGroupObject;
116
+ results.forEach((resultObject) => {
117
+ const {
118
+ analysis_type,
119
+ // analysis_params,
120
+ coordination_values,
121
+ // path,
122
+ } = resultObject;
123
+ if (analysis_type === targetAnalysisType) {
124
+ // This is a diff. exp. result.
125
+ if (sampleSetSelection) {
126
+ // Comparing two sample groups.
127
+ rawObsSetSelection.forEach((obsSetPath) => {
128
+ if (isEqual([obsSetPath], coordination_values.obsSetFilter)) {
129
+ // The obsSetSelection matches.
130
+ // Now check whether the sampleSetSelection matches.
131
+ if (isEqualPathPair(rawSampleSetSelection, coordination_values.sampleSetFilter)) {
132
+ matchingComparisons.push(resultObject);
133
+ }
134
+ }
135
+ });
136
+ } else if (obsSetSelection) {
137
+ // Comparing no sample groups but have selected cell type(s) of interest.
138
+ rawObsSetSelection.forEach((obsSetPath) => {
139
+ if (isEqual([obsSetPath], coordination_values.obsSetSelection)) {
140
+ matchingComparisons.push(resultObject);
141
+ }
142
+ });
143
+ }
144
+ }
145
+ });
146
+ });
147
+
148
+ // Using this matchingComparisons list,
149
+ // load the relevant columns of each matching dataframe and concatenate them together.
150
+ const result = await Promise.all(matchingComparisons.map(async (comparisonObject) => {
151
+ const df = await this.loadDataFrame(comparisonObject.path);
152
+ return {
153
+ df,
154
+ metadata: comparisonObject,
155
+ };
156
+ }));
157
+ return new LoaderResult({ featureSetStats: result }, null);
158
+ }
159
+
160
+ // eslint-disable-next-line class-methods-use-this
161
+ async load() {
162
+ throw new Error('The load() method is not implemented for FeatureSetStatsAnndataLoader.');
163
+ }
164
+ }