@vitessce/csv 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/CsvSource.js +27 -0
- package/dist/csv-loaders/CsvLoader.js +26 -0
- package/dist/csv-loaders/FeatureLabelsCsv.js +18 -0
- package/dist/csv-loaders/ObsEmbeddingCsv.js +23 -0
- package/dist/csv-loaders/ObsFeatureMatrixCsv.js +30 -0
- package/dist/csv-loaders/ObsLabelsCsv.js +18 -0
- package/dist/csv-loaders/ObsLocationsCsv.js +23 -0
- package/dist/csv-loaders/ObsSetsCsv.js +48 -0
- package/dist/csv-loaders/index.js +7 -0
- package/dist/index.js +2 -0
- package/package.json +27 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { obsSetsCsvSchema, LoaderResult, AbstractLoaderError } from '@vitessce/vit-s';
|
|
2
|
+
import { initializeCellSetColor, treeToMembershipMap, dataToCellSetsTree } from '@vitessce/sets';
|
|
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
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as CsvLoader } from './CsvLoader';
|
|
2
|
+
export { default as FeatureLabelsCsvLoader } from './FeatureLabelsCsv';
|
|
3
|
+
export { default as ObsEmbeddingCsvLoader } from './ObsEmbeddingCsv';
|
|
4
|
+
export { default as ObsFeatureMatrixCsvLoader } from './ObsFeatureMatrixCsv';
|
|
5
|
+
export { default as ObsLabelsCsvLoader } from './ObsLabelsCsv';
|
|
6
|
+
export { default as ObsLocationsCsvLoader } from './ObsLocationsCsv';
|
|
7
|
+
export { default as ObsSetsCsvLoader } from './ObsSetsCsv';
|
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vitessce/csv",
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
|
+
"author": "Gehlenborg Lab",
|
|
5
|
+
"homepage": "http://vitessce.io",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/vitessce/vitessce.git"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@vitessce/constants-internal": "2.0.0-beta.0",
|
|
17
|
+
"@vitessce/sets": "2.0.0-beta.0",
|
|
18
|
+
"@vitessce/vit-s": "2.0.0-beta.0",
|
|
19
|
+
"d3-array": "^2.4.0",
|
|
20
|
+
"d3-dsv": "^1.1.1"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"start": "tsc --watch",
|
|
24
|
+
"build": "tsc",
|
|
25
|
+
"test": "pnpm exec vitest --run -r ../../../ --dir ."
|
|
26
|
+
}
|
|
27
|
+
}
|