@datagrok/hit-triage 1.9.2 → 1.10.1
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/CHANGELOG.md +15 -0
- package/CLAUDE.md +199 -0
- package/css/hit-triage.css +0 -41
- package/dist/package-test.js +1 -1
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/files/pepTriage/campaigns/DMT-1/campaign.json +1 -0
- package/files/pepTriage/campaigns/DMT-1/enriched_table.csv +2262 -0
- package/files/pepTriage/templates/Demo Template.json +1 -0
- package/package.json +6 -4
- package/src/app/accordeons/new-campaign-accordeon.ts +24 -6
- package/src/app/accordeons/new-pep-triage-template-accordeon.ts +208 -0
- package/src/app/accordeons/new-template-accordeon.ts +15 -9
- package/src/app/consts.ts +23 -10
- package/src/app/dialogs/functions-dialog.ts +14 -221
- package/src/app/dialogs/merge-table-dialog.ts +360 -0
- package/src/app/hit-app-base.ts +4 -7
- package/src/app/hit-design-app.ts +19 -42
- package/src/app/hit-design-views/info-view.ts +17 -15
- package/src/app/hit-triage-app.ts +44 -17
- package/src/app/hit-triage-views/info-view.ts +268 -49
- package/src/app/pep-triage-app.ts +87 -0
- package/src/app/pep-triage-views/info-view.ts +123 -0
- package/src/app/types.ts +40 -66
- package/src/app/utils/calculate-single-cell.ts +20 -219
- package/src/app/utils/merge-table.ts +297 -0
- package/src/app/utils.ts +100 -123
- package/src/package-api.ts +12 -0
- package/src/package.g.ts +24 -0
- package/src/package.ts +62 -0
|
@@ -1,230 +1,23 @@
|
|
|
1
|
-
import * as DG from 'datagrok-api/dg';
|
|
2
|
-
import * as ui from 'datagrok-api/ui';
|
|
3
1
|
import * as grok from 'datagrok-api/grok';
|
|
4
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
chemFunctionsDialog as _chemFunctionsDialog,
|
|
4
|
+
} from '@datagrok-libraries/statistics/src/compute-functions/dialog';
|
|
5
5
|
import {IChemFunctionsDialogResult, IComputeDialogResult, IDescriptorTree,
|
|
6
|
-
HitTriageTemplate
|
|
7
|
-
IFunctionArgs} from '../types';
|
|
6
|
+
HitTriageTemplate} from '../types';
|
|
8
7
|
import '../../../css/hit-triage.css';
|
|
9
|
-
import {funcTypeNames, HTQueryPrefix, HTScriptPrefix} from '../consts';
|
|
10
8
|
import {HitAppBase} from '../hit-app-base';
|
|
11
|
-
import {
|
|
9
|
+
import {HTFunctionOrderingLSKey} from '../consts';
|
|
12
10
|
|
|
13
11
|
export async function chemFunctionsDialog(app: HitAppBase<any>,
|
|
14
12
|
onOk: (result: IComputeDialogResult) => void, onCancel: () => void,
|
|
15
13
|
template: Omit<HitTriageTemplate, 'dataSourceType'>, dialog?: boolean,
|
|
16
14
|
): Promise<IChemFunctionsDialogResult> {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
func: f,
|
|
27
|
-
args: template?.compute?.functions?.find((tf) =>
|
|
28
|
-
tf.name === f.name && tf.package === f.package.name)?.args ?? {}});
|
|
29
|
-
});
|
|
30
|
-
computeFunctions.scripts
|
|
31
|
-
.filter(({inputs: i}) => i.length >= 2 && i[0].propertyType === 'dataframe' && i[1].propertyType === 'column')
|
|
32
|
-
.forEach((s) => {
|
|
33
|
-
allFunctions.push({
|
|
34
|
-
func: s,
|
|
35
|
-
args: template?.compute?.scripts?.find((ts) => ts.id === s.id)?.args ?? {}});
|
|
36
|
-
});
|
|
37
|
-
computeFunctions.queries
|
|
38
|
-
.filter((q) => q.inputs.length > 0 && q.inputs[0].propertyType === 'list')// for now only lists...
|
|
39
|
-
.forEach((q) => {
|
|
40
|
-
allFunctions.push({
|
|
41
|
-
func: q,
|
|
42
|
-
args: template?.compute?.queries?.find((ts) => ts.id === q.id)?.args ?? {}});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const host = ui.div([], {classes: 'hit-triage-compute-dialog-host'});
|
|
46
|
-
const descriptorItems: DG.TreeViewNode[] = [];
|
|
47
|
-
const descriptorsGroup = ui.tree();
|
|
48
|
-
const descriptorsGroupHost = ui.wait(async () => {
|
|
49
|
-
try {
|
|
50
|
-
// tree groups
|
|
51
|
-
const descriptorsTree = (await grok.chem.descriptorsTree()) as IDescriptorTree;
|
|
52
|
-
descriptorsGroup.root.classList.add('hit-triage-compute-dialog-descriptors-group');
|
|
53
|
-
|
|
54
|
-
function createTreeGroup(name: string, treeNode: DG.TreeViewGroup): DG.TreeViewGroup {
|
|
55
|
-
const res = treeNode.group(name, null, false);
|
|
56
|
-
res.enableCheckBox(false);
|
|
57
|
-
return res;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// const descriptorsGroup = createTreeGroup('Descriptors', tree);
|
|
61
|
-
const keys = Object.keys(descriptorsTree);
|
|
62
|
-
const preselectedDescriptors: string[] = template?.compute?.descriptors?.args ?? [];
|
|
63
|
-
for (const groupName of keys) {
|
|
64
|
-
const group = createTreeGroup(groupName, descriptorsGroup);
|
|
65
|
-
|
|
66
|
-
for (const descriptor of descriptorsTree[groupName].descriptors) {
|
|
67
|
-
const item = group.item(descriptor.name, descriptor);
|
|
68
|
-
descriptorItems.push(item);
|
|
69
|
-
item.enableCheckBox(preselectedDescriptors.includes(descriptor.name));
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
return descriptorsGroup.root;
|
|
73
|
-
} catch (e) {
|
|
74
|
-
console.error(e);
|
|
75
|
-
}
|
|
76
|
-
return ui.divText('Failed to load descriptors');
|
|
77
|
-
});
|
|
78
|
-
descriptorsGroupHost.classList.add('oy-scroll');
|
|
79
|
-
|
|
80
|
-
const descriptorsName = 'Descriptors';
|
|
81
|
-
const funcNamesMap: {[key: string]: string} = {[descriptorsName]: descriptorsName};
|
|
82
|
-
// if compute is in dialog form, we need to show all the functions
|
|
83
|
-
const tabControlArgs: {[key: string]: HTMLElement} = {[descriptorsName]: descriptorsGroupHost};
|
|
84
|
-
const funcInputsMap: {[funcName: string]: DG.FuncCall} = {};
|
|
85
|
-
const calculatedFunctions: {[key: string]: boolean} = {[descriptorsName]: false};
|
|
86
|
-
calculatedFunctions[descriptorsName] =
|
|
87
|
-
!!template?.compute?.descriptors?.enabled && template?.compute?.descriptors?.args?.length > 0;
|
|
88
|
-
// handling package functions
|
|
89
|
-
for (const func of allFunctions) {
|
|
90
|
-
try {
|
|
91
|
-
const f = func.func;
|
|
92
|
-
const funcCall = f.prepare(func.args);
|
|
93
|
-
const keyName = f.type === funcTypeNames.function ?
|
|
94
|
-
`${f.package.name}:${f.name}`: f.type === funcTypeNames.script ?
|
|
95
|
-
`${HTScriptPrefix}:${f.name ?? ''}:${f.id}` : `${HTQueryPrefix}:${f.name ?? ''}:${f.id}`;
|
|
96
|
-
funcInputsMap[keyName] = funcCall;
|
|
97
|
-
const editor = ui.div();
|
|
98
|
-
ui.setUpdateIndicator(editor, true);
|
|
99
|
-
// deffered action to not wait for the editor to be built
|
|
100
|
-
funcCall.buildEditor(editor, {condensed: false}).then((inputs) => {
|
|
101
|
-
inputs?.[0]?.root && (inputs[0].root.style.display = 'none'); // table input
|
|
102
|
-
// for queries we don't have column input, we only have one input for the list of molecules
|
|
103
|
-
inputs?.[1]?.root && f.type !== funcTypeNames.query && (inputs[1].root.style.display = 'none'); // column input
|
|
104
|
-
|
|
105
|
-
inputs.forEach((input) => {
|
|
106
|
-
if (input.property?.name && Object.keys(func.args).includes(input.property?.name))
|
|
107
|
-
input.value = func.args[input.property.name];
|
|
108
|
-
input.fireChanged();
|
|
109
|
-
});
|
|
110
|
-
}).catch((e) => {
|
|
111
|
-
console.error(e);
|
|
112
|
-
ui.setUpdateIndicator(editor, false);
|
|
113
|
-
editor.appendChild(ui.divText('Failed to build function editor'));
|
|
114
|
-
}).finally(() => ui.setUpdateIndicator(editor, false));
|
|
115
|
-
editor.classList.add('oy-scroll');
|
|
116
|
-
editor.style.marginLeft = '15px';
|
|
117
|
-
editor.style.removeProperty('max-width');
|
|
118
|
-
tabControlArgs[f.friendlyName ?? f.name] = editor;
|
|
119
|
-
funcNamesMap[f.friendlyName ?? f.name] = keyName;
|
|
120
|
-
calculatedFunctions[keyName] = (template?.compute?.functions?.some(
|
|
121
|
-
(f) => func.func.type === funcTypeNames.function &&
|
|
122
|
-
f.name === func.func.name && f.package === getFuncPackageNameSafe(func.func)) ||
|
|
123
|
-
template?.compute?.scripts?.some((s) => s.id === f.id) ||
|
|
124
|
-
template?.compute?.queries?.some((s) => s.id === f.id)) ?? false;
|
|
125
|
-
} catch (e) {
|
|
126
|
-
console.error(e);
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const tc = ui.tabControl(tabControlArgs, true);
|
|
132
|
-
tc.onTabChanged.subscribe(() => {try {tc.currentPane.content.style.removeProperty('max-width');} catch (e) {}});
|
|
133
|
-
tc.header.style.overflow = 'scroll';
|
|
134
|
-
tc.root.style.width = '100%';
|
|
135
|
-
tc.root.style.minWidth = '350px';
|
|
136
|
-
host.appendChild(tc.root);
|
|
137
|
-
// add checkboxes to each hader
|
|
138
|
-
function addCheckboxesToPaneHeaders() {
|
|
139
|
-
tc.panes.forEach((pane)=> {
|
|
140
|
-
const functionCheck =
|
|
141
|
-
ui.input.bool('', {value: calculatedFunctions[funcNamesMap[pane.name]], onValueChanged: (value) => {
|
|
142
|
-
calculatedFunctions[funcNamesMap[pane.name]] = !!value;
|
|
143
|
-
if (!value)
|
|
144
|
-
$(pane.content).find('input')?.attr('disabled', 'true');
|
|
145
|
-
else
|
|
146
|
-
$(pane.content).find('input')?.removeAttr('disabled');
|
|
147
|
-
}});
|
|
148
|
-
functionCheck.setTooltip('Toggle calculation of this function');
|
|
149
|
-
pane.header.appendChild(functionCheck.root);
|
|
150
|
-
pane.header.classList.add('hit-triage-compute-dialog-pane-header');
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function initTabs(order: FunctionOrdering) {
|
|
155
|
-
tc.clear();
|
|
156
|
-
let actOrder = order.order ?? Object.keys(tabControlArgs);
|
|
157
|
-
if (actOrder.length === 0)
|
|
158
|
-
actOrder = Object.keys(tabControlArgs);
|
|
159
|
-
|
|
160
|
-
actOrder.forEach((n) => {
|
|
161
|
-
if (tabControlArgs[n])
|
|
162
|
-
tc.addPane(n, () => tabControlArgs[n]);
|
|
163
|
-
});
|
|
164
|
-
// after adding ordered panes, we also need to add new functions, not included in the order
|
|
165
|
-
Object.keys(tabControlArgs).forEach((n) => {
|
|
166
|
-
if (!actOrder.includes(n) && tabControlArgs[n] && !(order.hidden ?? []).includes(n))
|
|
167
|
-
tc.addPane(n, () => tabControlArgs[n]);
|
|
168
|
-
});
|
|
169
|
-
// make sure that hidden functions are not checked;
|
|
170
|
-
(order.hidden ?? []).forEach((n) => {
|
|
171
|
-
calculatedFunctions[funcNamesMap[n]] = false;
|
|
172
|
-
});
|
|
173
|
-
addCheckboxesToPaneHeaders();
|
|
174
|
-
if (tc.panes.length > 0)
|
|
175
|
-
tc.currentPane = tc.panes[0];
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
initTabs(getSavedFunctionOrdering());
|
|
179
|
-
function onOkProxy() {
|
|
180
|
-
const res: IComputeDialogResult = {descriptors: [], externals: {}, scripts: {}, queries: {}};
|
|
181
|
-
res.descriptors = calculatedFunctions[descriptorsName] ?
|
|
182
|
-
descriptorItems.filter((i) => i.checked).map((i) => i.value.name) : [];
|
|
183
|
-
const filteredFuncs = Object.entries(funcInputsMap).filter(([name, _]) => calculatedFunctions[name]);
|
|
184
|
-
// handling package functions
|
|
185
|
-
filteredFuncs.filter(([name, _]) => !name.startsWith(HTScriptPrefix) && !name.startsWith(HTQueryPrefix))
|
|
186
|
-
.forEach(([name, value]) => {
|
|
187
|
-
res.externals[name] = {};
|
|
188
|
-
const inputs = value.inputs;
|
|
189
|
-
Object.entries(inputs).slice(2).forEach(([inputName, inputVal]) => {
|
|
190
|
-
res.externals[name][inputName] = inputVal;
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
// handling scripts
|
|
194
|
-
filteredFuncs.filter(([name, _]) => name.startsWith(HTScriptPrefix))
|
|
195
|
-
.forEach(([name, value]) => {
|
|
196
|
-
res.scripts![name] = {};
|
|
197
|
-
const inputs = value.inputs;
|
|
198
|
-
Object.entries(inputs).slice(2).forEach(([inputName, inputVal]) => {
|
|
199
|
-
res.scripts![name][inputName] = inputVal;
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
// handling queries
|
|
203
|
-
filteredFuncs.filter(([name, _]) => name.startsWith(HTQueryPrefix))
|
|
204
|
-
.forEach(([name, value]) => {
|
|
205
|
-
res.queries![name] = {};
|
|
206
|
-
const inputs = value.inputs;
|
|
207
|
-
Object.entries(inputs).slice(1).forEach(([inputName, inputVal]) => {
|
|
208
|
-
res.queries![name][inputName] = inputVal;
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
console.log(res);
|
|
212
|
-
onOk(res);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
tc.root.appendChild(getReorderingInput(Object.keys(tabControlArgs), (newOrder) => {
|
|
216
|
-
initTabs(newOrder);
|
|
217
|
-
}));
|
|
218
|
-
if (dialog) {
|
|
219
|
-
ui.dialog('Compute')
|
|
220
|
-
.add(host)
|
|
221
|
-
.onOK(() => onOkProxy())
|
|
222
|
-
.onCancel(onCancel)
|
|
223
|
-
.show({resizable: true});
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return {
|
|
227
|
-
root: host,
|
|
228
|
-
okProxy: onOkProxy,
|
|
229
|
-
};
|
|
230
|
-
};
|
|
15
|
+
return _chemFunctionsDialog(
|
|
16
|
+
app.computeFunctions,
|
|
17
|
+
onOk, onCancel,
|
|
18
|
+
template,
|
|
19
|
+
dialog,
|
|
20
|
+
() => grok.chem.descriptorsTree() as Promise<IDescriptorTree>,
|
|
21
|
+
HTFunctionOrderingLSKey,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
import * as DG from 'datagrok-api/dg';
|
|
3
|
+
import * as ui from 'datagrok-api/ui';
|
|
4
|
+
import * as grok from 'datagrok-api/grok';
|
|
5
|
+
import {HitDesignApp} from '../hit-design-app';
|
|
6
|
+
import {HitAppBase} from '../hit-app-base';
|
|
7
|
+
import {HitDesignMergeClashStrategy, HitDesignMergeConfig, HitDesignMergeMode} from '../types';
|
|
8
|
+
import {guessMoleculeColumn, guessVidColumn, isLocalUploadFileInfo, mergeIntoCampaign} from '../utils/merge-table';
|
|
9
|
+
import {_package} from '../../package';
|
|
10
|
+
|
|
11
|
+
// Mirrors the drag-n-drop path in HitDesignApp.handleUploadingDataframe: csv goes through
|
|
12
|
+
// DG.DataFrame.fromCsv, anything else is delegated to a registered file-handler function.
|
|
13
|
+
// HitAppBase.molFileExtReaders is statically filtered to only those extensions for which
|
|
14
|
+
// the platform actually exposes a reader, so this list reflects what we can really parse.
|
|
15
|
+
const ALLOWED_EXTENSIONS: string[] = ['csv', ...HitAppBase.molFileExtReaders.map((r) => r.ext)];
|
|
16
|
+
|
|
17
|
+
function getExtension(fi: DG.FileInfo): string {
|
|
18
|
+
const ext = fi.extension?.toLowerCase();
|
|
19
|
+
if (ext) return ext;
|
|
20
|
+
const name = fi.name?.toLowerCase() ?? '';
|
|
21
|
+
const dot = name.lastIndexOf('.');
|
|
22
|
+
return dot >= 0 ? name.slice(dot + 1) : '';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function readFileInfoToDataFrame(fi: DG.FileInfo): Promise<DG.DataFrame | null> {
|
|
26
|
+
const ext = getExtension(fi);
|
|
27
|
+
if (ext === 'csv') {
|
|
28
|
+
const text = await fi.readAsString();
|
|
29
|
+
return DG.DataFrame.fromCsv(text);
|
|
30
|
+
}
|
|
31
|
+
const reader = HitAppBase.molFileExtReaders.find((r) => r.ext === ext);
|
|
32
|
+
if (!reader) return null;
|
|
33
|
+
const bytes = await fi.readAsBytes();
|
|
34
|
+
if (!bytes) return null;
|
|
35
|
+
const bytesArg = reader.handlerFunc.inputs[0].name;
|
|
36
|
+
const result: any = await reader.handlerFunc.apply({[bytesArg]: bytes});
|
|
37
|
+
return Array.isArray(result) ? result[0] : result;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const MODE_LABELS: Record<HitDesignMergeMode, string> = {
|
|
41
|
+
smiles: 'By canonical SMILES',
|
|
42
|
+
vid: 'By V-iD',
|
|
43
|
+
};
|
|
44
|
+
const CLASH_LABELS: Record<HitDesignMergeClashStrategy, string> = {
|
|
45
|
+
skip: 'Skip (keep campaign value)',
|
|
46
|
+
overwrite: 'Overwrite (use incoming value)',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const NONE_OPTION = '(none)';
|
|
50
|
+
|
|
51
|
+
function setChoiceItems(input: DG.InputBase<string | null>, items: string[], desired?: string | null): void {
|
|
52
|
+
(input as unknown as DG.ChoiceInput<string>).items = items;
|
|
53
|
+
if (desired != null && items.includes(desired))
|
|
54
|
+
input.value = desired;
|
|
55
|
+
else if (items.length > 0)
|
|
56
|
+
input.value = items[0];
|
|
57
|
+
else
|
|
58
|
+
input.value = null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function openMergeTableDialog<T extends HitDesignApp>(app: T): Promise<void> {
|
|
62
|
+
if (!app.dataFrame) {
|
|
63
|
+
grok.shell.error('Cannot merge: campaign has no data.');
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const saved: HitDesignMergeConfig | undefined = app.campaign?.mergeConfig;
|
|
67
|
+
|
|
68
|
+
// Mutable dialog state
|
|
69
|
+
let incomingDf: DG.DataFrame | null = null;
|
|
70
|
+
let isLoadingFile = false;
|
|
71
|
+
// Re-entrancy guard — onValueChanged on the file input fires for both user actions and
|
|
72
|
+
// programmatic resets. We only want the validate-then-load behavior on user actions.
|
|
73
|
+
let suppressFileChange = false;
|
|
74
|
+
|
|
75
|
+
// ---- Inputs ----
|
|
76
|
+
const fileInput = ui.input.file('Source file', {
|
|
77
|
+
nullable: true,
|
|
78
|
+
tooltipText: `Pick a file from your computer or from a Datagrok file share.\n` +
|
|
79
|
+
`Allowed extensions: ${ALLOWED_EXTENSIONS.join(', ')}.\n` +
|
|
80
|
+
`Files picked from a share are remembered with the campaign and reloaded automatically next time.`,
|
|
81
|
+
onValueChanged: (v) => onFileChanged(v),
|
|
82
|
+
});
|
|
83
|
+
fileInput.input.setAttribute('placeholder', `Drop file or pick from share — ${ALLOWED_EXTENSIONS.join(', ')}`);
|
|
84
|
+
|
|
85
|
+
const modeInput = ui.input.choice<string>('Merge by', {
|
|
86
|
+
items: Object.values(MODE_LABELS),
|
|
87
|
+
value: MODE_LABELS[saved?.mode ?? 'vid'],
|
|
88
|
+
nullable: false,
|
|
89
|
+
tooltipText: 'Join key. "Canonical SMILES" matches by canonicalized molecule structure; ' +
|
|
90
|
+
'"V-iD" matches by the campaign\'s V-iD identifier.',
|
|
91
|
+
onValueChanged: () => runValidation(),
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const molColInput = ui.input.choice<string>('Molecule column (incoming)', {
|
|
95
|
+
items: [],
|
|
96
|
+
value: null as unknown as string,
|
|
97
|
+
nullable: true,
|
|
98
|
+
tooltipText: 'Column in the incoming table holding the molecules. ' +
|
|
99
|
+
'Required for SMILES merge. In V-iD merge it is optional — if set, ' +
|
|
100
|
+
'unmatched rows can be added to the campaign and registered with new V-iDs.',
|
|
101
|
+
onValueChanged: () => runValidation(),
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const vidColInput = ui.input.choice<string>('V-iD column (incoming)', {
|
|
105
|
+
items: [],
|
|
106
|
+
value: null as unknown as string,
|
|
107
|
+
nullable: true,
|
|
108
|
+
tooltipText: 'Column in the incoming table holding V-iD strings. Used as the join key when merging by V-iD.',
|
|
109
|
+
onValueChanged: () => runValidation(),
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const addRowsInput = ui.input.bool('Add unmatched rows', {
|
|
113
|
+
value: saved?.addNewRows ?? true,
|
|
114
|
+
tooltipText: 'When on, rows from the incoming table whose key is not present in the campaign are added as new rows. ' +
|
|
115
|
+
'When off, only existing rows are updated. ' +
|
|
116
|
+
'Disabled when no incoming molecule column is selected (nothing to register the new row with).',
|
|
117
|
+
onValueChanged: () => runValidation(),
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const runComputeInput = ui.input.bool('Run compute on new rows', {
|
|
121
|
+
value: saved?.runComputeOnNewRows ?? true,
|
|
122
|
+
tooltipText: 'Run the campaign\'s compute pipeline (descriptors, functions, scripts, queries) on the incoming molecules ' +
|
|
123
|
+
'so new rows arrive with all calculated columns filled in. Disabled when no rows will be added.',
|
|
124
|
+
onValueChanged: () => runValidation(),
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const clashInput = ui.input.choice<string>('On clashing data', {
|
|
128
|
+
items: Object.values(CLASH_LABELS),
|
|
129
|
+
value: CLASH_LABELS[saved?.clashStrategy ?? 'overwrite'],
|
|
130
|
+
nullable: false,
|
|
131
|
+
tooltipText: 'How to resolve cells that have a value on both sides for a matched row. ' +
|
|
132
|
+
'"Skip" keeps the existing campaign value; "Overwrite" replaces it with the incoming value. ' +
|
|
133
|
+
'Empty campaign cells are always filled from the incoming table regardless of this setting.',
|
|
134
|
+
onValueChanged: () => runValidation(),
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const errorDiv = ui.divText('');
|
|
138
|
+
errorDiv.style.color = 'var(--failure)';
|
|
139
|
+
errorDiv.style.fontSize = '12px';
|
|
140
|
+
errorDiv.style.marginTop = '8px';
|
|
141
|
+
errorDiv.style.minHeight = '16px';
|
|
142
|
+
|
|
143
|
+
const inputsRoot = ui.divV([
|
|
144
|
+
fileInput.root,
|
|
145
|
+
modeInput.root,
|
|
146
|
+
molColInput.root,
|
|
147
|
+
vidColInput.root,
|
|
148
|
+
addRowsInput.root,
|
|
149
|
+
runComputeInput.root,
|
|
150
|
+
clashInput.root,
|
|
151
|
+
errorDiv,
|
|
152
|
+
]);
|
|
153
|
+
inputsRoot.style.minWidth = '420px';
|
|
154
|
+
|
|
155
|
+
// ---- Helpers reading current input state ----
|
|
156
|
+
const labelToMode = (label: string | null): HitDesignMergeMode =>
|
|
157
|
+
label === MODE_LABELS.vid ? 'vid' : 'smiles';
|
|
158
|
+
const labelToClash = (label: string | null): HitDesignMergeClashStrategy =>
|
|
159
|
+
label === CLASH_LABELS.overwrite ? 'overwrite' : 'skip';
|
|
160
|
+
const colChoiceValue = (input: DG.InputBase<string | null>): string | undefined => {
|
|
161
|
+
const v = input.value;
|
|
162
|
+
return v && v !== NONE_OPTION ? v : undefined;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// ---- Core validation / state machine ----
|
|
166
|
+
function runValidation(): void {
|
|
167
|
+
const mode = labelToMode(modeInput.value);
|
|
168
|
+
const fileLoaded = !!incomingDf && !isLoadingFile;
|
|
169
|
+
|
|
170
|
+
// Block / unblock inputs based on availability of incoming data + selected mode.
|
|
171
|
+
modeInput.enabled = fileLoaded;
|
|
172
|
+
molColInput.enabled = fileLoaded;
|
|
173
|
+
vidColInput.enabled = fileLoaded && mode === 'vid';
|
|
174
|
+
clashInput.enabled = fileLoaded;
|
|
175
|
+
|
|
176
|
+
const molCol = colChoiceValue(molColInput);
|
|
177
|
+
const vidCol = colChoiceValue(vidColInput);
|
|
178
|
+
|
|
179
|
+
// Disable downstream toggles when their precondition isn't met, but DON'T clobber the
|
|
180
|
+
// user's chosen value — the OK handler only honors them when they're effective, so the
|
|
181
|
+
// value sticks across input changes (e.g. the user briefly unsets the molecule column).
|
|
182
|
+
const canChooseAddRows = fileLoaded && !!molCol;
|
|
183
|
+
addRowsInput.enabled = canChooseAddRows;
|
|
184
|
+
|
|
185
|
+
const canRunCompute = canChooseAddRows && addRowsInput.value === true;
|
|
186
|
+
runComputeInput.enabled = canRunCompute;
|
|
187
|
+
|
|
188
|
+
let errorMessage = '';
|
|
189
|
+
if (isLoadingFile)
|
|
190
|
+
errorMessage = 'Reading file…';
|
|
191
|
+
else if (!fileLoaded)
|
|
192
|
+
errorMessage = 'Pick a source file to merge from.';
|
|
193
|
+
else if (mode === 'smiles' && !molCol)
|
|
194
|
+
errorMessage = 'Pick the molecule column from the incoming table.';
|
|
195
|
+
else if (mode === 'vid' && !vidCol)
|
|
196
|
+
errorMessage = 'Pick the V-iD column from the incoming table.';
|
|
197
|
+
|
|
198
|
+
errorDiv.textContent = errorMessage;
|
|
199
|
+
setOkEnabled(errorMessage === '');
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// ---- File loading ----
|
|
203
|
+
async function loadAndApplyFile(fi: DG.FileInfo, savedToApply: HitDesignMergeConfig | null): Promise<void> {
|
|
204
|
+
isLoadingFile = true;
|
|
205
|
+
incomingDf = null;
|
|
206
|
+
runValidation();
|
|
207
|
+
ui.setUpdateIndicator(inputsRoot, true, 'Reading file...');
|
|
208
|
+
try {
|
|
209
|
+
const df = await readFileInfoToDataFrame(fi);
|
|
210
|
+
if (!df) throw new Error('Empty result');
|
|
211
|
+
df.name = (fi.name ?? '').replace(/\.[^.]+$/, '');
|
|
212
|
+
await df.meta.detectSemanticTypes();
|
|
213
|
+
await grok.data.detectSemanticTypes(df);
|
|
214
|
+
incomingDf = df;
|
|
215
|
+
} catch (e) {
|
|
216
|
+
_package.logger.error(e);
|
|
217
|
+
grok.shell.error(`Failed to read "${fi.name}". Check that the file is accessible and well-formed.`);
|
|
218
|
+
incomingDf = null;
|
|
219
|
+
} finally {
|
|
220
|
+
ui.setUpdateIndicator(inputsRoot, false);
|
|
221
|
+
isLoadingFile = false;
|
|
222
|
+
}
|
|
223
|
+
populateColumnChoices(savedToApply);
|
|
224
|
+
if (savedToApply)
|
|
225
|
+
applySavedScalarChoices(savedToApply);
|
|
226
|
+
runValidation();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function populateColumnChoices(savedToApply: HitDesignMergeConfig | null): void {
|
|
230
|
+
if (!incomingDf) {
|
|
231
|
+
setChoiceItems(molColInput, []);
|
|
232
|
+
setChoiceItems(vidColInput, []);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const colNames = incomingDf.columns.toList().map((c) => c.name);
|
|
236
|
+
|
|
237
|
+
const molDesired = savedToApply?.molColName ?? guessMoleculeColumn(incomingDf)?.name ?? null;
|
|
238
|
+
const molItems = [NONE_OPTION, ...colNames];
|
|
239
|
+
setChoiceItems(molColInput, molItems, molDesired ?? NONE_OPTION);
|
|
240
|
+
|
|
241
|
+
const vidDesired = savedToApply?.vidColName ?? guessVidColumn(incomingDf)?.name ?? null;
|
|
242
|
+
const vidItems = [NONE_OPTION, ...colNames];
|
|
243
|
+
setChoiceItems(vidColInput, vidItems, vidDesired ?? NONE_OPTION);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function applySavedScalarChoices(savedToApply: HitDesignMergeConfig): void {
|
|
247
|
+
modeInput.value = MODE_LABELS[savedToApply.mode];
|
|
248
|
+
addRowsInput.value = savedToApply.addNewRows;
|
|
249
|
+
runComputeInput.value = savedToApply.runComputeOnNewRows;
|
|
250
|
+
clashInput.value = CLASH_LABELS[savedToApply.clashStrategy];
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async function onFileChanged(fi: DG.FileInfo | null): Promise<void> {
|
|
254
|
+
if (suppressFileChange) return;
|
|
255
|
+
|
|
256
|
+
if (!fi) {
|
|
257
|
+
incomingDf = null;
|
|
258
|
+
populateColumnChoices(null);
|
|
259
|
+
runValidation();
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const ext = getExtension(fi);
|
|
263
|
+
if (!ALLOWED_EXTENSIONS.includes(ext as typeof ALLOWED_EXTENSIONS[number])) {
|
|
264
|
+
// Defer the clear to break the change → handler → change loop, and to make sure
|
|
265
|
+
// we see the user's actual selection before reverting.
|
|
266
|
+
setTimeout(() => {
|
|
267
|
+
suppressFileChange = true;
|
|
268
|
+
try {
|
|
269
|
+
fileInput.value = null;
|
|
270
|
+
} finally {
|
|
271
|
+
suppressFileChange = false;
|
|
272
|
+
}
|
|
273
|
+
runValidation();
|
|
274
|
+
}, 0);
|
|
275
|
+
grok.shell.warning(`Unsupported file type ".${ext || '?'}". Allowed: ${ALLOWED_EXTENSIONS.join(', ')}.`);
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
await loadAndApplyFile(fi, null);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// ---- Dialog ----
|
|
282
|
+
const dialog = ui.dialog('Merge with table');
|
|
283
|
+
dialog.add(inputsRoot);
|
|
284
|
+
dialog.onOK(async () => {
|
|
285
|
+
await onOk();
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
function setOkEnabled(enabled: boolean): void {
|
|
289
|
+
const okBtn = dialog.getButton('OK');
|
|
290
|
+
if (!okBtn) return;
|
|
291
|
+
if (enabled) {
|
|
292
|
+
okBtn.removeAttribute('disabled');
|
|
293
|
+
okBtn.classList.remove('disabled');
|
|
294
|
+
} else {
|
|
295
|
+
okBtn.setAttribute('disabled', 'true');
|
|
296
|
+
okBtn.classList.add('disabled');
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
async function onOk(): Promise<void> {
|
|
301
|
+
if (!incomingDf) return;
|
|
302
|
+
const mode = labelToMode(modeInput.value);
|
|
303
|
+
const molCol = colChoiceValue(molColInput);
|
|
304
|
+
const vidCol = colChoiceValue(vidColInput);
|
|
305
|
+
const fi = fileInput.value;
|
|
306
|
+
const filePath = fi && !isLocalUploadFileInfo(fi) ? fi.fullPath : undefined;
|
|
307
|
+
|
|
308
|
+
const cfg: HitDesignMergeConfig = {
|
|
309
|
+
mode,
|
|
310
|
+
filePath,
|
|
311
|
+
molColName: molCol,
|
|
312
|
+
vidColName: mode === 'vid' ? vidCol : undefined,
|
|
313
|
+
addNewRows: !!addRowsInput.value && !!molCol,
|
|
314
|
+
runComputeOnNewRows: !!runComputeInput.value && !!addRowsInput.value && !!molCol,
|
|
315
|
+
clashStrategy: labelToClash(clashInput.value),
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const pg = DG.TaskBarProgressIndicator.create('Merging table into campaign...');
|
|
319
|
+
try {
|
|
320
|
+
await mergeIntoCampaign(app, incomingDf, cfg);
|
|
321
|
+
if (app.campaign) {
|
|
322
|
+
app.campaign.mergeConfig = cfg;
|
|
323
|
+
await app.saveCampaign(false);
|
|
324
|
+
}
|
|
325
|
+
grok.shell.info('Table merged into campaign.');
|
|
326
|
+
} catch (e) {
|
|
327
|
+
_package.logger.error(e);
|
|
328
|
+
grok.shell.error('Merge failed. See console for details.');
|
|
329
|
+
} finally {
|
|
330
|
+
pg.close();
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
dialog.show();
|
|
335
|
+
// Initial state: nothing loaded yet, all dependent inputs disabled.
|
|
336
|
+
runValidation();
|
|
337
|
+
|
|
338
|
+
// If the campaign already has a remembered file path, try to recreate the FileInfo and
|
|
339
|
+
// walk through the same load → restore flow as a fresh user pick would.
|
|
340
|
+
if (saved?.filePath) {
|
|
341
|
+
try {
|
|
342
|
+
const exists = await grok.dapi.files.exists(saved.filePath);
|
|
343
|
+
if (!exists)
|
|
344
|
+
grok.shell.warning(`Saved merge file not found or not accessible: ${saved.filePath}`);
|
|
345
|
+
else {
|
|
346
|
+
const restoredFi = DG.FileInfo.fromString(saved.filePath, '');
|
|
347
|
+
suppressFileChange = true;
|
|
348
|
+
try {
|
|
349
|
+
fileInput.value = restoredFi;
|
|
350
|
+
} finally {
|
|
351
|
+
suppressFileChange = false;
|
|
352
|
+
}
|
|
353
|
+
await loadAndApplyFile(restoredFi, saved);
|
|
354
|
+
}
|
|
355
|
+
} catch (e) {
|
|
356
|
+
_package.logger.error(e);
|
|
357
|
+
grok.shell.warning('Could not restore previously saved merge file.');
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
package/src/app/hit-app-base.ts
CHANGED
|
@@ -4,7 +4,8 @@ import * as ui from 'datagrok-api/ui';
|
|
|
4
4
|
import * as DG from 'datagrok-api/dg';
|
|
5
5
|
import {_package} from '../package';
|
|
6
6
|
import {AppName, ComputeFunctions, HitDesignCampaign, HitTriageCampaign} from './types';
|
|
7
|
-
import {
|
|
7
|
+
import {HitTriageComputeFunctionTag, ViDColName} from './consts';
|
|
8
|
+
import {discoverComputeFunctions} from '@datagrok-libraries/statistics/src/compute-functions/discovery';
|
|
8
9
|
import {checkEditPermissions} from './utils';
|
|
9
10
|
import * as api from '../package-api';
|
|
10
11
|
|
|
@@ -13,7 +14,7 @@ export abstract class HitAppBase<T> {
|
|
|
13
14
|
public template?: T;
|
|
14
15
|
public baseUrl!: string;
|
|
15
16
|
public computeFunctions: ComputeFunctions;
|
|
16
|
-
|
|
17
|
+
public isJoining = false;
|
|
17
18
|
protected hasEditPermission = false;
|
|
18
19
|
private _appName: AppName;
|
|
19
20
|
public get appName(): AppName {return this._appName;}
|
|
@@ -30,11 +31,7 @@ export abstract class HitAppBase<T> {
|
|
|
30
31
|
constructor(public parentCall: DG.FuncCall, appN: AppName) {
|
|
31
32
|
this.baseUrl = new URL(window.location.href).origin + `/apps/HitTriage/${appN.replace(' ', '')}`;
|
|
32
33
|
this._appName = appN;
|
|
33
|
-
|
|
34
|
-
const functions = funcs.filter((f) => f.type === funcTypeNames.function);
|
|
35
|
-
const scripts = funcs.filter((f) => f.type === funcTypeNames.script) as DG.Script[];
|
|
36
|
-
const queries = funcs.filter((f) => f.type === funcTypeNames.query) as DG.DataQuery[];
|
|
37
|
-
this.computeFunctions = {functions, scripts, queries};
|
|
34
|
+
this.computeFunctions = discoverComputeFunctions(HitTriageComputeFunctionTag);
|
|
38
35
|
|
|
39
36
|
// this.layouts = new Promise<DG.ViewLayout[]>(async (resolve) => {
|
|
40
37
|
// // we need all layouts, as applicable ones might not be enaugh
|