@weng-lab/genomebrowser-ui 0.1.11 → 0.2.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/.env.local +1 -0
- package/dist/TrackSelect/DataGrid/DefaultGroupingCell.d.ts +6 -0
- package/dist/TrackSelect/FolderList/Breadcrumb.d.ts +6 -0
- package/dist/TrackSelect/FolderList/FolderCard.d.ts +6 -0
- package/dist/TrackSelect/FolderList/FolderList.d.ts +6 -0
- package/dist/TrackSelect/{Data/humanBiosamples.json.d.ts → Folders/biosamples/data/human.json.d.ts} +1940 -1919
- package/dist/TrackSelect/{Data/mouseBiosamples.json.d.ts → Folders/biosamples/data/mouse.json.d.ts} +408 -357
- package/dist/TrackSelect/Folders/biosamples/human.d.ts +7 -0
- package/dist/TrackSelect/Folders/biosamples/mouse.d.ts +7 -0
- package/dist/TrackSelect/Folders/biosamples/shared/AssayToggle.d.ts +14 -0
- package/dist/TrackSelect/Folders/biosamples/shared/BiosampleGroupingCell.d.ts +6 -0
- package/dist/TrackSelect/Folders/biosamples/shared/BiosampleTreeItem.d.ts +7 -0
- package/dist/TrackSelect/Folders/biosamples/shared/columns.d.ts +14 -0
- package/dist/TrackSelect/Folders/biosamples/shared/constants.d.ts +19 -0
- package/dist/TrackSelect/Folders/biosamples/shared/createFolder.d.ts +24 -0
- package/dist/TrackSelect/Folders/biosamples/shared/treeBuilder.d.ts +25 -0
- package/dist/TrackSelect/Folders/biosamples/shared/types.d.ts +44 -0
- package/dist/TrackSelect/Folders/genes/data/human.json.d.ts +10 -0
- package/dist/TrackSelect/Folders/genes/data/mouse.json.d.ts +10 -0
- package/dist/TrackSelect/Folders/genes/human.d.ts +7 -0
- package/dist/TrackSelect/Folders/genes/mouse.d.ts +7 -0
- package/dist/TrackSelect/Folders/genes/shared/columns.d.ts +14 -0
- package/dist/TrackSelect/Folders/genes/shared/createFolder.d.ts +12 -0
- package/dist/TrackSelect/Folders/genes/shared/treeBuilder.d.ts +13 -0
- package/dist/TrackSelect/Folders/genes/shared/types.d.ts +26 -0
- package/dist/TrackSelect/Folders/index.d.ts +14 -0
- package/dist/TrackSelect/Folders/types.d.ts +76 -0
- package/dist/TrackSelect/TrackSelect.d.ts +12 -5
- package/dist/TrackSelect/TreeView/CustomTreeItem.d.ts +3 -0
- package/dist/TrackSelect/TreeView/TreeViewWrapper.d.ts +1 -1
- package/dist/TrackSelect/store.d.ts +1 -2
- package/dist/TrackSelect/types.d.ts +24 -62
- package/dist/genomebrowser-ui.es.js +1373 -2117
- package/dist/genomebrowser-ui.es.js.map +1 -1
- package/dist/lib.d.ts +2 -2
- package/package.json +3 -3
- package/src/TrackSelect/DataGrid/DataGridWrapper.tsx +36 -20
- package/src/TrackSelect/DataGrid/DefaultGroupingCell.tsx +64 -0
- package/src/TrackSelect/FolderList/Breadcrumb.tsx +38 -0
- package/src/TrackSelect/FolderList/FolderCard.tsx +51 -0
- package/src/TrackSelect/FolderList/FolderList.tsx +47 -0
- package/src/TrackSelect/Folders/NEW.md +929 -0
- package/src/TrackSelect/{Data → Folders/biosamples/data}/formatBiosamples.go +2 -2
- package/src/TrackSelect/{Data/humanBiosamples.json → Folders/biosamples/data/human.json} +1940 -1919
- package/src/TrackSelect/{Data/mouseBiosamples.json → Folders/biosamples/data/mouse.json} +408 -357
- package/src/TrackSelect/Folders/biosamples/human.ts +17 -0
- package/src/TrackSelect/Folders/biosamples/mouse.ts +17 -0
- package/src/TrackSelect/Folders/biosamples/shared/AssayToggle.tsx +65 -0
- package/src/TrackSelect/{DataGrid/GroupingCell.tsx → Folders/biosamples/shared/BiosampleGroupingCell.tsx} +7 -5
- package/src/TrackSelect/Folders/biosamples/shared/BiosampleTreeItem.tsx +15 -0
- package/src/TrackSelect/{DataGrid → Folders/biosamples/shared}/columns.tsx +31 -17
- package/src/TrackSelect/Folders/biosamples/shared/constants.tsx +116 -0
- package/src/TrackSelect/Folders/biosamples/shared/createFolder.ts +116 -0
- package/src/TrackSelect/Folders/biosamples/shared/treeBuilder.ts +227 -0
- package/src/TrackSelect/Folders/biosamples/shared/types.ts +48 -0
- package/src/TrackSelect/Folders/genes/data/human.json +7 -0
- package/src/TrackSelect/Folders/genes/data/mouse.json +7 -0
- package/src/TrackSelect/Folders/genes/human.ts +16 -0
- package/src/TrackSelect/Folders/genes/mouse.ts +16 -0
- package/src/TrackSelect/Folders/genes/shared/columns.tsx +42 -0
- package/src/TrackSelect/Folders/genes/shared/createFolder.ts +68 -0
- package/src/TrackSelect/Folders/genes/shared/treeBuilder.ts +45 -0
- package/src/TrackSelect/Folders/genes/shared/types.ts +29 -0
- package/src/TrackSelect/Folders/index.ts +27 -0
- package/src/TrackSelect/Folders/types.ts +95 -0
- package/src/TrackSelect/TrackSelect.tsx +409 -311
- package/src/TrackSelect/TreeView/CustomTreeItem.tsx +217 -0
- package/src/TrackSelect/TreeView/TreeViewWrapper.tsx +47 -42
- package/src/TrackSelect/store.ts +103 -46
- package/src/TrackSelect/types.ts +28 -74
- package/src/lib.ts +2 -2
- package/test/main.tsx +113 -169
- package/.claude/settings.local.json +0 -7
- package/dist/TrackSelect/DataGrid/CustomToolbar.d.ts +0 -12
- package/dist/TrackSelect/DataGrid/GroupingCell.d.ts +0 -2
- package/dist/TrackSelect/DataGrid/columns.d.ts +0 -4
- package/dist/TrackSelect/DataGrid/dataGridHelpers.d.ts +0 -49
- package/dist/TrackSelect/TreeView/treeViewHelpers.d.ts +0 -49
- package/dist/TrackSelect/consts.d.ts +0 -11
- package/src/TrackSelect/DataGrid/CustomToolbar.tsx +0 -152
- package/src/TrackSelect/DataGrid/dataGridHelpers.tsx +0 -155
- package/src/TrackSelect/TreeView/treeViewHelpers.tsx +0 -475
- package/src/TrackSelect/consts.ts +0 -92
- package/src/TrackSelect/issues.md +0 -404
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { TreeViewBaseItem } from "@mui/x-tree-view";
|
|
2
|
+
import { ExtendedTreeItemProps } from "../../../types";
|
|
3
|
+
import { BiosampleRowInfo } from "./types";
|
|
4
|
+
import { assayTypes, ontologyTypes, formatAssayType } from "./constants";
|
|
5
|
+
|
|
6
|
+
/** Format an ID like "h3k27ac-ENCFF922YMQ" or "folder::h3k27ac-ENCFF922YMQ" to "H3K27ac - ENCFF922YMQ" */
|
|
7
|
+
function formatIdLabel(id: string): string {
|
|
8
|
+
// Remove folder prefix if present (e.g., "FolderName::h3k27ac-ENCFF922YMQ" -> "h3k27ac-ENCFF922YMQ")
|
|
9
|
+
const rawId = id.includes("::") ? id.split("::").pop()! : id;
|
|
10
|
+
|
|
11
|
+
const hyphenIndex = rawId.indexOf("-");
|
|
12
|
+
if (hyphenIndex === -1) return rawId;
|
|
13
|
+
|
|
14
|
+
const assayPart = rawId.substring(0, hyphenIndex);
|
|
15
|
+
const accessionPart = rawId.substring(hyphenIndex + 1);
|
|
16
|
+
|
|
17
|
+
return `${formatAssayType(assayPart)} - ${accessionPart}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Creates the root node for the tree view
|
|
22
|
+
*/
|
|
23
|
+
function createRootNode(
|
|
24
|
+
label: string,
|
|
25
|
+
folderId: string,
|
|
26
|
+
): TreeViewBaseItem<ExtendedTreeItemProps> {
|
|
27
|
+
return {
|
|
28
|
+
id: `${folderId}::root`,
|
|
29
|
+
label,
|
|
30
|
+
icon: "folder",
|
|
31
|
+
children: [],
|
|
32
|
+
allExpAccessions: [],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Builds tree in the sorted by assay view
|
|
38
|
+
* Hierarchy: Assay -> Ontology -> DisplayName -> Experiment
|
|
39
|
+
*
|
|
40
|
+
* @param selectedIds - list of selected row IDs
|
|
41
|
+
* @param rowById - Mapping between an id and its BiosampleRowInfo object
|
|
42
|
+
* @param rootLabel - Label for the root node
|
|
43
|
+
* @param folderId - Folder ID to prefix tree item IDs with
|
|
44
|
+
* @returns tree items for the RichTreeView
|
|
45
|
+
*/
|
|
46
|
+
export function buildSortedAssayTreeView(
|
|
47
|
+
selectedIds: string[],
|
|
48
|
+
rowById: Map<string, BiosampleRowInfo>,
|
|
49
|
+
rootLabel: string = "Biosamples",
|
|
50
|
+
folderId: string = "",
|
|
51
|
+
): TreeViewBaseItem<ExtendedTreeItemProps>[] {
|
|
52
|
+
const root = createRootNode(rootLabel, folderId);
|
|
53
|
+
const assayMap = new Map<string, TreeViewBaseItem<ExtendedTreeItemProps>>();
|
|
54
|
+
const ontologyMap = new Map<
|
|
55
|
+
string,
|
|
56
|
+
TreeViewBaseItem<ExtendedTreeItemProps>
|
|
57
|
+
>();
|
|
58
|
+
const displayNameMap = new Map<
|
|
59
|
+
string,
|
|
60
|
+
TreeViewBaseItem<ExtendedTreeItemProps>
|
|
61
|
+
>();
|
|
62
|
+
|
|
63
|
+
const selectedRows = selectedIds.reduce<BiosampleRowInfo[]>((acc, id) => {
|
|
64
|
+
const row = rowById.get(id);
|
|
65
|
+
if (row) acc.push(row);
|
|
66
|
+
return acc;
|
|
67
|
+
}, []);
|
|
68
|
+
|
|
69
|
+
selectedRows.forEach((row) => {
|
|
70
|
+
const assayKey = `${folderId}::${row.assay}`;
|
|
71
|
+
let assayNode = assayMap.get(assayKey);
|
|
72
|
+
if (!assayNode) {
|
|
73
|
+
assayNode = {
|
|
74
|
+
id: assayKey,
|
|
75
|
+
isAssayItem: true,
|
|
76
|
+
label: row.assay,
|
|
77
|
+
icon: "removeable",
|
|
78
|
+
children: [],
|
|
79
|
+
allExpAccessions: [],
|
|
80
|
+
};
|
|
81
|
+
assayMap.set(assayKey, assayNode);
|
|
82
|
+
root.children!.push(assayNode);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const ontologyKey = `${folderId}::${row.assay}-${row.ontology}`;
|
|
86
|
+
let ontologyNode = ontologyMap.get(ontologyKey);
|
|
87
|
+
if (!ontologyNode) {
|
|
88
|
+
ontologyNode = {
|
|
89
|
+
id: ontologyKey,
|
|
90
|
+
isAssayItem: false,
|
|
91
|
+
label: row.ontology,
|
|
92
|
+
icon: "removeable",
|
|
93
|
+
children: [],
|
|
94
|
+
allExpAccessions: [],
|
|
95
|
+
};
|
|
96
|
+
assayNode.children!.push(ontologyNode);
|
|
97
|
+
ontologyMap.set(ontologyKey, ontologyNode);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const displayNameKey = `${folderId}::${row.assay}-${row.ontology}-${row.displayName}`;
|
|
101
|
+
let displayNameNode = displayNameMap.get(displayNameKey);
|
|
102
|
+
if (!displayNameNode) {
|
|
103
|
+
displayNameNode = {
|
|
104
|
+
id: displayNameKey,
|
|
105
|
+
isAssayItem: false,
|
|
106
|
+
label: row.displayName,
|
|
107
|
+
icon: "removeable",
|
|
108
|
+
children: [],
|
|
109
|
+
allExpAccessions: [],
|
|
110
|
+
};
|
|
111
|
+
ontologyNode.children!.push(displayNameNode);
|
|
112
|
+
displayNameMap.set(displayNameKey, displayNameNode);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const expNode: TreeViewBaseItem<ExtendedTreeItemProps> = {
|
|
116
|
+
id: row.id,
|
|
117
|
+
isAssayItem: false,
|
|
118
|
+
label: formatIdLabel(row.id),
|
|
119
|
+
icon: "removeable",
|
|
120
|
+
assayName: row.assay,
|
|
121
|
+
children: [],
|
|
122
|
+
allExpAccessions: [row.id],
|
|
123
|
+
};
|
|
124
|
+
displayNameNode.children!.push(expNode);
|
|
125
|
+
|
|
126
|
+
assayNode.allExpAccessions!.push(row.id);
|
|
127
|
+
ontologyNode.allExpAccessions!.push(row.id);
|
|
128
|
+
displayNameNode.allExpAccessions!.push(row.id);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// standardize the order of the assay folders
|
|
132
|
+
root.children!.sort((a, b): number => {
|
|
133
|
+
const aAssay = a.id.split("::")[1] ?? a.id;
|
|
134
|
+
const bAssay = b.id.split("::")[1] ?? b.id;
|
|
135
|
+
return assayTypes.indexOf(aAssay) - assayTypes.indexOf(bAssay);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
return [root];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Builds tree in the default view (sorted by ontology)
|
|
143
|
+
* Hierarchy: Ontology -> DisplayName -> Experiment
|
|
144
|
+
*
|
|
145
|
+
* @param selectedIds - list of selected row IDs
|
|
146
|
+
* @param rowById - Mapping between an id and its BiosampleRowInfo object
|
|
147
|
+
* @param rootLabel - Label for the root node
|
|
148
|
+
* @param folderId - Folder ID to prefix tree item IDs with
|
|
149
|
+
* @returns tree items for the RichTreeView
|
|
150
|
+
*/
|
|
151
|
+
export function buildTreeView(
|
|
152
|
+
selectedIds: string[],
|
|
153
|
+
rowById: Map<string, BiosampleRowInfo>,
|
|
154
|
+
rootLabel: string = "Biosamples",
|
|
155
|
+
folderId: string = "",
|
|
156
|
+
): TreeViewBaseItem<ExtendedTreeItemProps>[] {
|
|
157
|
+
const root = createRootNode(rootLabel, folderId);
|
|
158
|
+
const ontologyMap = new Map<
|
|
159
|
+
string,
|
|
160
|
+
TreeViewBaseItem<ExtendedTreeItemProps>
|
|
161
|
+
>();
|
|
162
|
+
const displayNameMap = new Map<
|
|
163
|
+
string,
|
|
164
|
+
TreeViewBaseItem<ExtendedTreeItemProps>
|
|
165
|
+
>();
|
|
166
|
+
|
|
167
|
+
const selectedRows = selectedIds.reduce<BiosampleRowInfo[]>((acc, id) => {
|
|
168
|
+
const row = rowById.get(id);
|
|
169
|
+
if (row) acc.push(row);
|
|
170
|
+
return acc;
|
|
171
|
+
}, []);
|
|
172
|
+
|
|
173
|
+
selectedRows.forEach((row) => {
|
|
174
|
+
if (!row) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const ontologyKey = `${folderId}::${row.ontology}`;
|
|
178
|
+
let ontologyNode = ontologyMap.get(ontologyKey);
|
|
179
|
+
if (!ontologyNode) {
|
|
180
|
+
ontologyNode = {
|
|
181
|
+
id: ontologyKey,
|
|
182
|
+
label: row.ontology,
|
|
183
|
+
icon: "removeable",
|
|
184
|
+
children: [],
|
|
185
|
+
allExpAccessions: [],
|
|
186
|
+
};
|
|
187
|
+
ontologyMap.set(ontologyKey, ontologyNode);
|
|
188
|
+
root.children!.push(ontologyNode);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const displayNameKey = `${folderId}::${row.ontology}-${row.displayName}`;
|
|
192
|
+
let displayNameNode = displayNameMap.get(displayNameKey);
|
|
193
|
+
if (!displayNameNode) {
|
|
194
|
+
displayNameNode = {
|
|
195
|
+
id: displayNameKey,
|
|
196
|
+
label: row.displayName,
|
|
197
|
+
icon: "removeable",
|
|
198
|
+
children: [],
|
|
199
|
+
allExpAccessions: [],
|
|
200
|
+
};
|
|
201
|
+
ontologyNode.children!.push(displayNameNode);
|
|
202
|
+
displayNameMap.set(displayNameKey, displayNameNode);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const expNode: TreeViewBaseItem<ExtendedTreeItemProps> = {
|
|
206
|
+
id: row.id,
|
|
207
|
+
label: formatIdLabel(row.id),
|
|
208
|
+
icon: "removeable",
|
|
209
|
+
assayName: row.assay,
|
|
210
|
+
children: [],
|
|
211
|
+
allExpAccessions: [row.id],
|
|
212
|
+
};
|
|
213
|
+
displayNameNode.children!.push(expNode);
|
|
214
|
+
|
|
215
|
+
ontologyNode.allExpAccessions!.push(row.id);
|
|
216
|
+
displayNameNode.allExpAccessions!.push(row.id);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// standardize the order of the ontology folders
|
|
220
|
+
root.children!.sort((a, b): number => {
|
|
221
|
+
const aOntology = a.id.split("::")[1] ?? a.id;
|
|
222
|
+
const bOntology = b.id.split("::")[1] ?? b.id;
|
|
223
|
+
return ontologyTypes.indexOf(aOntology) - ontologyTypes.indexOf(bOntology);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
return [root];
|
|
227
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for biosample folder data
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Assay information from the JSON data
|
|
7
|
+
*/
|
|
8
|
+
export type BiosampleAssayInfo = {
|
|
9
|
+
id: string;
|
|
10
|
+
assay: string;
|
|
11
|
+
url: string;
|
|
12
|
+
experimentAccession: string;
|
|
13
|
+
fileAccession: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Track information from the JSON data
|
|
18
|
+
*/
|
|
19
|
+
export type BiosampleTrackInfo = {
|
|
20
|
+
name: string;
|
|
21
|
+
ontology: string;
|
|
22
|
+
lifeStage: string;
|
|
23
|
+
sampleType: string;
|
|
24
|
+
displayName: string;
|
|
25
|
+
assays: BiosampleAssayInfo[];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Row format for DataGrid (flattened from TrackInfo)
|
|
30
|
+
*/
|
|
31
|
+
export type BiosampleRowInfo = {
|
|
32
|
+
id: string;
|
|
33
|
+
ontology: string;
|
|
34
|
+
lifeStage: string;
|
|
35
|
+
sampleType: string;
|
|
36
|
+
displayName: string;
|
|
37
|
+
assay: string;
|
|
38
|
+
experimentAccession: string;
|
|
39
|
+
fileAccession: string;
|
|
40
|
+
url: string;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Structure of the biosample JSON data files
|
|
45
|
+
*/
|
|
46
|
+
export type BiosampleDataFile = {
|
|
47
|
+
tracks: BiosampleTrackInfo[];
|
|
48
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createGeneFolder } from "./shared/createFolder";
|
|
2
|
+
import humanData from "./data/human.json";
|
|
3
|
+
import { GeneDataFile } from "./shared/types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Gene annotations folder for human (GRCh38 assembly)
|
|
7
|
+
*
|
|
8
|
+
* Contains gene annotation tracks like GENCODE that users can
|
|
9
|
+
* select to display in the genome browser.
|
|
10
|
+
*/
|
|
11
|
+
export const humanGenesFolder = createGeneFolder({
|
|
12
|
+
id: "human-genes",
|
|
13
|
+
label: "Genes",
|
|
14
|
+
description: "Gene annotation tracks",
|
|
15
|
+
data: humanData as GeneDataFile,
|
|
16
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createGeneFolder } from "./shared/createFolder";
|
|
2
|
+
import mouseData from "./data/mouse.json";
|
|
3
|
+
import { GeneDataFile } from "./shared/types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Gene annotations folder for human (GRCh38 assembly)
|
|
7
|
+
*
|
|
8
|
+
* Contains gene annotation tracks like GENCODE that users can
|
|
9
|
+
* select to display in the genome browser.
|
|
10
|
+
*/
|
|
11
|
+
export const mouseGenesFolder = createGeneFolder({
|
|
12
|
+
id: "mouse-genes",
|
|
13
|
+
label: "Genes",
|
|
14
|
+
description: "Gene annotation tracks",
|
|
15
|
+
data: mouseData as GeneDataFile,
|
|
16
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { GridColDef } from "@mui/x-data-grid-premium";
|
|
2
|
+
import { GeneRowInfo } from "./types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Format versions array as comma-separated string with "v" prefix
|
|
6
|
+
* e.g., [29, 40] -> "v29, v40"
|
|
7
|
+
*/
|
|
8
|
+
function formatVersions(versions: number[]): string {
|
|
9
|
+
return versions.map((v) => `v${v}`).join(", ");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const displayNameCol: GridColDef<GeneRowInfo> = {
|
|
13
|
+
field: "displayName",
|
|
14
|
+
headerName: "Name",
|
|
15
|
+
flex: 1,
|
|
16
|
+
minWidth: 200,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const versionsCol: GridColDef<GeneRowInfo> = {
|
|
20
|
+
field: "versions",
|
|
21
|
+
headerName: "Versions",
|
|
22
|
+
width: 150,
|
|
23
|
+
valueFormatter: (value: number[]) => value && formatVersions(value),
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Default columns for genes DataGrid (flat list, no grouping)
|
|
28
|
+
*/
|
|
29
|
+
export const defaultColumns: GridColDef<GeneRowInfo>[] = [
|
|
30
|
+
displayNameCol,
|
|
31
|
+
versionsCol,
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* No grouping for genes - flat list
|
|
36
|
+
*/
|
|
37
|
+
export const defaultGroupingModel: string[] = [];
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Leaf field - the unique identifier
|
|
41
|
+
*/
|
|
42
|
+
export const defaultLeafField = "id";
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { FolderDefinition } from "../../types";
|
|
2
|
+
import { GeneDataFile, GeneRowInfo, GeneTrackInfo } from "./types";
|
|
3
|
+
import {
|
|
4
|
+
defaultColumns,
|
|
5
|
+
defaultGroupingModel,
|
|
6
|
+
defaultLeafField,
|
|
7
|
+
} from "./columns";
|
|
8
|
+
import { buildTreeView } from "./treeBuilder";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Transforms a single track from JSON into a row for DataGrid
|
|
12
|
+
* For genes, this is a 1:1 mapping (no flattening needed)
|
|
13
|
+
*/
|
|
14
|
+
function trackToRow(track: GeneTrackInfo): GeneRowInfo {
|
|
15
|
+
return {
|
|
16
|
+
id: track.id,
|
|
17
|
+
displayName: track.displayName,
|
|
18
|
+
versions: track.versions,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Transforms raw JSON data into rows and lookup map
|
|
24
|
+
*/
|
|
25
|
+
function transformData(data: GeneDataFile): {
|
|
26
|
+
rows: GeneRowInfo[];
|
|
27
|
+
rowById: Map<string, GeneRowInfo>;
|
|
28
|
+
} {
|
|
29
|
+
const rows = data.map(trackToRow);
|
|
30
|
+
const rowById = new Map<string, GeneRowInfo>(
|
|
31
|
+
rows.map((row) => [row.id, row]),
|
|
32
|
+
);
|
|
33
|
+
return { rows, rowById };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface CreateGeneFolderOptions {
|
|
37
|
+
id: string;
|
|
38
|
+
label: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
data: GeneDataFile;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Factory function that creates a FolderDefinition for genes
|
|
45
|
+
*/
|
|
46
|
+
export function createGeneFolder(
|
|
47
|
+
options: CreateGeneFolderOptions,
|
|
48
|
+
): FolderDefinition<GeneRowInfo> {
|
|
49
|
+
const { id, label, description, data } = options;
|
|
50
|
+
const { rowById } = transformData(data);
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
id,
|
|
54
|
+
label,
|
|
55
|
+
description,
|
|
56
|
+
rowById,
|
|
57
|
+
getRowId: (row) => row.id,
|
|
58
|
+
|
|
59
|
+
// Default view configuration
|
|
60
|
+
columns: defaultColumns,
|
|
61
|
+
groupingModel: defaultGroupingModel,
|
|
62
|
+
leafField: defaultLeafField,
|
|
63
|
+
|
|
64
|
+
// Tree builder for selected items panel
|
|
65
|
+
buildTree: (selectedIds, rowById) =>
|
|
66
|
+
buildTreeView(selectedIds, rowById, label),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { TreeViewBaseItem } from "@mui/x-tree-view";
|
|
2
|
+
import { ExtendedTreeItemProps } from "../../../types";
|
|
3
|
+
import { GeneRowInfo } from "./types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Builds a flat tree structure for the TreeView panel (selected items)
|
|
7
|
+
* Since genes have no grouping, this is a simple root -> leaf structure
|
|
8
|
+
*
|
|
9
|
+
* @param selectedIds - Array of selected row IDs
|
|
10
|
+
* @param rowById - Map of row ID to row data
|
|
11
|
+
* @param rootLabel - Label for the root node
|
|
12
|
+
* @returns Tree structure for RichTreeView
|
|
13
|
+
*/
|
|
14
|
+
export function buildTreeView(
|
|
15
|
+
selectedIds: string[],
|
|
16
|
+
rowById: Map<string, GeneRowInfo>,
|
|
17
|
+
rootLabel: string = "Genes",
|
|
18
|
+
): TreeViewBaseItem<ExtendedTreeItemProps>[] {
|
|
19
|
+
// Root node
|
|
20
|
+
const root: TreeViewBaseItem<ExtendedTreeItemProps> = {
|
|
21
|
+
id: "root",
|
|
22
|
+
label: rootLabel,
|
|
23
|
+
icon: "folder",
|
|
24
|
+
children: [],
|
|
25
|
+
allExpAccessions: [],
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// Get selected rows and add as direct children of root
|
|
29
|
+
selectedIds.forEach((id) => {
|
|
30
|
+
const row = rowById.get(id);
|
|
31
|
+
if (row) {
|
|
32
|
+
const leafNode: TreeViewBaseItem<ExtendedTreeItemProps> = {
|
|
33
|
+
id: row.id,
|
|
34
|
+
label: row.displayName,
|
|
35
|
+
icon: "removeable",
|
|
36
|
+
children: [],
|
|
37
|
+
allExpAccessions: [row.id],
|
|
38
|
+
};
|
|
39
|
+
root.children!.push(leafNode);
|
|
40
|
+
root.allExpAccessions!.push(row.id);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return [root];
|
|
45
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for genes folder data
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Gene track information from the JSON data
|
|
7
|
+
*/
|
|
8
|
+
export type GeneTrackInfo = {
|
|
9
|
+
/** Unique identifier for this gene track */
|
|
10
|
+
id: string;
|
|
11
|
+
/** Display name shown in the UI */
|
|
12
|
+
displayName: string;
|
|
13
|
+
/** Available versions for this gene annotation */
|
|
14
|
+
versions: number[];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Row format for DataGrid (same as track info for genes since it's flat)
|
|
19
|
+
*/
|
|
20
|
+
export type GeneRowInfo = {
|
|
21
|
+
id: string;
|
|
22
|
+
displayName: string;
|
|
23
|
+
versions: number[];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Structure of the gene JSON data files (direct array)
|
|
28
|
+
*/
|
|
29
|
+
export type GeneDataFile = GeneTrackInfo[];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Assembly, FolderDefinition } from "./types";
|
|
2
|
+
import { humanBiosamplesFolder } from "./biosamples/human";
|
|
3
|
+
import { mouseBiosamplesFolder } from "./biosamples/mouse";
|
|
4
|
+
import { humanGenesFolder } from "./genes/human";
|
|
5
|
+
import { mouseGenesFolder } from "./genes/mouse";
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
type Assembly,
|
|
9
|
+
type FolderDefinition,
|
|
10
|
+
type FolderRuntimeConfig,
|
|
11
|
+
} from "./types";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Registry of folders available for each assembly.
|
|
15
|
+
*
|
|
16
|
+
* Each assembly can have multiple folders (e.g., biosamples, genes, etc.).
|
|
17
|
+
* TrackSelect receives the folders for the current assembly and renders
|
|
18
|
+
* them as tabs or a folder selector.
|
|
19
|
+
*
|
|
20
|
+
* To add a new folder:
|
|
21
|
+
* 1. Create a folder config file (e.g., folders/genes/human.ts)
|
|
22
|
+
* 2. Import and add it to the appropriate assembly array below
|
|
23
|
+
*/
|
|
24
|
+
export const foldersByAssembly: Record<Assembly, FolderDefinition[]> = {
|
|
25
|
+
GRCh38: [humanGenesFolder, humanBiosamplesFolder],
|
|
26
|
+
mm10: [mouseGenesFolder, mouseBiosamplesFolder],
|
|
27
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { GridColDef, GridRenderCellParams } from "@mui/x-data-grid-premium";
|
|
2
|
+
import { TreeViewBaseItem } from "@mui/x-tree-view";
|
|
3
|
+
import { ExtendedTreeItemProps, CustomTreeItemProps } from "../types";
|
|
4
|
+
|
|
5
|
+
export type Assembly = "GRCh38" | "mm10";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Runtime configuration that can be modified by ToolbarExtras components.
|
|
9
|
+
* This allows folder-specific UI (like AssayToggle) to dynamically update
|
|
10
|
+
* how the DataGrid displays data.
|
|
11
|
+
*/
|
|
12
|
+
export interface FolderRuntimeConfig {
|
|
13
|
+
columns: GridColDef[];
|
|
14
|
+
groupingModel: string[];
|
|
15
|
+
leafField: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Definition for a folder in TrackSelect.
|
|
20
|
+
*
|
|
21
|
+
* A folder represents a category of data (e.g., biosamples, genes, etc.)
|
|
22
|
+
* that can be displayed in the DataGrid and TreeView. Each folder is
|
|
23
|
+
* self-contained with its own data, column definitions, and tree building logic.
|
|
24
|
+
*
|
|
25
|
+
* @template TRow - The type of row data stored in this folder
|
|
26
|
+
*/
|
|
27
|
+
export interface FolderDefinition<TRow = any> {
|
|
28
|
+
/** Unique identifier for this folder */
|
|
29
|
+
id: string;
|
|
30
|
+
|
|
31
|
+
/** Display label shown in the UI */
|
|
32
|
+
label: string;
|
|
33
|
+
|
|
34
|
+
/** Optional description shown in folder cards */
|
|
35
|
+
description?: string;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Single source of truth for all row data.
|
|
39
|
+
* Maps row ID to the full row object.
|
|
40
|
+
*/
|
|
41
|
+
rowById: Map<string, TRow>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Function to extract the unique ID from a row object.
|
|
45
|
+
* Used for selection tracking and lookups.
|
|
46
|
+
*/
|
|
47
|
+
getRowId: (row: TRow) => string;
|
|
48
|
+
|
|
49
|
+
/** Column definitions for the DataGrid */
|
|
50
|
+
columns: GridColDef[];
|
|
51
|
+
|
|
52
|
+
/** Fields to group by in the DataGrid (row grouping) */
|
|
53
|
+
groupingModel: string[];
|
|
54
|
+
|
|
55
|
+
/** The field that represents the leaf level in the grouping hierarchy */
|
|
56
|
+
leafField: string;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Builds a tree structure from selected row IDs.
|
|
60
|
+
* Used to display selected items in the TreeView panel.
|
|
61
|
+
*
|
|
62
|
+
* @param selectedIds - Array of selected row IDs
|
|
63
|
+
* @param rowById - Map of row ID to row data (same as this.rowById)
|
|
64
|
+
* @returns Array of tree items to render in the TreeView
|
|
65
|
+
*/
|
|
66
|
+
buildTree: (
|
|
67
|
+
selectedIds: string[],
|
|
68
|
+
rowById: Map<string, TRow>,
|
|
69
|
+
) => TreeViewBaseItem<ExtendedTreeItemProps>[];
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Optional component to render folder-specific toolbar controls.
|
|
73
|
+
* For example, biosamples folder uses this to render an assay toggle
|
|
74
|
+
* that switches between sample-grouped and assay-grouped views.
|
|
75
|
+
*
|
|
76
|
+
* @param updateConfig - Callback to update the folder's runtime config
|
|
77
|
+
*/
|
|
78
|
+
ToolbarExtras?: React.FC<{
|
|
79
|
+
updateConfig: (partial: Partial<FolderRuntimeConfig>) => void;
|
|
80
|
+
}>;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Optional custom component for rendering grouping cells in the DataGrid.
|
|
84
|
+
* If not provided, a default grouping cell renderer will be used.
|
|
85
|
+
*/
|
|
86
|
+
GroupingCellComponent?: React.FC<GridRenderCellParams>;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Optional custom TreeItem component for the TreeView.
|
|
90
|
+
* If not provided, the default CustomTreeItem will be used.
|
|
91
|
+
*/
|
|
92
|
+
TreeItemComponent?: React.ForwardRefExoticComponent<
|
|
93
|
+
CustomTreeItemProps & React.RefAttributes<HTMLLIElement>
|
|
94
|
+
>;
|
|
95
|
+
}
|