@vitessce/csv 2.0.2 → 2.0.3
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.mjs +10321 -0
- package/{dist → dist-tsc}/index.js +0 -0
- package/package.json +8 -8
- package/src/CsvSource.js +28 -0
- package/src/csv-loaders/CsvLoader.js +33 -0
- package/src/csv-loaders/FeatureLabelsCsv.js +21 -0
- package/src/csv-loaders/ObsEmbeddingCsv.js +26 -0
- package/src/csv-loaders/ObsFeatureMatrixCsv.js +40 -0
- package/src/csv-loaders/ObsLabelsCsv.js +21 -0
- package/src/csv-loaders/ObsLocationsCsv.js +26 -0
- package/src/csv-loaders/ObsSetsCsv.js +69 -0
- package/{dist → src}/csv-loaders/index.js +0 -0
- package/src/index.js +2 -0
- package/dist/CsvSource.js +0 -27
- package/dist/csv-loaders/CsvLoader.js +0 -26
- package/dist/csv-loaders/FeatureLabelsCsv.js +0 -18
- package/dist/csv-loaders/ObsEmbeddingCsv.js +0 -23
- package/dist/csv-loaders/ObsFeatureMatrixCsv.js +0 -30
- package/dist/csv-loaders/ObsLabelsCsv.js +0 -18
- package/dist/csv-loaders/ObsLocationsCsv.js +0 -23
- package/dist/csv-loaders/ObsSetsCsv.js +0 -48
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitessce/csv",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"author": "Gehlenborg Lab",
|
|
5
5
|
"homepage": "http://vitessce.io",
|
|
6
6
|
"repository": {
|
|
@@ -8,20 +8,20 @@
|
|
|
8
8
|
"url": "git+https://github.com/vitessce/vitessce.git"
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"main": "dist/index.
|
|
11
|
+
"main": "dist/index.mjs",
|
|
12
12
|
"files": [
|
|
13
|
-
"dist"
|
|
13
|
+
"dist",
|
|
14
|
+
"src"
|
|
14
15
|
],
|
|
15
16
|
"dependencies": {
|
|
16
17
|
"d3-array": "^2.4.0",
|
|
17
18
|
"d3-dsv": "^1.1.1",
|
|
18
|
-
"@vitessce/constants-internal": "2.0.
|
|
19
|
-
"@vitessce/sets-utils": "2.0.
|
|
20
|
-
"@vitessce/vit-s": "2.0.
|
|
19
|
+
"@vitessce/constants-internal": "2.0.3",
|
|
20
|
+
"@vitessce/sets-utils": "2.0.3",
|
|
21
|
+
"@vitessce/vit-s": "2.0.3"
|
|
21
22
|
},
|
|
22
23
|
"scripts": {
|
|
23
|
-
"
|
|
24
|
-
"build": "tsc",
|
|
24
|
+
"bundle": "pnpm exec vite build -c ../../../scripts/vite.config.js",
|
|
25
25
|
"test": "pnpm exec vitest --run -r ../../../ --dir ."
|
|
26
26
|
}
|
|
27
27
|
}
|
package/src/CsvSource.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* eslint-disable no-underscore-dangle */
|
|
2
|
+
import { csvParse } from 'd3-dsv';
|
|
3
|
+
import { DataSourceFetchError, AbstractLoaderError } from '@vitessce/vit-s';
|
|
4
|
+
|
|
5
|
+
export default class CsvSource {
|
|
6
|
+
constructor({ url, requestInit }) {
|
|
7
|
+
this.url = url;
|
|
8
|
+
this.requestInit = requestInit;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
get data() {
|
|
12
|
+
if (this._data) return this._data;
|
|
13
|
+
this._data = fetch(this.url, this.requestInit).then((response) => {
|
|
14
|
+
if (!response.ok) {
|
|
15
|
+
return Promise.reject(new DataSourceFetchError('CsvSource', this.url, response.headers));
|
|
16
|
+
}
|
|
17
|
+
return response.text();
|
|
18
|
+
// eslint-disable-next-line no-console
|
|
19
|
+
}).catch(() => Promise.reject(new DataSourceFetchError('CsvSource', this.url, {})))
|
|
20
|
+
.then((data) => {
|
|
21
|
+
if (data instanceof AbstractLoaderError) {
|
|
22
|
+
return Promise.reject(data);
|
|
23
|
+
}
|
|
24
|
+
return csvParse(data);
|
|
25
|
+
});
|
|
26
|
+
return this._data;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AbstractTwoStepLoader, AbstractLoaderError, LoaderResult } from '@vitessce/vit-s';
|
|
2
|
+
|
|
3
|
+
export default class CsvLoader extends AbstractTwoStepLoader {
|
|
4
|
+
getSourceData() {
|
|
5
|
+
const {
|
|
6
|
+
url,
|
|
7
|
+
} = this;
|
|
8
|
+
if (this.data) {
|
|
9
|
+
return this.data;
|
|
10
|
+
}
|
|
11
|
+
this.data = this.dataSource.data
|
|
12
|
+
.then((data) => {
|
|
13
|
+
if (data instanceof AbstractLoaderError) {
|
|
14
|
+
return Promise.reject(data);
|
|
15
|
+
}
|
|
16
|
+
return Promise.resolve(new LoaderResult(data, url));
|
|
17
|
+
});
|
|
18
|
+
return this.data;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async load() {
|
|
22
|
+
const payload = await this.getSourceData().catch(reason => Promise.resolve(reason));
|
|
23
|
+
if (payload instanceof AbstractLoaderError) {
|
|
24
|
+
return Promise.reject(payload);
|
|
25
|
+
}
|
|
26
|
+
const { data, url } = payload;
|
|
27
|
+
const result = this.loadFromCache(data);
|
|
28
|
+
return Promise.resolve(new LoaderResult(
|
|
29
|
+
result,
|
|
30
|
+
url,
|
|
31
|
+
));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { featureLabelsCsvSchema } from '@vitessce/vit-s';
|
|
2
|
+
import CsvLoader from './CsvLoader';
|
|
3
|
+
|
|
4
|
+
export default class FeatureLabelsCsvLoader extends CsvLoader {
|
|
5
|
+
constructor(dataSource, params) {
|
|
6
|
+
super(dataSource, params);
|
|
7
|
+
|
|
8
|
+
this.optionsSchema = featureLabelsCsvSchema;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
loadFromCache(data) {
|
|
12
|
+
if (this.cachedResult) {
|
|
13
|
+
return this.cachedResult;
|
|
14
|
+
}
|
|
15
|
+
const { featureIndex: indexCol, featureLabels: labelCol } = this.options;
|
|
16
|
+
const featureIndex = data.map(d => String(d[indexCol]));
|
|
17
|
+
const featureLabels = data.map(d => String(d[labelCol]));
|
|
18
|
+
this.cachedResult = { featureIndex, featureLabels };
|
|
19
|
+
return this.cachedResult;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { obsEmbeddingCsvSchema } from '@vitessce/vit-s';
|
|
2
|
+
import CsvLoader from './CsvLoader';
|
|
3
|
+
|
|
4
|
+
export default class ObsEmbeddingCsvLoader extends CsvLoader {
|
|
5
|
+
constructor(dataSource, params) {
|
|
6
|
+
super(dataSource, params);
|
|
7
|
+
|
|
8
|
+
this.optionsSchema = obsEmbeddingCsvSchema;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
loadFromCache(data) {
|
|
12
|
+
if (this.cachedResult) {
|
|
13
|
+
return this.cachedResult;
|
|
14
|
+
}
|
|
15
|
+
const { obsIndex: indexCol, obsEmbedding: [xCol, yCol] } = this.options;
|
|
16
|
+
const obsIndex = data.map(d => String(d[indexCol]));
|
|
17
|
+
const obsEmbeddingX = Float32Array.from(data.map(d => d[xCol]));
|
|
18
|
+
const obsEmbeddingY = Float32Array.from(data.map(d => d[yCol]));
|
|
19
|
+
const obsEmbedding = {
|
|
20
|
+
data: [obsEmbeddingX, obsEmbeddingY],
|
|
21
|
+
shape: [2, obsEmbeddingX.length],
|
|
22
|
+
};
|
|
23
|
+
this.cachedResult = { obsIndex, obsEmbedding };
|
|
24
|
+
return this.cachedResult;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { max } from 'd3-array';
|
|
2
|
+
import { emptySchema } from '@vitessce/vit-s';
|
|
3
|
+
import CsvLoader from './CsvLoader';
|
|
4
|
+
|
|
5
|
+
export default class ObsFeatureMatrixCsvLoader extends CsvLoader {
|
|
6
|
+
constructor(dataSource, params) {
|
|
7
|
+
super(dataSource, params);
|
|
8
|
+
|
|
9
|
+
this.optionsSchema = emptySchema;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
loadFromCache(data) {
|
|
13
|
+
if (this.cachedResult) {
|
|
14
|
+
return this.cachedResult;
|
|
15
|
+
}
|
|
16
|
+
const obsIndex = data.map(d => String(d[data.columns[0]]));
|
|
17
|
+
const featureIndex = [...data.columns];
|
|
18
|
+
featureIndex.shift(); // Remove first element which is index colname.
|
|
19
|
+
const shape = [obsIndex.length, featureIndex.length];
|
|
20
|
+
const out = new Uint8Array(shape[0] * shape[1]);
|
|
21
|
+
// Normalize by gene. Compute per-gene max.
|
|
22
|
+
const featureMax = featureIndex
|
|
23
|
+
.map(featureId => max(data.map(d => parseFloat(d[featureId]))));
|
|
24
|
+
// Divide each value by gene-specific max.
|
|
25
|
+
data.forEach((row, obsI) => {
|
|
26
|
+
const normalizedRow = featureIndex.map(
|
|
27
|
+
(featureId, featureI) => parseFloat(row[featureId]) / featureMax[featureI] * 255,
|
|
28
|
+
);
|
|
29
|
+
out.set(
|
|
30
|
+
normalizedRow,
|
|
31
|
+
obsI * shape[1],
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const obsFeatureMatrix = { data: out };
|
|
36
|
+
|
|
37
|
+
this.cachedResult = { obsIndex, featureIndex, obsFeatureMatrix };
|
|
38
|
+
return this.cachedResult;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { obsLabelsCsvSchema } from '@vitessce/vit-s';
|
|
2
|
+
import CsvLoader from './CsvLoader';
|
|
3
|
+
|
|
4
|
+
export default class ObsLabelsCsvLoader extends CsvLoader {
|
|
5
|
+
constructor(dataSource, params) {
|
|
6
|
+
super(dataSource, params);
|
|
7
|
+
|
|
8
|
+
this.optionsSchema = obsLabelsCsvSchema;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
loadFromCache(data) {
|
|
12
|
+
if (this.cachedResult) {
|
|
13
|
+
return this.cachedResult;
|
|
14
|
+
}
|
|
15
|
+
const { obsIndex: indexCol, obsLabels: labelCol } = this.options;
|
|
16
|
+
const obsIndex = data.map(d => String(d[indexCol]));
|
|
17
|
+
const obsLabels = data.map(d => String(d[labelCol]));
|
|
18
|
+
this.cachedResult = { obsIndex, obsLabels };
|
|
19
|
+
return this.cachedResult;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { obsLocationsCsvSchema } from '@vitessce/vit-s';
|
|
2
|
+
import CsvLoader from './CsvLoader';
|
|
3
|
+
|
|
4
|
+
export default class ObsLocationsCsvLoader extends CsvLoader {
|
|
5
|
+
constructor(dataSource, params) {
|
|
6
|
+
super(dataSource, params);
|
|
7
|
+
|
|
8
|
+
this.optionsSchema = obsLocationsCsvSchema;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
loadFromCache(data) {
|
|
12
|
+
if (this.cachedResult) {
|
|
13
|
+
return this.cachedResult;
|
|
14
|
+
}
|
|
15
|
+
const { obsIndex: indexCol, obsLocations: [xCol, yCol] } = this.options;
|
|
16
|
+
const obsIndex = data.map(d => String(d[indexCol]));
|
|
17
|
+
const obsLocationsX = Float32Array.from(data.map(d => d[xCol]));
|
|
18
|
+
const obsLocationsY = Float32Array.from(data.map(d => d[yCol]));
|
|
19
|
+
const obsLocations = {
|
|
20
|
+
data: [obsLocationsX, obsLocationsY],
|
|
21
|
+
shape: [2, obsLocationsX.length],
|
|
22
|
+
};
|
|
23
|
+
this.cachedResult = { obsIndex, obsLocations };
|
|
24
|
+
return this.cachedResult;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { obsSetsCsvSchema, LoaderResult, AbstractLoaderError } from '@vitessce/vit-s';
|
|
2
|
+
import { initializeCellSetColor, treeToMembershipMap, dataToCellSetsTree } from '@vitessce/sets-utils';
|
|
3
|
+
import CsvLoader from './CsvLoader';
|
|
4
|
+
|
|
5
|
+
export default class ObsSetsCsvLoader extends CsvLoader {
|
|
6
|
+
constructor(dataSource, params) {
|
|
7
|
+
super(dataSource, params);
|
|
8
|
+
|
|
9
|
+
this.optionsSchema = obsSetsCsvSchema;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
loadFromCache(data) {
|
|
13
|
+
if (this.cachedResult) {
|
|
14
|
+
return this.cachedResult;
|
|
15
|
+
}
|
|
16
|
+
const { obsIndex: indexCol, obsSets: setsArr } = this.options;
|
|
17
|
+
const obsIndex = data.map(d => String(d[indexCol]));
|
|
18
|
+
|
|
19
|
+
const setsCols = setsArr.map(({ column }) => column);
|
|
20
|
+
const cellSetIds = setsCols.map(setCol => (Array.isArray(setCol)
|
|
21
|
+
? setCol.map(subCol => data.map(d => d[subCol]))
|
|
22
|
+
: data.map(d => d[setCol])
|
|
23
|
+
));
|
|
24
|
+
const scoresCols = setsArr.map(option => option.scorePath || undefined);
|
|
25
|
+
const cellSetScores = scoresCols.map(scoreCol => (
|
|
26
|
+
scoreCol ? data.map(d => d[scoreCol]) : undefined
|
|
27
|
+
));
|
|
28
|
+
const obsIndices = cellSetIds.map(() => obsIndex);
|
|
29
|
+
const cellSetsTree = dataToCellSetsTree([
|
|
30
|
+
obsIndices,
|
|
31
|
+
cellSetIds,
|
|
32
|
+
cellSetScores,
|
|
33
|
+
], setsArr);
|
|
34
|
+
const obsSetsMembership = treeToMembershipMap(cellSetsTree);
|
|
35
|
+
|
|
36
|
+
const coordinationValues = {};
|
|
37
|
+
const { tree } = cellSetsTree;
|
|
38
|
+
const newAutoSetSelectionParentName = tree[0].name;
|
|
39
|
+
// Create a list of set paths to initally select.
|
|
40
|
+
const newAutoSetSelections = tree[0].children.map(node => [
|
|
41
|
+
newAutoSetSelectionParentName,
|
|
42
|
+
node.name,
|
|
43
|
+
]);
|
|
44
|
+
// Create a list of cell set objects with color mappings.
|
|
45
|
+
const newAutoSetColors = initializeCellSetColor(cellSetsTree, []);
|
|
46
|
+
coordinationValues.obsSetSelection = newAutoSetSelections;
|
|
47
|
+
coordinationValues.obsSetColor = newAutoSetColors;
|
|
48
|
+
return [obsIndex, cellSetsTree, obsSetsMembership, coordinationValues];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async load() {
|
|
52
|
+
const payload = await this.getSourceData().catch(reason => Promise.resolve(reason));
|
|
53
|
+
if (payload instanceof AbstractLoaderError) {
|
|
54
|
+
return Promise.reject(payload);
|
|
55
|
+
}
|
|
56
|
+
const { data, url } = payload;
|
|
57
|
+
const [
|
|
58
|
+
obsIndex,
|
|
59
|
+
cellSetsTree,
|
|
60
|
+
obsSetsMembership,
|
|
61
|
+
coordinationValues,
|
|
62
|
+
] = this.loadFromCache(data);
|
|
63
|
+
return Promise.resolve(
|
|
64
|
+
new LoaderResult({
|
|
65
|
+
obsIndex, obsSets: cellSetsTree, obsSetsMembership,
|
|
66
|
+
}, url, coordinationValues),
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
File without changes
|
package/src/index.js
ADDED
package/dist/CsvSource.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-underscore-dangle */
|
|
2
|
-
import { csvParse } from 'd3-dsv';
|
|
3
|
-
import { DataSourceFetchError, AbstractLoaderError } from '@vitessce/vit-s';
|
|
4
|
-
export default class CsvSource {
|
|
5
|
-
constructor({ url, requestInit }) {
|
|
6
|
-
this.url = url;
|
|
7
|
-
this.requestInit = requestInit;
|
|
8
|
-
}
|
|
9
|
-
get data() {
|
|
10
|
-
if (this._data)
|
|
11
|
-
return this._data;
|
|
12
|
-
this._data = fetch(this.url, this.requestInit).then((response) => {
|
|
13
|
-
if (!response.ok) {
|
|
14
|
-
return Promise.reject(new DataSourceFetchError('CsvSource', this.url, response.headers));
|
|
15
|
-
}
|
|
16
|
-
return response.text();
|
|
17
|
-
// eslint-disable-next-line no-console
|
|
18
|
-
}).catch(() => Promise.reject(new DataSourceFetchError('CsvSource', this.url, {})))
|
|
19
|
-
.then((data) => {
|
|
20
|
-
if (data instanceof AbstractLoaderError) {
|
|
21
|
-
return Promise.reject(data);
|
|
22
|
-
}
|
|
23
|
-
return csvParse(data);
|
|
24
|
-
});
|
|
25
|
-
return this._data;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { AbstractTwoStepLoader, AbstractLoaderError, LoaderResult } from '@vitessce/vit-s';
|
|
2
|
-
export default class CsvLoader extends AbstractTwoStepLoader {
|
|
3
|
-
getSourceData() {
|
|
4
|
-
const { url, } = this;
|
|
5
|
-
if (this.data) {
|
|
6
|
-
return this.data;
|
|
7
|
-
}
|
|
8
|
-
this.data = this.dataSource.data
|
|
9
|
-
.then((data) => {
|
|
10
|
-
if (data instanceof AbstractLoaderError) {
|
|
11
|
-
return Promise.reject(data);
|
|
12
|
-
}
|
|
13
|
-
return Promise.resolve(new LoaderResult(data, url));
|
|
14
|
-
});
|
|
15
|
-
return this.data;
|
|
16
|
-
}
|
|
17
|
-
async load() {
|
|
18
|
-
const payload = await this.getSourceData().catch(reason => Promise.resolve(reason));
|
|
19
|
-
if (payload instanceof AbstractLoaderError) {
|
|
20
|
-
return Promise.reject(payload);
|
|
21
|
-
}
|
|
22
|
-
const { data, url } = payload;
|
|
23
|
-
const result = this.loadFromCache(data);
|
|
24
|
-
return Promise.resolve(new LoaderResult(result, url));
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { featureLabelsCsvSchema } from '@vitessce/vit-s';
|
|
2
|
-
import CsvLoader from './CsvLoader';
|
|
3
|
-
export default class FeatureLabelsCsvLoader extends CsvLoader {
|
|
4
|
-
constructor(dataSource, params) {
|
|
5
|
-
super(dataSource, params);
|
|
6
|
-
this.optionsSchema = featureLabelsCsvSchema;
|
|
7
|
-
}
|
|
8
|
-
loadFromCache(data) {
|
|
9
|
-
if (this.cachedResult) {
|
|
10
|
-
return this.cachedResult;
|
|
11
|
-
}
|
|
12
|
-
const { featureIndex: indexCol, featureLabels: labelCol } = this.options;
|
|
13
|
-
const featureIndex = data.map(d => String(d[indexCol]));
|
|
14
|
-
const featureLabels = data.map(d => String(d[labelCol]));
|
|
15
|
-
this.cachedResult = { featureIndex, featureLabels };
|
|
16
|
-
return this.cachedResult;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { obsEmbeddingCsvSchema } from '@vitessce/vit-s';
|
|
2
|
-
import CsvLoader from './CsvLoader';
|
|
3
|
-
export default class ObsEmbeddingCsvLoader extends CsvLoader {
|
|
4
|
-
constructor(dataSource, params) {
|
|
5
|
-
super(dataSource, params);
|
|
6
|
-
this.optionsSchema = obsEmbeddingCsvSchema;
|
|
7
|
-
}
|
|
8
|
-
loadFromCache(data) {
|
|
9
|
-
if (this.cachedResult) {
|
|
10
|
-
return this.cachedResult;
|
|
11
|
-
}
|
|
12
|
-
const { obsIndex: indexCol, obsEmbedding: [xCol, yCol] } = this.options;
|
|
13
|
-
const obsIndex = data.map(d => String(d[indexCol]));
|
|
14
|
-
const obsEmbeddingX = Float32Array.from(data.map(d => d[xCol]));
|
|
15
|
-
const obsEmbeddingY = Float32Array.from(data.map(d => d[yCol]));
|
|
16
|
-
const obsEmbedding = {
|
|
17
|
-
data: [obsEmbeddingX, obsEmbeddingY],
|
|
18
|
-
shape: [2, obsEmbeddingX.length],
|
|
19
|
-
};
|
|
20
|
-
this.cachedResult = { obsIndex, obsEmbedding };
|
|
21
|
-
return this.cachedResult;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { max } from 'd3-array';
|
|
2
|
-
import { emptySchema } from '@vitessce/vit-s';
|
|
3
|
-
import CsvLoader from './CsvLoader';
|
|
4
|
-
export default class ObsFeatureMatrixCsvLoader extends CsvLoader {
|
|
5
|
-
constructor(dataSource, params) {
|
|
6
|
-
super(dataSource, params);
|
|
7
|
-
this.optionsSchema = emptySchema;
|
|
8
|
-
}
|
|
9
|
-
loadFromCache(data) {
|
|
10
|
-
if (this.cachedResult) {
|
|
11
|
-
return this.cachedResult;
|
|
12
|
-
}
|
|
13
|
-
const obsIndex = data.map(d => String(d[data.columns[0]]));
|
|
14
|
-
const featureIndex = [...data.columns];
|
|
15
|
-
featureIndex.shift(); // Remove first element which is index colname.
|
|
16
|
-
const shape = [obsIndex.length, featureIndex.length];
|
|
17
|
-
const out = new Uint8Array(shape[0] * shape[1]);
|
|
18
|
-
// Normalize by gene. Compute per-gene max.
|
|
19
|
-
const featureMax = featureIndex
|
|
20
|
-
.map(featureId => max(data.map(d => parseFloat(d[featureId]))));
|
|
21
|
-
// Divide each value by gene-specific max.
|
|
22
|
-
data.forEach((row, obsI) => {
|
|
23
|
-
const normalizedRow = featureIndex.map((featureId, featureI) => parseFloat(row[featureId]) / featureMax[featureI] * 255);
|
|
24
|
-
out.set(normalizedRow, obsI * shape[1]);
|
|
25
|
-
});
|
|
26
|
-
const obsFeatureMatrix = { data: out };
|
|
27
|
-
this.cachedResult = { obsIndex, featureIndex, obsFeatureMatrix };
|
|
28
|
-
return this.cachedResult;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { obsLabelsCsvSchema } from '@vitessce/vit-s';
|
|
2
|
-
import CsvLoader from './CsvLoader';
|
|
3
|
-
export default class ObsLabelsCsvLoader extends CsvLoader {
|
|
4
|
-
constructor(dataSource, params) {
|
|
5
|
-
super(dataSource, params);
|
|
6
|
-
this.optionsSchema = obsLabelsCsvSchema;
|
|
7
|
-
}
|
|
8
|
-
loadFromCache(data) {
|
|
9
|
-
if (this.cachedResult) {
|
|
10
|
-
return this.cachedResult;
|
|
11
|
-
}
|
|
12
|
-
const { obsIndex: indexCol, obsLabels: labelCol } = this.options;
|
|
13
|
-
const obsIndex = data.map(d => String(d[indexCol]));
|
|
14
|
-
const obsLabels = data.map(d => String(d[labelCol]));
|
|
15
|
-
this.cachedResult = { obsIndex, obsLabels };
|
|
16
|
-
return this.cachedResult;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { obsLocationsCsvSchema } from '@vitessce/vit-s';
|
|
2
|
-
import CsvLoader from './CsvLoader';
|
|
3
|
-
export default class ObsLocationsCsvLoader extends CsvLoader {
|
|
4
|
-
constructor(dataSource, params) {
|
|
5
|
-
super(dataSource, params);
|
|
6
|
-
this.optionsSchema = obsLocationsCsvSchema;
|
|
7
|
-
}
|
|
8
|
-
loadFromCache(data) {
|
|
9
|
-
if (this.cachedResult) {
|
|
10
|
-
return this.cachedResult;
|
|
11
|
-
}
|
|
12
|
-
const { obsIndex: indexCol, obsLocations: [xCol, yCol] } = this.options;
|
|
13
|
-
const obsIndex = data.map(d => String(d[indexCol]));
|
|
14
|
-
const obsLocationsX = Float32Array.from(data.map(d => d[xCol]));
|
|
15
|
-
const obsLocationsY = Float32Array.from(data.map(d => d[yCol]));
|
|
16
|
-
const obsLocations = {
|
|
17
|
-
data: [obsLocationsX, obsLocationsY],
|
|
18
|
-
shape: [2, obsLocationsX.length],
|
|
19
|
-
};
|
|
20
|
-
this.cachedResult = { obsIndex, obsLocations };
|
|
21
|
-
return this.cachedResult;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { obsSetsCsvSchema, LoaderResult, AbstractLoaderError } from '@vitessce/vit-s';
|
|
2
|
-
import { initializeCellSetColor, treeToMembershipMap, dataToCellSetsTree } from '@vitessce/sets-utils';
|
|
3
|
-
import CsvLoader from './CsvLoader';
|
|
4
|
-
export default class ObsSetsCsvLoader extends CsvLoader {
|
|
5
|
-
constructor(dataSource, params) {
|
|
6
|
-
super(dataSource, params);
|
|
7
|
-
this.optionsSchema = obsSetsCsvSchema;
|
|
8
|
-
}
|
|
9
|
-
loadFromCache(data) {
|
|
10
|
-
if (this.cachedResult) {
|
|
11
|
-
return this.cachedResult;
|
|
12
|
-
}
|
|
13
|
-
const { obsIndex: indexCol, obsSets: setsArr } = this.options;
|
|
14
|
-
const obsIndex = data.map(d => String(d[indexCol]));
|
|
15
|
-
const setsCols = setsArr.map(({ column }) => column);
|
|
16
|
-
const cellSetIds = setsCols.map(setCol => (Array.isArray(setCol)
|
|
17
|
-
? setCol.map(subCol => data.map(d => d[subCol]))
|
|
18
|
-
: data.map(d => d[setCol])));
|
|
19
|
-
const scoresCols = setsArr.map(option => option.scorePath || undefined);
|
|
20
|
-
const cellSetScores = scoresCols.map(scoreCol => (scoreCol ? data.map(d => d[scoreCol]) : undefined));
|
|
21
|
-
const cellSetsTree = dataToCellSetsTree([obsIndex, cellSetIds, cellSetScores], setsArr);
|
|
22
|
-
const obsSetsMembership = treeToMembershipMap(cellSetsTree);
|
|
23
|
-
const coordinationValues = {};
|
|
24
|
-
const { tree } = cellSetsTree;
|
|
25
|
-
const newAutoSetSelectionParentName = tree[0].name;
|
|
26
|
-
// Create a list of set paths to initally select.
|
|
27
|
-
const newAutoSetSelections = tree[0].children.map(node => [
|
|
28
|
-
newAutoSetSelectionParentName,
|
|
29
|
-
node.name,
|
|
30
|
-
]);
|
|
31
|
-
// Create a list of cell set objects with color mappings.
|
|
32
|
-
const newAutoSetColors = initializeCellSetColor(cellSetsTree, []);
|
|
33
|
-
coordinationValues.obsSetSelection = newAutoSetSelections;
|
|
34
|
-
coordinationValues.obsSetColor = newAutoSetColors;
|
|
35
|
-
return [obsIndex, cellSetsTree, obsSetsMembership, coordinationValues];
|
|
36
|
-
}
|
|
37
|
-
async load() {
|
|
38
|
-
const payload = await this.getSourceData().catch(reason => Promise.resolve(reason));
|
|
39
|
-
if (payload instanceof AbstractLoaderError) {
|
|
40
|
-
return Promise.reject(payload);
|
|
41
|
-
}
|
|
42
|
-
const { data, url } = payload;
|
|
43
|
-
const [obsIndex, cellSetsTree, obsSetsMembership, coordinationValues,] = this.loadFromCache(data);
|
|
44
|
-
return Promise.resolve(new LoaderResult({
|
|
45
|
-
obsIndex, obsSets: cellSetsTree, obsSetsMembership,
|
|
46
|
-
}, url, coordinationValues));
|
|
47
|
-
}
|
|
48
|
-
}
|