@vitessce/zarr 3.5.6 → 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.
- package/dist/index.js +1056 -171
- package/dist/zstd-561fda0e.js +778 -0
- package/dist-tsc/AnnDataSource.d.ts +10 -4
- package/dist-tsc/AnnDataSource.d.ts.map +1 -1
- package/dist-tsc/AnnDataSource.js +16 -3
- package/dist-tsc/ZarrDataSource.d.ts +3 -4
- package/dist-tsc/ZarrDataSource.d.ts.map +1 -1
- package/dist-tsc/ZarrDataSource.js +1 -2
- package/dist-tsc/anndata-loaders/ComparisonMetadataAnndataLoader.d.ts +20 -0
- package/dist-tsc/anndata-loaders/ComparisonMetadataAnndataLoader.d.ts.map +1 -0
- package/dist-tsc/anndata-loaders/ComparisonMetadataAnndataLoader.js +29 -0
- package/dist-tsc/anndata-loaders/FeatureSetStatsAnndataLoader.d.ts +49 -0
- package/dist-tsc/anndata-loaders/FeatureSetStatsAnndataLoader.d.ts.map +1 -0
- package/dist-tsc/anndata-loaders/FeatureSetStatsAnndataLoader.js +143 -0
- package/dist-tsc/anndata-loaders/FeatureStatsAnndataLoader.d.ts +53 -0
- package/dist-tsc/anndata-loaders/FeatureStatsAnndataLoader.d.ts.map +1 -0
- package/dist-tsc/anndata-loaders/FeatureStatsAnndataLoader.js +157 -0
- package/dist-tsc/anndata-loaders/ObsSetStatsAnndataLoader.d.ts +66 -0
- package/dist-tsc/anndata-loaders/ObsSetStatsAnndataLoader.d.ts.map +1 -0
- package/dist-tsc/anndata-loaders/ObsSetStatsAnndataLoader.js +183 -0
- package/dist-tsc/anndata-loaders/SampleSetsAnndataLoader.d.ts +18 -0
- package/dist-tsc/anndata-loaders/SampleSetsAnndataLoader.d.ts.map +1 -0
- package/dist-tsc/anndata-loaders/SampleSetsAnndataLoader.js +75 -0
- package/dist-tsc/anndata-loaders/comparative-utils.d.ts +19 -0
- package/dist-tsc/anndata-loaders/comparative-utils.d.ts.map +1 -0
- package/dist-tsc/anndata-loaders/comparative-utils.js +30 -0
- package/dist-tsc/anndata-loaders/index.d.ts +5 -0
- package/dist-tsc/anndata-loaders/index.js +5 -0
- package/dist-tsc/utils.js +2 -1
- package/package.json +11 -13
- package/src/AnnDataSource.js +18 -4
- package/src/ZarrDataSource.js +1 -2
- package/src/anndata-loaders/ComparisonMetadataAnndataLoader.js +34 -0
- package/src/anndata-loaders/FeatureSetStatsAnndataLoader.js +164 -0
- package/src/anndata-loaders/FeatureStatsAnndataLoader.js +177 -0
- package/src/anndata-loaders/ObsSetStatsAnndataLoader.js +211 -0
- package/src/anndata-loaders/SampleSetsAnndataLoader.js +88 -0
- package/src/anndata-loaders/comparative-utils.js +35 -0
- package/src/anndata-loaders/index.js +5 -0
- package/src/utils.js +2 -2
- 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,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loader for converting zarr into the cell sets json schema.
|
|
3
|
+
*/
|
|
4
|
+
export default class SampleSetsAnndataLoader extends AbstractTwoStepLoader<any> {
|
|
5
|
+
constructor(dataSource: any, params: import("@vitessce/types").LoaderParams);
|
|
6
|
+
loadObsIndices(): Promise<any[]>;
|
|
7
|
+
loadCellSetIds(): any;
|
|
8
|
+
loadCellSetScores(): any;
|
|
9
|
+
load(): Promise<LoaderResult<{
|
|
10
|
+
sampleIndex: any;
|
|
11
|
+
sampleSets: any;
|
|
12
|
+
sampleSetsMembership: Map<any, any>;
|
|
13
|
+
}>>;
|
|
14
|
+
cachedResult: Promise<any[]> | undefined;
|
|
15
|
+
}
|
|
16
|
+
import { AbstractTwoStepLoader } from '@vitessce/abstract';
|
|
17
|
+
import { LoaderResult } from '@vitessce/abstract';
|
|
18
|
+
//# sourceMappingURL=SampleSetsAnndataLoader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SampleSetsAnndataLoader.d.ts","sourceRoot":"","sources":["../../src/anndata-loaders/SampleSetsAnndataLoader.js"],"names":[],"mappings":"AAUA;;GAEG;AACH;;IACE,iCAkBC;IAED,sBAIC;IAED,yBAKC;IAED;;;;QAuCC;IAhCG,yCAQG;CAyBR;sCArFM,oBAAoB;6BAApB,oBAAoB"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { LoaderResult, AbstractTwoStepLoader, AbstractLoaderError, } from '@vitessce/abstract';
|
|
2
|
+
import { initializeCellSetColor, treeToMembershipMap, dataToCellSetsTree, } from '@vitessce/sets-utils';
|
|
3
|
+
/**
|
|
4
|
+
* Loader for converting zarr into the cell sets json schema.
|
|
5
|
+
*/
|
|
6
|
+
export default class SampleSetsAnndataLoader extends AbstractTwoStepLoader {
|
|
7
|
+
loadObsIndices() {
|
|
8
|
+
const { options } = this;
|
|
9
|
+
const obsIndexPromises = options
|
|
10
|
+
.sampleSets
|
|
11
|
+
?.map(({ path }) => path)
|
|
12
|
+
.map((pathOrPaths) => {
|
|
13
|
+
if (Array.isArray(pathOrPaths)) {
|
|
14
|
+
// The multi-level case, try using the first item to get the obsIndex.
|
|
15
|
+
if (pathOrPaths.length > 0) {
|
|
16
|
+
return this.dataSource.loadDataFrameIndex(pathOrPaths[0]);
|
|
17
|
+
}
|
|
18
|
+
// pathOrPaths should not be of length 0, but if so, fall back to the default obsIndex.
|
|
19
|
+
return this.dataSource.loadDataFrameIndex();
|
|
20
|
+
}
|
|
21
|
+
// The single-level case.
|
|
22
|
+
return this.dataSource.loadDataFrameIndex(pathOrPaths);
|
|
23
|
+
});
|
|
24
|
+
return Promise.all(obsIndexPromises);
|
|
25
|
+
}
|
|
26
|
+
loadCellSetIds() {
|
|
27
|
+
const { options } = this;
|
|
28
|
+
const cellSetZarrLocation = options.sampleSets?.map(({ path }) => path);
|
|
29
|
+
return this.dataSource.loadObsColumns(cellSetZarrLocation);
|
|
30
|
+
}
|
|
31
|
+
loadCellSetScores() {
|
|
32
|
+
const { options } = this;
|
|
33
|
+
const cellSetScoreZarrLocation = options.sampleSets
|
|
34
|
+
?.map(option => option.scorePath || undefined);
|
|
35
|
+
return this.dataSource.loadObsColumns(cellSetScoreZarrLocation);
|
|
36
|
+
}
|
|
37
|
+
async load() {
|
|
38
|
+
const superResult = await super.load().catch(reason => Promise.resolve(reason));
|
|
39
|
+
if (superResult instanceof AbstractLoaderError) {
|
|
40
|
+
return Promise.reject(superResult);
|
|
41
|
+
}
|
|
42
|
+
if (!this.cachedResult) {
|
|
43
|
+
const { options } = this;
|
|
44
|
+
this.cachedResult = Promise.all([
|
|
45
|
+
this.dataSource.loadDataFrameIndex(),
|
|
46
|
+
this.loadObsIndices(),
|
|
47
|
+
this.loadCellSetIds(),
|
|
48
|
+
this.loadCellSetScores(),
|
|
49
|
+
]).then(data => ([
|
|
50
|
+
data[0],
|
|
51
|
+
dataToCellSetsTree([data[1], data[2], data[3]], options.sampleSets),
|
|
52
|
+
]));
|
|
53
|
+
}
|
|
54
|
+
const [obsIndex, obsSets] = await this.cachedResult;
|
|
55
|
+
const obsSetsMembership = treeToMembershipMap(obsSets);
|
|
56
|
+
const coordinationValues = {};
|
|
57
|
+
const { tree } = obsSets;
|
|
58
|
+
const newAutoSetSelectionParentName = tree[0].name;
|
|
59
|
+
// Create a list of set paths to initally select.
|
|
60
|
+
// eslint-disable-next-line no-unused-vars
|
|
61
|
+
const newAutoSetSelections = tree[0].children.map(node => [
|
|
62
|
+
newAutoSetSelectionParentName,
|
|
63
|
+
node.name,
|
|
64
|
+
]);
|
|
65
|
+
// Create a list of cell set objects with color mappings.
|
|
66
|
+
const newAutoSetColors = initializeCellSetColor(obsSets, []);
|
|
67
|
+
// coordinationValues.sampleSetSelection = newAutoSetSelections;
|
|
68
|
+
coordinationValues.sampleSetColor = newAutoSetColors;
|
|
69
|
+
return Promise.resolve(new LoaderResult({
|
|
70
|
+
sampleIndex: obsIndex,
|
|
71
|
+
sampleSets: obsSets,
|
|
72
|
+
sampleSetsMembership: obsSetsMembership,
|
|
73
|
+
}, null, coordinationValues));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -9,4 +9,9 @@ export { default as ObsLabelsAnndataLoader } from "./ObsLabelsAnndataLoader.js";
|
|
|
9
9
|
export { default as FeatureLabelsAnndataLoader } from "./FeatureLabelsAnndataLoader.js";
|
|
10
10
|
export { default as ObsFeatureColumnsAnndataLoader } from "./ObsFeatureColumnsAnndataLoader.js";
|
|
11
11
|
export { default as SampleEdgesAnndataLoader } from "./SampleEdgesAnndataLoader.js";
|
|
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";
|
|
12
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -9,3 +9,8 @@ export { default as ObsLabelsAnndataLoader } from './ObsLabelsAnndataLoader.js';
|
|
|
9
9
|
export { default as FeatureLabelsAnndataLoader } from './FeatureLabelsAnndataLoader.js';
|
|
10
10
|
export { default as ObsFeatureColumnsAnndataLoader } from './ObsFeatureColumnsAnndataLoader.js';
|
|
11
11
|
export { default as SampleEdgesAnndataLoader } from './SampleEdgesAnndataLoader.js';
|
|
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/dist-tsc/utils.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
+
import { log } from '@vitessce/globals';
|
|
2
3
|
/**
|
|
3
4
|
* Returns the directory part of a path,
|
|
4
5
|
* (before the last '/' character).
|
|
@@ -20,7 +21,7 @@ export function basename(path) {
|
|
|
20
21
|
const arr = path.split('/');
|
|
21
22
|
const result = arr.at(-1);
|
|
22
23
|
if (!result) {
|
|
23
|
-
|
|
24
|
+
log.error('basename of path is empty', path);
|
|
24
25
|
return '';
|
|
25
26
|
}
|
|
26
27
|
return result;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitessce/zarr",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.8",
|
|
4
4
|
"author": "HIDIVE Lab at HMS",
|
|
5
5
|
"homepage": "http://vitessce.io",
|
|
6
6
|
"repository": {
|
|
@@ -18,23 +18,21 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"d3-array": "^2.4.0",
|
|
20
20
|
"lodash-es": "^4.17.21",
|
|
21
|
-
"zarrita": "0.4.0
|
|
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.
|
|
26
|
-
"@vitessce/constants-internal": "3.5.
|
|
27
|
-
"@vitessce/sets-utils": "3.5.
|
|
28
|
-
"@vitessce/image-utils": "3.5.
|
|
29
|
-
"@vitessce/utils": "3.5.
|
|
30
|
-
"@vitessce/zarr-utils": "3.5.
|
|
31
|
-
"@vitessce/config": "3.5.
|
|
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"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"@
|
|
35
|
-
"@zarrita/storage": "0.1.0-next.6",
|
|
36
|
-
"@zarrita/typedarray": "0.1.0-next.3",
|
|
37
|
-
"@vitessce/types": "3.5.6"
|
|
35
|
+
"@vitessce/types": "3.5.8"
|
|
38
36
|
},
|
|
39
37
|
"scripts": {
|
|
40
38
|
"bundle": "pnpm exec vite build -c ../../../scripts/vite.config.js",
|
package/src/AnnDataSource.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
/* eslint-disable no-underscore-dangle */
|
|
3
3
|
import { open as zarrOpen, get as zarrGet } from 'zarrita';
|
|
4
|
+
import { log } from '@vitessce/globals';
|
|
4
5
|
import { dirname } from './utils.js';
|
|
5
6
|
import ZarrDataSource from './ZarrDataSource.js';
|
|
6
|
-
|
|
7
7
|
/** @import { DataSourceParams } from '@vitessce/types' */
|
|
8
|
-
/** @import { ByteStringArray } from '
|
|
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,
|
|
@@ -207,6 +206,21 @@ export default class AnnDataSource extends ZarrDataSource {
|
|
|
207
206
|
return this.obsIndex;
|
|
208
207
|
}
|
|
209
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Class method for loading the obs index.
|
|
211
|
+
* @param {string|undefined} path Used by subclasses.
|
|
212
|
+
* @returns {Promise<string[]>} An promise for a zarr array
|
|
213
|
+
* containing the indices.
|
|
214
|
+
*/
|
|
215
|
+
loadDataFrameIndex(
|
|
216
|
+
// eslint-disable-next-line no-unused-vars
|
|
217
|
+
path = undefined,
|
|
218
|
+
) {
|
|
219
|
+
const dfPath = path ? dirname(path) : '';
|
|
220
|
+
return this.getJson(`${dfPath}/.zattrs`)
|
|
221
|
+
.then(({ _index }) => this.getFlatArrDecompressed(`${dfPath.length > 0 ? '/' : ''}${dfPath}/${_index}`));
|
|
222
|
+
}
|
|
223
|
+
|
|
210
224
|
/**
|
|
211
225
|
* Class method for loading the var index.
|
|
212
226
|
* @param {string|undefined} path Used by subclasses.
|
|
@@ -340,7 +354,7 @@ export default class AnnDataSource extends ZarrDataSource {
|
|
|
340
354
|
try {
|
|
341
355
|
val = await this._loadElement(`${path}/${key}`);
|
|
342
356
|
} catch (e) {
|
|
343
|
-
|
|
357
|
+
log.error(`Error in _loadDict: could not load ${key}`);
|
|
344
358
|
}
|
|
345
359
|
result[key] = val;
|
|
346
360
|
}));
|
package/src/ZarrDataSource.js
CHANGED
|
@@ -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 '
|
|
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
|
+
}
|