@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,177 @@
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, pValueTransformation } = 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
+ if (pValueTransformation === 'minuslog10') {
27
+ // Invert the transformation, to return the plain p-values.
28
+ // The view will do the -Math.log10 transformation if needed.
29
+ values.data = values.data.map(val => (10 ** -val));
30
+ }
31
+ return values.data;
32
+ }
33
+
34
+ /**
35
+ * Class method for loading feature string labels.
36
+ * @returns {Promise<any>} A promise for the array.
37
+ */
38
+ async loadFoldChanges(dfPath) {
39
+ const { foldChangeColumn, foldChangeTransformation } = this.options;
40
+ // Check the options to determine whether the significance values are pre-transformed
41
+ // or if we still need to compute log2 here.
42
+ const values = await this.dataSource.loadNumeric(`${dfPath}/${foldChangeColumn}`);
43
+ // Invert the transformation
44
+ if (foldChangeTransformation === 'log2') {
45
+ values.data = values.data.map(val => (2 ** val));
46
+ }
47
+ return values.data;
48
+ }
49
+
50
+ async loadFeatureNames(dfPath) {
51
+ const { indexColumn } = this.options;
52
+ if (indexColumn) {
53
+ return this.dataSource._loadColumn(`${dfPath}/${indexColumn}`);
54
+ }
55
+ // Use the default dataframe index column in this case.
56
+ return this.dataSource.loadDataFrameIndex(dfPath);
57
+ }
58
+
59
+ async loadDataFrame(dfPath) {
60
+ const [
61
+ featureId,
62
+ featureFoldChange,
63
+ featureSignificance,
64
+ ] = await Promise.all([
65
+ this.loadFeatureNames(dfPath),
66
+ this.loadFoldChanges(dfPath),
67
+ this.loadSignificances(dfPath),
68
+ ]);
69
+ return {
70
+ featureId,
71
+ featureFoldChange,
72
+ featureSignificance,
73
+ };
74
+ }
75
+
76
+ /**
77
+ *
78
+ * @returns {Promise<StatsMeta[]>}
79
+ */
80
+ async loadMetadata() {
81
+ const { metadataPath } = this.options;
82
+ if (this.metadata) {
83
+ return this.metadata;
84
+ }
85
+ if (!this.metadata) {
86
+ this.metadata = await loadComparisonMetadata(this.dataSource, metadataPath);
87
+ return this.metadata;
88
+ }
89
+ return this.metadata;
90
+ }
91
+
92
+
93
+ /**
94
+ * Load data from multiple dataframes, merged.
95
+ * @param {object} volcanoOptions
96
+ * @param {string[]|null} [volcanoOptions.sampleFacet]
97
+ * @param {string[]|null} [volcanoOptions.obsSetFacet]
98
+ * @param {number|null} [volcanoOptions.topK]
99
+ * @param {string[][]|null} [volcanoOptions.sampleSetSelection]
100
+ * @returns {Promise<LoaderResult<FeatureStatsData>>}
101
+ */
102
+ async loadMulti(volcanoOptions) {
103
+ const { analysisType: targetAnalysisType = 'rank_genes_groups' } = this.options;
104
+ const { sampleSetSelection, obsSetSelection } = volcanoOptions || {};
105
+
106
+ // We expect these set paths to have already been transformed
107
+ // to use the "raw" column names,
108
+ // according to the mappings defined in obsSets and sampleSets loader options.
109
+ // The values in the comparison_metadata have the "raw" column names.
110
+ const rawObsSetSelection = obsSetSelection;
111
+ const rawSampleSetSelection = sampleSetSelection;
112
+
113
+ if (sampleSetSelection) {
114
+ if (sampleSetSelection.length !== 2) {
115
+ return Promise.reject(new Error('Expected exactly two sample sets for volcano plot.'));
116
+ }
117
+ }
118
+
119
+ if (!obsSetSelection) {
120
+ return Promise.reject(new Error('Expected obsSetSelection to be present.'));
121
+ }
122
+
123
+ const metadata = await this.loadMetadata();
124
+
125
+ // Match metadata against to get paths to dataframe(s) of interest.
126
+ const matchingComparisons = [];
127
+ Object.values(metadata.comparisons).forEach((comparisonGroupObject) => {
128
+ const { results } = comparisonGroupObject;
129
+ results.forEach((resultObject) => {
130
+ const {
131
+ analysis_type,
132
+ // analysis_params,
133
+ coordination_values,
134
+ // path,
135
+ } = resultObject;
136
+ if (analysis_type === targetAnalysisType) {
137
+ // This is a diff. exp. result.
138
+ if (sampleSetSelection) {
139
+ // Comparing two sample groups.
140
+ rawObsSetSelection.forEach((obsSetPath) => {
141
+ if (isEqual([obsSetPath], coordination_values.obsSetFilter)) {
142
+ // The obsSetSelection matches.
143
+ // Now check whether the sampleSetSelection matches.
144
+ if (isEqualPathPair(rawSampleSetSelection, coordination_values.sampleSetFilter)) {
145
+ matchingComparisons.push(resultObject);
146
+ }
147
+ }
148
+ });
149
+ } else if (obsSetSelection) {
150
+ // Comparing no sample groups but have selected cell type(s) of interest.
151
+ rawObsSetSelection.forEach((obsSetPath) => {
152
+ if (isEqual([obsSetPath], coordination_values.obsSetSelection)) {
153
+ matchingComparisons.push(resultObject);
154
+ }
155
+ });
156
+ }
157
+ }
158
+ });
159
+ });
160
+
161
+ // Using this matchingComparisons list,
162
+ // load the relevant columns of each matching dataframe and concatenate them together.
163
+ const result = await Promise.all(matchingComparisons.map(async (comparisonObject) => {
164
+ const df = await this.loadDataFrame(comparisonObject.path);
165
+ return {
166
+ df,
167
+ metadata: comparisonObject,
168
+ };
169
+ }));
170
+ return new LoaderResult({ featureStats: result }, null);
171
+ }
172
+
173
+ // eslint-disable-next-line class-methods-use-this
174
+ async load() {
175
+ throw new Error('The load() method is not implemented for FeatureStatsAnndataLoader.');
176
+ }
177
+ }
@@ -0,0 +1,211 @@
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 { ObsSetStatsData } 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 ObsSetStatsAnndataLoader extends AbstractTwoStepLoader {
17
+ /**
18
+ * Class method for loading feature string labels.
19
+ * @returns {Promise<any>} A promise for the array.
20
+ */
21
+ async loadInterceptValues(dfPath) {
22
+ const { interceptExpectedSampleColumn } = 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}/${interceptExpectedSampleColumn}`);
26
+ return values.data;
27
+ }
28
+
29
+ /**
30
+ * Class method for loading feature string labels.
31
+ * @returns {Promise<any>} A promise for the array.
32
+ */
33
+ async loadEffectValues(dfPath) {
34
+ const { effectExpectedSampleColumn } = this.options;
35
+ // Check the options to determine whether the significance values are pre-transformed
36
+ // or if we still need to compute minus log10 here.
37
+ const values = await this.dataSource.loadNumeric(`${dfPath}/${effectExpectedSampleColumn}`);
38
+ return values.data;
39
+ }
40
+
41
+ /**
42
+ * Class method for loading feature string labels.
43
+ * @returns {Promise<any>} A promise for the array.
44
+ */
45
+ async loadIsCredible(dfPath) {
46
+ const { isCredibleEffectColumn } = this.options;
47
+ // Check the options to determine whether the significance values are pre-transformed
48
+ // or if we still need to compute minus log10 here.
49
+ const values = await this.dataSource.loadNumeric(`${dfPath}/${isCredibleEffectColumn}`);
50
+ return Array.from(values.data);
51
+ }
52
+
53
+ /**
54
+ * Class method for loading feature string labels.
55
+ * @returns {Promise<any>} A promise for the array.
56
+ */
57
+ async loadFoldChanges(dfPath) {
58
+ const { foldChangeColumn, foldChangeTransformation } = this.options;
59
+ // Check the options to determine whether the significance values are pre-transformed
60
+ // or if we still need to compute log2 here.
61
+ const values = await this.dataSource.loadNumeric(`${dfPath}/${foldChangeColumn}`);
62
+ // Invert the transformation
63
+ if (foldChangeTransformation === 'log2') {
64
+ values.data = values.data.map(val => (2 ** val));
65
+ }
66
+ return values.data;
67
+ }
68
+
69
+ async loadCovariate(dfPath) {
70
+ const { covariateColumn } = this.options;
71
+ return this.dataSource._loadColumn(`${dfPath}/${covariateColumn}`);
72
+ }
73
+
74
+ async loadObsSetNames(dfPath) {
75
+ const { indexColumn } = this.options;
76
+ if (indexColumn) {
77
+ return this.dataSource._loadColumn(`${dfPath}/${indexColumn}`);
78
+ }
79
+ // Use the default dataframe index column in this case.
80
+ return this.dataSource.loadDataFrameIndex(dfPath);
81
+ }
82
+
83
+ async loadDataFrame(dfPath) {
84
+ const [
85
+ obsSetId,
86
+ obsSetFoldChange,
87
+ interceptExpectedSample,
88
+ effectExpectedSample,
89
+ isCredibleEffect,
90
+ // TODO: rather than passing this down,
91
+ // do the fold change direction swapping in the loader
92
+ // (as opposed to in the view).
93
+ // TODO: also, see https://github.com/keller-mark/compasce/issues/30
94
+ // which would allow not loading this column altogether.
95
+ covariate,
96
+ ] = await Promise.all([
97
+ this.loadObsSetNames(dfPath),
98
+ this.loadFoldChanges(dfPath),
99
+ this.loadInterceptValues(dfPath),
100
+ this.loadEffectValues(dfPath),
101
+ this.loadIsCredible(dfPath),
102
+ this.loadCovariate(dfPath),
103
+ ]);
104
+ return {
105
+ obsSetId,
106
+ obsSetFoldChange,
107
+ interceptExpectedSample,
108
+ effectExpectedSample,
109
+ isCredibleEffect,
110
+ covariate,
111
+ };
112
+ }
113
+
114
+ /**
115
+ *
116
+ * @returns {Promise<StatsMeta[]>}
117
+ */
118
+ async loadMetadata() {
119
+ const { metadataPath } = this.options;
120
+ if (this.metadata) {
121
+ return this.metadata;
122
+ }
123
+ if (!this.metadata) {
124
+ this.metadata = await loadComparisonMetadata(this.dataSource, metadataPath);
125
+ return this.metadata;
126
+ }
127
+ return this.metadata;
128
+ }
129
+
130
+
131
+ /**
132
+ * Load data from multiple dataframes, merged.
133
+ * @param {object} volcanoOptions
134
+ * @param {string[]|null} [volcanoOptions.sampleFacet]
135
+ * @param {string[]|null} [volcanoOptions.obsSetFacet]
136
+ * @param {number|null} [volcanoOptions.topK]
137
+ * @param {string[][]|null} [volcanoOptions.sampleSetSelection]
138
+ * @returns {Promise<LoaderResult<ObsSetStatsData>>}
139
+ */
140
+ async loadMulti(volcanoOptions) {
141
+ const { analysisType: targetAnalysisType = 'sccoda_df' } = this.options;
142
+ const { sampleSetSelection, obsSetSelection } = volcanoOptions || {};
143
+
144
+ // We expect these set paths to have already been transformed
145
+ // to use the "raw" column names,
146
+ // according to the mappings defined in obsSets and sampleSets loader options.
147
+ // The values in the comparison_metadata have the "raw" column names.
148
+ const rawObsSetSelection = obsSetSelection;
149
+ const rawSampleSetSelection = sampleSetSelection;
150
+
151
+ if (!sampleSetSelection || sampleSetSelection?.length !== 2) {
152
+ return Promise.reject(new Error('Expected exactly two sample sets for cell type composition analysis plot.'));
153
+ }
154
+
155
+ if (!obsSetSelection) {
156
+ return Promise.reject(new Error('Expected obsSetSelection to be present.'));
157
+ }
158
+
159
+ const metadata = await this.loadMetadata();
160
+ // For cell type composition analysis,
161
+ // results have `obsSetSelection: [['cell_type']]`
162
+ // to indicate that the analysis was performed using this obsSet grouping.
163
+ // Here, we obtain the unique obsSet groupings from the obsSetSelection paths.
164
+ const rawObsSetGroups = Array.from(
165
+ new Set(rawObsSetSelection.map(setPath => setPath?.[0])),
166
+ );
167
+
168
+ // Match metadata against to get paths to dataframe(s) of interest.
169
+ const matchingComparisons = [];
170
+ Object.values(metadata.comparisons).forEach((comparisonGroupObject) => {
171
+ const { results } = comparisonGroupObject;
172
+ results.forEach((resultObject) => {
173
+ const {
174
+ analysis_type,
175
+ // analysis_params,
176
+ coordination_values,
177
+ // path,
178
+ } = resultObject;
179
+ if (analysis_type === targetAnalysisType) {
180
+ // This is a diff. exp. result.
181
+ if (sampleSetSelection) {
182
+ // Comparing two sample groups.
183
+ if (isEqual([rawObsSetGroups], coordination_values.obsSetSelection)) {
184
+ // The obsSetSelection matches.
185
+ // Now check whether the sampleSetSelection matches.
186
+ if (isEqualPathPair(rawSampleSetSelection, coordination_values.sampleSetFilter)) {
187
+ matchingComparisons.push(resultObject);
188
+ }
189
+ }
190
+ }
191
+ }
192
+ });
193
+ });
194
+
195
+ // Using this matchingComparisons list,
196
+ // load the relevant columns of each matching dataframe and concatenate them together.
197
+ const result = await Promise.all(matchingComparisons.map(async (comparisonObject) => {
198
+ const df = await this.loadDataFrame(comparisonObject.path);
199
+ return {
200
+ df,
201
+ metadata: comparisonObject,
202
+ };
203
+ }));
204
+ return new LoaderResult({ obsSetStats: result }, null);
205
+ }
206
+
207
+ // eslint-disable-next-line class-methods-use-this
208
+ async load() {
209
+ throw new Error('The load() method is not implemented for ObsSetStatsAnndataLoader.');
210
+ }
211
+ }
@@ -0,0 +1,35 @@
1
+ /* eslint-disable no-underscore-dangle */
2
+ /* eslint-disable camelcase */
3
+ import { isEqual } from 'lodash-es';
4
+
5
+ /** @import AnnDataSource from '../AnnDataSource.js' */
6
+
7
+ /**
8
+ * Do two pairs of paths contain the same two elements,
9
+ * potentially swapped in their order?
10
+ * @param {[string[], string[]]} pathPairA A pair of paths like
11
+ * [["Disease", "Healthy"], ["Disease", "CKD"]]
12
+ * @param {[string[], string[]]} pathPairB A pair of paths like
13
+ * [["Disease", "CKD"], ["Disease", "Healthy"]]
14
+ * @returns {boolean} Whether the two pairs contain the same two paths.
15
+ */
16
+ export function isEqualPathPair(pathPairA, pathPairB) {
17
+ return (
18
+ (isEqual(pathPairA[0], pathPairB[0]) && isEqual(pathPairA[1], pathPairB[1]))
19
+ || (isEqual(pathPairA[0], pathPairB[1]) && isEqual(pathPairA[1], pathPairB[0]))
20
+ );
21
+ }
22
+
23
+ /**
24
+ * @param {AnnDataSource} dataSource
25
+ * @param {string} metadataPath
26
+ * @returns {Promise<any>}
27
+ */
28
+ export async function loadComparisonMetadata(dataSource, metadataPath) {
29
+ // eslint-disable-next-line no-underscore-dangle
30
+ const metadata = JSON.parse(await dataSource._loadString(metadataPath));
31
+ if (!(metadata.schema_version === '0.0.1' || metadata.schema_version === '0.0.2')) {
32
+ throw new Error('Unsupported comparison_metadata schema version.');
33
+ }
34
+ return metadata;
35
+ }
@@ -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';