@weng-lab/genomebrowser-ui 0.4.0 → 0.4.2
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/TrackSelect/Folders/biosamples/data/{human_with_wgbs.json.d.ts → humans_fixed.json.d.ts} +511 -511
- package/dist/TrackSelect/Folders/biosamples/shared/types.d.ts +1 -1
- package/dist/TrackSelect/Folders/index.d.ts +2 -0
- package/dist/TrackSelect/Folders/psychscreen/data/human.json.d.ts +815 -0
- package/dist/TrackSelect/Folders/psychscreen/human.d.ts +1 -0
- package/dist/TrackSelect/Folders/psychscreen/shared/PsychscreenGroupingCell.d.ts +2 -0
- package/dist/TrackSelect/Folders/psychscreen/shared/columns.d.ts +7 -0
- package/dist/TrackSelect/Folders/psychscreen/shared/createFolder.d.ts +9 -0
- package/dist/TrackSelect/Folders/psychscreen/shared/toTrack.d.ts +5 -0
- package/dist/TrackSelect/Folders/psychscreen/shared/types.d.ts +12 -0
- package/dist/TrackSelect/trackContext.d.ts +2 -1
- package/dist/TrackSelect/types.d.ts +1 -1
- package/dist/genomebrowser-ui.es.js +1814 -1625
- package/dist/genomebrowser-ui.es.js.map +1 -1
- package/package.json +2 -2
- package/src/TrackSelect/DataGrid/DataGridWrapper.tsx +99 -11
- package/src/TrackSelect/Folders/biosamples/data/fix-human-collections.mjs +119 -0
- package/src/TrackSelect/Folders/biosamples/data/humans_fixed.json +59909 -0
- package/src/TrackSelect/Folders/biosamples/human.ts +1 -1
- package/src/TrackSelect/Folders/biosamples/shared/columns.tsx +2 -2
- package/src/TrackSelect/Folders/biosamples/shared/types.ts +1 -1
- package/src/TrackSelect/Folders/index.ts +4 -0
- package/src/TrackSelect/Folders/psychscreen/data/human.json +812 -0
- package/src/TrackSelect/Folders/psychscreen/human.ts +10 -0
- package/src/TrackSelect/Folders/psychscreen/shared/PsychscreenGroupingCell.tsx +78 -0
- package/src/TrackSelect/Folders/psychscreen/shared/columns.tsx +52 -0
- package/src/TrackSelect/Folders/psychscreen/shared/createFolder.ts +45 -0
- package/src/TrackSelect/Folders/psychscreen/shared/toTrack.ts +48 -0
- package/src/TrackSelect/Folders/psychscreen/shared/types.ts +14 -0
- package/src/TrackSelect/TreeView/CustomTreeItem.tsx +10 -2
- package/src/TrackSelect/TreeView/TreeViewWrapper.tsx +4 -1
- package/src/TrackSelect/trackContext.ts +2 -0
- package/src/TrackSelect/types.ts +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weng-lab/genomebrowser-ui",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"publishConfig": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@mui/x-data-grid-premium": "^8.19.0",
|
|
24
24
|
"react": "^19.0.0",
|
|
25
25
|
"react-dom": "^19.0.0",
|
|
26
|
-
"@weng-lab/genomebrowser": "1.8.
|
|
26
|
+
"@weng-lab/genomebrowser": "1.8.6"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@eslint/js": "^9.34.0",
|
|
@@ -5,9 +5,12 @@ import {
|
|
|
5
5
|
GridAutosizeOptions,
|
|
6
6
|
GridColDef,
|
|
7
7
|
GridColumnVisibilityModel,
|
|
8
|
+
GridRenderCellParams,
|
|
9
|
+
GridRowId,
|
|
10
|
+
GridRowSelectionModel,
|
|
8
11
|
useGridApiRef,
|
|
9
12
|
} from "@mui/x-data-grid-premium";
|
|
10
|
-
import { useEffect, useMemo, useState } from "react";
|
|
13
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
11
14
|
import { DataGridProps } from "../types";
|
|
12
15
|
import { DefaultGroupingCell } from "./DefaultGroupingCell";
|
|
13
16
|
|
|
@@ -17,6 +20,25 @@ const autosizeOptions: GridAutosizeOptions = {
|
|
|
17
20
|
outliersFactor: 1.5,
|
|
18
21
|
};
|
|
19
22
|
|
|
23
|
+
const areSetsEqual = <T,>(a: Set<T>, b: Set<T>) => {
|
|
24
|
+
if (a.size !== b.size) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
for (const value of a) {
|
|
29
|
+
if (!b.has(value)) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return true;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const areSelectionModelsEqual = (
|
|
38
|
+
a: GridRowSelectionModel,
|
|
39
|
+
b: GridRowSelectionModel,
|
|
40
|
+
) => a.type === b.type && areSetsEqual(a.ids, b.ids);
|
|
41
|
+
|
|
20
42
|
export function DataGridWrapper(props: DataGridProps) {
|
|
21
43
|
const {
|
|
22
44
|
columns,
|
|
@@ -32,6 +54,60 @@ export function DataGridWrapper(props: DataGridProps) {
|
|
|
32
54
|
|
|
33
55
|
const apiRef = useGridApiRef();
|
|
34
56
|
|
|
57
|
+
const rowIdSet = useMemo(
|
|
58
|
+
() => new Set(rows.map((row: { id: string }) => row.id)),
|
|
59
|
+
[rows],
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const filterToLeafIds = useCallback(
|
|
63
|
+
(ids: Set<GridRowId>) =>
|
|
64
|
+
new Set([...ids].map(String).filter((id) => rowIdSet.has(id))),
|
|
65
|
+
[rowIdSet],
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const getPropagatedSelectionModel = useCallback(
|
|
69
|
+
(ids: Set<GridRowId>) => {
|
|
70
|
+
const selectionModel: GridRowSelectionModel = {
|
|
71
|
+
type: "include",
|
|
72
|
+
ids,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
return apiRef.current.getPropagatedRowSelectionModel
|
|
76
|
+
? apiRef.current.getPropagatedRowSelectionModel(selectionModel)
|
|
77
|
+
: selectionModel;
|
|
78
|
+
},
|
|
79
|
+
[apiRef],
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const [rowSelectionModel, setRowSelectionModel] =
|
|
83
|
+
useState<GridRowSelectionModel>(() => ({
|
|
84
|
+
type: "include",
|
|
85
|
+
ids: new Set(selectedIds),
|
|
86
|
+
}));
|
|
87
|
+
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
const currentLeafIds = filterToLeafIds(rowSelectionModel.ids);
|
|
90
|
+
if (areSetsEqual(currentLeafIds, selectedIds)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const nextSelectionModel = getPropagatedSelectionModel(
|
|
95
|
+
new Set(selectedIds),
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
setRowSelectionModel((currentSelectionModel) =>
|
|
99
|
+
areSelectionModelsEqual(currentSelectionModel, nextSelectionModel)
|
|
100
|
+
? currentSelectionModel
|
|
101
|
+
: nextSelectionModel,
|
|
102
|
+
);
|
|
103
|
+
}, [
|
|
104
|
+
filterToLeafIds,
|
|
105
|
+
getPropagatedSelectionModel,
|
|
106
|
+
groupingModel,
|
|
107
|
+
rowSelectionModel.ids,
|
|
108
|
+
selectedIds,
|
|
109
|
+
]);
|
|
110
|
+
|
|
35
111
|
useEffect(() => {
|
|
36
112
|
if (apiRef.current && apiRef.current.autosizeColumns) {
|
|
37
113
|
apiRef.current.autosizeColumns(autosizeOptions);
|
|
@@ -88,7 +164,7 @@ export function DataGridWrapper(props: DataGridProps) {
|
|
|
88
164
|
apiRef={apiRef}
|
|
89
165
|
rows={rows}
|
|
90
166
|
columns={columns}
|
|
91
|
-
getRowId={(row) => row.id}
|
|
167
|
+
getRowId={(row: { id: string }) => row.id}
|
|
92
168
|
autosizeOptions={autosizeOptions}
|
|
93
169
|
rowGroupingModel={groupingModel}
|
|
94
170
|
groupingColDef={{
|
|
@@ -97,20 +173,32 @@ export function DataGridWrapper(props: DataGridProps) {
|
|
|
97
173
|
minWidth: 300,
|
|
98
174
|
maxWidth: 500,
|
|
99
175
|
flex: 2,
|
|
100
|
-
renderCell: (params) =>
|
|
176
|
+
renderCell: (params: GridRenderCellParams) => (
|
|
177
|
+
<GroupingCell {...params} />
|
|
178
|
+
),
|
|
101
179
|
}}
|
|
102
180
|
columnVisibilityModel={columnVisibilityModel}
|
|
103
181
|
onColumnVisibilityModelChange={setColumnVisibilityModel}
|
|
104
|
-
onRowSelectionModelChange={(selection) => {
|
|
105
|
-
const
|
|
106
|
-
|
|
182
|
+
onRowSelectionModelChange={(selection: GridRowSelectionModel) => {
|
|
183
|
+
const nextSelectionModel = getPropagatedSelectionModel(
|
|
184
|
+
selection.ids,
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
setRowSelectionModel((currentSelectionModel) =>
|
|
188
|
+
areSelectionModelsEqual(currentSelectionModel, nextSelectionModel)
|
|
189
|
+
? currentSelectionModel
|
|
190
|
+
: nextSelectionModel,
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
const leafIds = filterToLeafIds(nextSelectionModel.ids);
|
|
194
|
+
|
|
195
|
+
if (!areSetsEqual(leafIds, selectedIds)) {
|
|
196
|
+
onSelectionChange(leafIds);
|
|
197
|
+
}
|
|
107
198
|
}}
|
|
108
|
-
rowSelectionPropagation={{ descendants: true, parents:
|
|
199
|
+
rowSelectionPropagation={{ descendants: true, parents: true }}
|
|
109
200
|
disableRowGrouping={false}
|
|
110
|
-
rowSelectionModel={
|
|
111
|
-
type: "include",
|
|
112
|
-
ids: selectedIds,
|
|
113
|
-
}}
|
|
201
|
+
rowSelectionModel={rowSelectionModel}
|
|
114
202
|
slotProps={{
|
|
115
203
|
filterPanel: {
|
|
116
204
|
filterFormProps: {
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
const inputPath = join(__dirname, "human_with_wgbs.json");
|
|
7
|
+
const outputPath = join(__dirname, "humans_fixed.json");
|
|
8
|
+
|
|
9
|
+
const expectedCounts = {
|
|
10
|
+
Core: 170,
|
|
11
|
+
Partial: 1155,
|
|
12
|
+
Ancillary: 562,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const counts = {
|
|
16
|
+
Core: 0,
|
|
17
|
+
Partial: 0,
|
|
18
|
+
Ancillary: 0,
|
|
19
|
+
NA: 0,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const specialCases = {
|
|
23
|
+
GM12866_ENCDO000ABQ: "NA",
|
|
24
|
+
neural_crest_cell_ENCDO222AAA: "Partial",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const specialCaseFound = Object.fromEntries(
|
|
28
|
+
Object.keys(specialCases).map((name) => [name, false]),
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
function classifyTrack(track) {
|
|
32
|
+
const specialCollection = specialCases[track.name];
|
|
33
|
+
if (specialCollection) {
|
|
34
|
+
specialCaseFound[track.name] = true;
|
|
35
|
+
return specialCollection;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const assays = new Set(
|
|
39
|
+
track.assays.map((assay) => assay.assay.toLowerCase()),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
if (!assays.has("dnase")) {
|
|
43
|
+
return "Ancillary";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (
|
|
47
|
+
assays.has("h3k4me3") &&
|
|
48
|
+
assays.has("h3k27ac") &&
|
|
49
|
+
assays.has("ctcf")
|
|
50
|
+
) {
|
|
51
|
+
return "Core";
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return "Partial";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function isAggregate(track) {
|
|
58
|
+
return track.name === "aggregate-biosample-data" || track.ontology === "aggregate";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function validateCounts() {
|
|
62
|
+
const mismatches = Object.entries(expectedCounts).filter(
|
|
63
|
+
([collection, expected]) => counts[collection] !== expected,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
if (mismatches.length === 0) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
console.error("Classification count validation failed.");
|
|
71
|
+
console.error("Expected:", expectedCounts);
|
|
72
|
+
console.error("Actual:", counts);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const input = JSON.parse(await readFile(inputPath, "utf8"));
|
|
77
|
+
const changes = [];
|
|
78
|
+
|
|
79
|
+
const fixedTracks = input.tracks.map((track) => {
|
|
80
|
+
const collection = classifyTrack(track);
|
|
81
|
+
|
|
82
|
+
if (!isAggregate(track)) {
|
|
83
|
+
counts[collection] += 1;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (track.collection !== collection) {
|
|
87
|
+
changes.push({
|
|
88
|
+
name: track.name,
|
|
89
|
+
displayName: track.displayName,
|
|
90
|
+
from: track.collection,
|
|
91
|
+
to: collection,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
...track,
|
|
97
|
+
collection,
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
validateCounts();
|
|
102
|
+
|
|
103
|
+
await writeFile(
|
|
104
|
+
outputPath,
|
|
105
|
+
`${JSON.stringify({ ...input, tracks: fixedTracks }, null, 2)}\n`,
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
console.log("Wrote", outputPath);
|
|
109
|
+
console.log("Counts excluding aggregate:", counts);
|
|
110
|
+
console.log("Changed tracks:", changes.length);
|
|
111
|
+
console.log("Special cases found:", specialCaseFound);
|
|
112
|
+
|
|
113
|
+
const changeCounts = changes.reduce((acc, change) => {
|
|
114
|
+
const key = `${change.from} -> ${change.to}`;
|
|
115
|
+
acc[key] = (acc[key] ?? 0) + 1;
|
|
116
|
+
return acc;
|
|
117
|
+
}, {});
|
|
118
|
+
|
|
119
|
+
console.log("Change counts:", changeCounts);
|