@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,26 +1,39 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
1
2
|
import * as grok from 'datagrok-api/grok';
|
|
2
3
|
import * as ui from 'datagrok-api/ui';
|
|
3
4
|
import * as DG from 'datagrok-api/dg';
|
|
4
5
|
import {HitTriageApp} from '../hit-triage-app';
|
|
5
6
|
import {_package} from '../../package';
|
|
6
7
|
import {HitTriageTemplate} from '../types';
|
|
7
|
-
import {CampaignIdKey, CampaignJsonName,
|
|
8
|
+
import {CampaignIdKey, CampaignJsonName, CampaignGrouping, CampaignGroupingType,
|
|
9
|
+
HTCampaignTableColumns, HTDefaultCampaignTableInfoGetters, HitTriageDataSourceTag, i18n} from '../consts';
|
|
8
10
|
import {HitTriageCampaign} from '../types';
|
|
9
11
|
import '../../../css/hit-triage.css';
|
|
10
|
-
import {addBreadCrumbsToRibbons, checkEditPermissions, checkViewPermissions,
|
|
12
|
+
import {addBreadCrumbsToRibbons, checkEditPermissions, checkViewPermissions,
|
|
13
|
+
getGroupedCampaigns, getHTSavedCampaignsGrouping, getHTSavedCampaignsSorting,
|
|
14
|
+
getHTSavedCampaignTableColumns, loadTemplate, modifyUrl, popRibbonPannels,
|
|
15
|
+
processGroupingTable, setHTSavedCampaignsGrouping, setHTSavedCampaignsSorting,
|
|
16
|
+
setHTSavedCampaignTableColumns, sortCampaigns,
|
|
17
|
+
HTSavedCampaignsTableSorting} from '../utils';
|
|
11
18
|
import {newCampaignAccordeon} from '../accordeons/new-campaign-accordeon';
|
|
12
19
|
import $ from 'cash-dom';
|
|
13
20
|
import {createTemplateAccordeon} from '../accordeons/new-template-accordeon';
|
|
14
21
|
import {HitBaseView} from '../base-view';
|
|
15
22
|
import {u2} from '@datagrok-libraries/utils/src/u2';
|
|
16
|
-
import {defaultPermissions} from '../dialogs/permissions-dialog';
|
|
23
|
+
import {defaultPermissions, PermissionsDialog} from '../dialogs/permissions-dialog';
|
|
17
24
|
|
|
18
25
|
export class InfoView extends HitBaseView<HitTriageTemplate, HitTriageApp> {
|
|
19
26
|
public readmePath = _package.webRoot + 'README_HT.md';
|
|
20
27
|
private dataSourceFunctionsMap: {[key: string]: DG.Func | DG.DataQuery} = {};
|
|
28
|
+
currentGroupping: string = 'None';
|
|
29
|
+
protected _appHeader: HTMLElement | null = null;
|
|
30
|
+
protected _contentRoot: HTMLElement = ui.div([], {classes: 'hit-triage-info-view-container'});
|
|
21
31
|
constructor(app: HitTriageApp) {
|
|
22
32
|
super(app);
|
|
23
33
|
this.name = 'Hit Triage';
|
|
34
|
+
this._appHeader = this.getAppHeader();
|
|
35
|
+
this.root.appendChild(ui.div([this._appHeader], {style: {marginLeft: '10px'}}));
|
|
36
|
+
this.root.appendChild(this._contentRoot);
|
|
24
37
|
grok.shell.windows.showHelp = true;
|
|
25
38
|
grok.shell.windows.help.showHelp(this.readmePath);
|
|
26
39
|
this.checkCampaign().then((c) => {this.app.campaign = c; this.init();});
|
|
@@ -31,35 +44,150 @@ export class InfoView extends HitBaseView<HitTriageTemplate, HitTriageApp> {
|
|
|
31
44
|
grok.shell.windows.help.showHelp(this.readmePath);
|
|
32
45
|
}
|
|
33
46
|
|
|
47
|
+
protected campaignsTableRoot: HTMLElement | null = null;
|
|
48
|
+
|
|
49
|
+
protected async refreshCampaignsTable() {
|
|
50
|
+
if (this.campaignsTableRoot == null)
|
|
51
|
+
return;
|
|
52
|
+
ui.setUpdateIndicator(this.campaignsTableRoot, true);
|
|
53
|
+
try {
|
|
54
|
+
const t = await this.getCampaignsTable();
|
|
55
|
+
ui.setUpdateIndicator(this.campaignsTableRoot, false);
|
|
56
|
+
ui.empty(this.campaignsTableRoot);
|
|
57
|
+
this.campaignsTableRoot.appendChild(t);
|
|
58
|
+
} catch (e) {
|
|
59
|
+
grok.shell.error('Failed to update campaigns table');
|
|
60
|
+
console.error(e);
|
|
61
|
+
} finally {
|
|
62
|
+
ui.setUpdateIndicator(this.campaignsTableRoot, false);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
protected getAppHeader() {
|
|
67
|
+
return u2.appHeader({
|
|
68
|
+
iconPath: _package.webRoot + '/images/icons/hit-triage-icon.png',
|
|
69
|
+
learnMoreUrl: 'https://github.com/datagrok-ai/public/blob/master/packages/HitTriage/README_HT.md',
|
|
70
|
+
description: '- Configure your own workflow using the template editor.\n'+
|
|
71
|
+
'- Calculate different molecular properties.\n'+
|
|
72
|
+
'- Filter molecules using different criteria.\n'+
|
|
73
|
+
'- Submit processed dataframe to the function of your choice.\n'+
|
|
74
|
+
'- Save campaigns and continue any time from where you left off.\n ',
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
protected getTemplatesFolder(): string {
|
|
79
|
+
return `${this.app.appName}/templates`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
protected getDataSourceTag(): string {
|
|
83
|
+
return HitTriageDataSourceTag;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
protected getDataSourceFunctionsMap(): {[key: string]: DG.Func | DG.DataQuery} {
|
|
87
|
+
return this.dataSourceFunctionsMap;
|
|
88
|
+
}
|
|
89
|
+
|
|
34
90
|
async init(presetTemplate?: HitTriageTemplate): Promise<void> {
|
|
35
91
|
ui.setUpdateIndicator(this.root, true);
|
|
36
92
|
try {
|
|
37
93
|
const continueCampaignsHeader = ui.h1(i18n.continueCampaigns);
|
|
38
94
|
const createNewCampaignHeader = ui.h1(i18n.createNewCampaignHeader, {style: {marginLeft: '10px'}});
|
|
39
|
-
const appHeader = u2.appHeader({
|
|
40
|
-
iconPath: _package.webRoot + '/images/icons/hit-triage-icon.png',
|
|
41
|
-
learnMoreUrl: 'https://github.com/datagrok-ai/public/blob/master/packages/HitTriage/README_HT.md',
|
|
42
|
-
description: '- Configure your own workflow using the template editor.\n'+
|
|
43
|
-
'- Calculate different molecular properties.\n'+
|
|
44
|
-
'- Filter molecules using different criteria.\n'+
|
|
45
|
-
'- Submit processed dataframe to the function of your choice.\n'+
|
|
46
|
-
'- Save campaigns and continue any time from where you left off.\n ',
|
|
47
|
-
});
|
|
48
95
|
|
|
49
96
|
const campaignAccordionDiv = ui.div();
|
|
50
97
|
const templatesDiv = ui.div([], {classes: 'ui-form'});
|
|
51
98
|
|
|
52
99
|
const campaignsTable = await this.getCampaignsTable();
|
|
100
|
+
this.campaignsTableRoot = ui.div([campaignsTable], {style: {position: 'relative'}});
|
|
101
|
+
|
|
102
|
+
// grouping via different campaign properties
|
|
103
|
+
const groupIcon = ui.iconFA('layer-group', async () => {
|
|
104
|
+
const menu = DG.Menu.popup();
|
|
105
|
+
Object.values(CampaignGrouping).forEach((i) => {
|
|
106
|
+
menu.item(i, async () => {
|
|
107
|
+
setHTSavedCampaignsGrouping(i as CampaignGroupingType);
|
|
108
|
+
await this.refreshCampaignsTable();
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
const campaignFieldsGroup = menu.group('Campaign Fields');
|
|
112
|
+
const campaignNamesMap = await _package.loadCampaigns(this.app.appName, this.deletedCampaigns);
|
|
113
|
+
const customFields = new Set<string>();
|
|
114
|
+
Object.values(campaignNamesMap).forEach((c) => {
|
|
115
|
+
if (c.campaignFields)
|
|
116
|
+
Object.keys(c.campaignFields).forEach((field) => customFields.add(field));
|
|
117
|
+
});
|
|
118
|
+
Array.from(customFields).forEach((field) => {
|
|
119
|
+
campaignFieldsGroup.item(field, async () => {
|
|
120
|
+
setHTSavedCampaignsGrouping(`campaignFields.${field}`);
|
|
121
|
+
await this.refreshCampaignsTable();
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
menu.show({element: sortingHeader, x: 120, y: sortingHeader.offsetTop + 30});
|
|
126
|
+
}, 'Group by');
|
|
127
|
+
groupIcon.style.marginBottom = '9px';
|
|
128
|
+
groupIcon.style.marginLeft = '8px';
|
|
129
|
+
groupIcon.style.fontSize = '15px';
|
|
130
|
+
groupIcon.style.color = 'var(--blue-1)';
|
|
131
|
+
ui.tooltip.bind(groupIcon, () => `Group Campaigns. Current: ${this.currentGroupping}`);
|
|
132
|
+
|
|
133
|
+
const editColumnsIcon = ui.iconFA('eye', async () => {
|
|
134
|
+
const menu = DG.Menu.popup();
|
|
135
|
+
const campaignNamesMap = await _package.loadCampaigns(this.app.appName, this.deletedCampaigns);
|
|
136
|
+
const getters: {[key in HTCampaignTableColumns]: (a: HitTriageCampaign) => string} = {...HTDefaultCampaignTableInfoGetters};
|
|
137
|
+
// remove Name as it is always present
|
|
138
|
+
// @ts-ignore
|
|
139
|
+
delete getters['Name'];
|
|
140
|
+
Object.values(campaignNamesMap).forEach((c) => {
|
|
141
|
+
if (c.campaignFields) {
|
|
142
|
+
Object.keys(c.campaignFields).forEach((field) => {
|
|
143
|
+
getters[`campaignFields.${field}`] = (a) => a.campaignFields?.[field] ?? '';
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
const savedColumns = getHTSavedCampaignTableColumns().reduce((acc: {[code in HTCampaignTableColumns]: boolean}, col) => {acc[col] = true; return acc;}, {} as any);
|
|
148
|
+
// first add the main columns
|
|
149
|
+
Object.keys(getters).filter((g) => !g.startsWith('campaignFields.')).forEach((col) => {
|
|
150
|
+
menu.item(col, () => {
|
|
151
|
+
savedColumns[col as HTCampaignTableColumns] = !savedColumns[col as HTCampaignTableColumns];
|
|
152
|
+
setHTSavedCampaignTableColumns(Object.keys(savedColumns).filter((c) => savedColumns[c as HTCampaignTableColumns]) as HTCampaignTableColumns[]);
|
|
153
|
+
this.refreshCampaignsTable();
|
|
154
|
+
}, null, {check: savedColumns[col as HTCampaignTableColumns] ?? false});
|
|
155
|
+
});
|
|
156
|
+
// then add a new group for custom campaign fields
|
|
157
|
+
const campaignsPropsGroup = menu.group('Campaign Fields');
|
|
158
|
+
|
|
159
|
+
Object.keys(getters).filter((g) => g.startsWith('campaignFields.')).forEach((col) => {
|
|
160
|
+
campaignsPropsGroup.item(col.replace('campaignFields.', ''), () => {
|
|
161
|
+
savedColumns[col as HTCampaignTableColumns] = !savedColumns[col as HTCampaignTableColumns];
|
|
162
|
+
setHTSavedCampaignTableColumns(Object.keys(savedColumns).filter((c) => savedColumns[c as HTCampaignTableColumns]) as HTCampaignTableColumns[]);
|
|
163
|
+
this.refreshCampaignsTable();
|
|
164
|
+
}, null, {check: savedColumns[col as HTCampaignTableColumns] ?? false});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
menu.show({element: sortingHeader, x: 100, y: sortingHeader.offsetTop + 30});
|
|
168
|
+
}, 'View');
|
|
169
|
+
ui.tooltip.bind(editColumnsIcon, 'Edit visible columns in campaigns table');
|
|
170
|
+
editColumnsIcon.style.marginBottom = '9px';
|
|
171
|
+
editColumnsIcon.style.marginLeft = '8px';
|
|
172
|
+
editColumnsIcon.style.fontSize = '15px';
|
|
173
|
+
editColumnsIcon.style.color = 'var(--blue-1)';
|
|
174
|
+
|
|
175
|
+
const refreshIcon = ui.iconFA('sync', async () => {
|
|
176
|
+
await this.refreshCampaignsTable();
|
|
177
|
+
}, 'Refresh');
|
|
178
|
+
refreshIcon.style.marginBottom = '9px';
|
|
179
|
+
refreshIcon.style.marginLeft = '8px';
|
|
180
|
+
refreshIcon.style.color = 'var(--blue-1)';
|
|
181
|
+
ui.tooltip.bind(refreshIcon, () => 'Refresh campaigns table');
|
|
182
|
+
const sortingHeader = ui.divH([continueCampaignsHeader, editColumnsIcon, groupIcon, refreshIcon], {style: {alignItems: 'center'}});
|
|
53
183
|
|
|
54
184
|
await this.startNewCampaign(campaignAccordionDiv, templatesDiv, presetTemplate);
|
|
55
|
-
$(this.
|
|
56
|
-
this.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
campaignAccordionDiv,
|
|
62
|
-
]));
|
|
185
|
+
$(this._contentRoot).empty();
|
|
186
|
+
this._contentRoot.appendChild(ui.divV([sortingHeader], {style: {marginLeft: '10px'}}));
|
|
187
|
+
this._contentRoot.appendChild(this.campaignsTableRoot);
|
|
188
|
+
this._contentRoot.appendChild(createNewCampaignHeader);
|
|
189
|
+
this._contentRoot.appendChild(templatesDiv);
|
|
190
|
+
this._contentRoot.appendChild(campaignAccordionDiv);
|
|
63
191
|
} catch (e) {
|
|
64
192
|
ui.setUpdateIndicator(this.root, false);
|
|
65
193
|
throw e;
|
|
@@ -68,18 +196,25 @@ export class InfoView extends HitBaseView<HitTriageTemplate, HitTriageApp> {
|
|
|
68
196
|
}
|
|
69
197
|
}
|
|
70
198
|
|
|
71
|
-
|
|
199
|
+
protected async startNewCampaign(
|
|
72
200
|
containerDiv: HTMLElement, templateInputDiv: HTMLElement, presetTemplate?: HitTriageTemplate,
|
|
73
201
|
) {
|
|
74
|
-
const templates = (await _package.files.list(
|
|
202
|
+
const templates = (await _package.files.list(this.getTemplatesFolder()))
|
|
203
|
+
.filter((file) => file.name.endsWith('.json'))
|
|
204
|
+
.map((file) => file.name.slice(0, -5));
|
|
75
205
|
// if the template is just created and saved, it may not be in the list of templates
|
|
76
206
|
if (presetTemplate && !templates.includes(presetTemplate.name))
|
|
77
207
|
templates.push(presetTemplate.name);
|
|
78
208
|
|
|
209
|
+
let selectedTemplate: HitTriageTemplate | null = null;
|
|
210
|
+
let templateChangeFlag = true;
|
|
79
211
|
const onTemmplateChange = async () => {
|
|
212
|
+
if (!templateChangeFlag)
|
|
213
|
+
return;
|
|
80
214
|
const templateName = templatesInput.value;
|
|
81
215
|
const template: HitTriageTemplate = presetTemplate && presetTemplate.name === templateName ? presetTemplate :
|
|
82
|
-
|
|
216
|
+
await loadTemplate<HitTriageTemplate>(this.getTemplatesFolder() + '/' + templateName + '.json');
|
|
217
|
+
selectedTemplate = template;
|
|
83
218
|
const newCampaignAccordeon = await this.getNewCampaignAccordeon(template, containerDiv);
|
|
84
219
|
$(containerDiv).empty();
|
|
85
220
|
containerDiv.className = 'ui-form';
|
|
@@ -91,29 +226,62 @@ export class InfoView extends HitBaseView<HitTriageTemplate, HitTriageApp> {
|
|
|
91
226
|
onValueChanged: async () => {
|
|
92
227
|
await onTemmplateChange();
|
|
93
228
|
}});
|
|
229
|
+
templatesInput.root.style.width = '100%';
|
|
94
230
|
const createNewtemplateButton = ui.icons.add(async () => {
|
|
95
231
|
ui.setUpdateIndicator(this.root, true);
|
|
96
232
|
await this.createNewTemplate();
|
|
97
233
|
ui.setUpdateIndicator(this.root, false);
|
|
98
234
|
}, i18n.createNewTemplate);
|
|
99
|
-
templatesInput.addOptions(createNewtemplateButton);
|
|
100
235
|
|
|
236
|
+
const cloneTemplateButton = ui.icons.copy(() => {
|
|
237
|
+
if (selectedTemplate)
|
|
238
|
+
this.createNewTemplate(selectedTemplate);
|
|
239
|
+
}, 'Clone template');
|
|
240
|
+
|
|
241
|
+
const deleteTempleteButton = ui.icons.delete(() => {
|
|
242
|
+
if (!templatesInput.value || templatesInput.items.length < 2)
|
|
243
|
+
return;
|
|
244
|
+
ui.dialog('Delete template')
|
|
245
|
+
.add(ui.divText(`Are you sure you want to delete template ${templatesInput.value}?`))
|
|
246
|
+
.onOK(async () => {
|
|
247
|
+
try {
|
|
248
|
+
const prevValue = templatesInput.value;
|
|
249
|
+
await _package.files.delete(`${this.getTemplatesFolder()}/${prevValue}.json`);
|
|
250
|
+
templateChangeFlag = false;
|
|
251
|
+
templatesInput.items = templatesInput.items.filter((item) => item !== prevValue);
|
|
252
|
+
templatesInput.value = templatesInput.items[0];
|
|
253
|
+
templateChangeFlag = true;
|
|
254
|
+
await onTemmplateChange();
|
|
255
|
+
grok.shell.info('Template ' + prevValue + ' was deleted successfully');
|
|
256
|
+
} catch (e) {
|
|
257
|
+
templateChangeFlag = true;
|
|
258
|
+
grok.shell.error('Failed to delete template ' + templatesInput.value);
|
|
259
|
+
console.error(e);
|
|
260
|
+
}
|
|
261
|
+
})
|
|
262
|
+
.show();
|
|
263
|
+
}, 'Delete template');
|
|
264
|
+
deleteTempleteButton.style.color = 'var(--blue-1)';
|
|
265
|
+
createNewtemplateButton.style.color = '#2083d5';
|
|
266
|
+
templatesInput.addOptions(createNewtemplateButton);
|
|
267
|
+
templatesInput.addOptions(cloneTemplateButton);
|
|
268
|
+
templatesInput.addOptions(deleteTempleteButton);
|
|
101
269
|
await onTemmplateChange();
|
|
102
270
|
$(templateInputDiv).empty();
|
|
103
271
|
templateInputDiv.appendChild(templatesInput.root);
|
|
104
272
|
}
|
|
105
273
|
|
|
106
|
-
|
|
274
|
+
protected async checkCampaign(campId?: string) {
|
|
107
275
|
const url = location.search;
|
|
108
276
|
const urlParams = new URLSearchParams(url);
|
|
109
277
|
if (!urlParams.has(CampaignIdKey) && !campId)
|
|
110
278
|
return;
|
|
111
279
|
const campaignId = campId ?? urlParams.get(CampaignIdKey);
|
|
112
280
|
// check if such campaign exists
|
|
113
|
-
if (!await _package.files.exists(
|
|
281
|
+
if (!await _package.files.exists(`${this.app.appName}/campaigns/${campaignId}/${CampaignJsonName}`))
|
|
114
282
|
return;
|
|
115
283
|
const campaign: HitTriageCampaign =
|
|
116
|
-
JSON.parse(await _package.files.readAsText(
|
|
284
|
+
JSON.parse(await _package.files.readAsText(`${this.app.appName}/campaigns/${campaignId}/${CampaignJsonName}`));
|
|
117
285
|
|
|
118
286
|
if (campaign) {
|
|
119
287
|
// in case if the link was opened and user has no permissions to view the campaign
|
|
@@ -126,8 +294,8 @@ export class InfoView extends HitBaseView<HitTriageTemplate, HitTriageApp> {
|
|
|
126
294
|
this.app.campaign = campaign;
|
|
127
295
|
}
|
|
128
296
|
// Load the template and modify it
|
|
129
|
-
const template: HitTriageTemplate =
|
|
130
|
-
|
|
297
|
+
const template: HitTriageTemplate = await loadTemplate<HitTriageTemplate>(
|
|
298
|
+
`${this.getTemplatesFolder()}/${campaign.templateName}.json`,
|
|
131
299
|
);
|
|
132
300
|
// modify the template with path to the campaign's precalculated table
|
|
133
301
|
this.app.setTemplate(template, campaign.filters, campaignId!, campaign.ingest);
|
|
@@ -139,37 +307,88 @@ export class InfoView extends HitBaseView<HitTriageTemplate, HitTriageApp> {
|
|
|
139
307
|
}
|
|
140
308
|
|
|
141
309
|
private async getCampaignsTable() {
|
|
142
|
-
const campaignNamesMap = await _package.loadCampaigns(
|
|
310
|
+
const campaignNamesMap = await _package.loadCampaigns(this.app.appName, this.deletedCampaigns) as {[name: string]: HitTriageCampaign};
|
|
311
|
+
const grouppingMode = getHTSavedCampaignsGrouping();
|
|
312
|
+
const campaignSorting = getHTSavedCampaignsSorting();
|
|
313
|
+
const allCampaigns = Object.values(campaignNamesMap);
|
|
314
|
+
// sort all campaigns
|
|
315
|
+
if (campaignSorting)
|
|
316
|
+
sortCampaigns(allCampaigns, campaignSorting, HTDefaultCampaignTableInfoGetters as any);
|
|
317
|
+
const grouppedCampaigns = getGroupedCampaigns<HitTriageCampaign>(allCampaigns, grouppingMode);
|
|
318
|
+
const shownColumns = getHTSavedCampaignTableColumns();
|
|
143
319
|
|
|
144
|
-
|
|
145
|
-
|
|
320
|
+
this.currentGroupping = grouppingMode;
|
|
321
|
+
|
|
322
|
+
const deleteAndShareCampaignIcons = (info: HitTriageCampaign) => {
|
|
323
|
+
const deleteIcon = ui.icons.delete(async () => {
|
|
146
324
|
ui.dialog('Delete campaign')
|
|
147
|
-
.add(ui.divText(`Are you sure you want to delete campaign ${info.name}?`))
|
|
325
|
+
.add(ui.divText(`Are you sure you want to delete campaign ${info.friendlyName ?? info.name}?`))
|
|
148
326
|
.onOK(async () => {
|
|
149
|
-
await this.deleteCampaign(
|
|
327
|
+
await this.deleteCampaign(this.app.appName, info.name);
|
|
150
328
|
this.deletedCampaigns.push(info.name);
|
|
151
329
|
await this.init();
|
|
152
330
|
})
|
|
153
331
|
.show();
|
|
154
332
|
}, 'Delete campaign');
|
|
155
|
-
|
|
333
|
+
const shareIcon = ui.iconFA('share', async () => {
|
|
334
|
+
await (new PermissionsDialog(info.permissions)).show(async (res) => {
|
|
335
|
+
try {
|
|
336
|
+
info.permissions = res;
|
|
337
|
+
info.authorUserId ??= grok.shell.user.id;
|
|
338
|
+
await _package.saveCampaignJson(this.app.appName, info);
|
|
339
|
+
grok.shell.info('Permissions updated for campaign ' + (info.friendlyName ?? info.name));
|
|
340
|
+
} catch (e) {
|
|
341
|
+
grok.shell.error('Failed to update permissions for campaign ' + (info.friendlyName ?? info.name));
|
|
342
|
+
console.error(e);
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
}, 'Manage campaign permissions');
|
|
346
|
+
deleteIcon.style.display = 'none';
|
|
347
|
+
shareIcon.style.display = 'none';
|
|
156
348
|
const authorId = info.authorUserId ?? DG.User.current().id;
|
|
157
349
|
const perms = info.permissions ?? defaultPermissions;
|
|
158
350
|
checkEditPermissions(authorId, perms).then((canEdit) => {
|
|
159
|
-
if (canEdit)
|
|
160
|
-
|
|
351
|
+
if (canEdit) {
|
|
352
|
+
deleteIcon.style.display = 'inline-block';
|
|
353
|
+
shareIcon.style.display = 'inline-block';
|
|
354
|
+
}
|
|
161
355
|
});
|
|
162
|
-
|
|
356
|
+
deleteIcon.style.color = 'var(--blue-1)';
|
|
357
|
+
shareIcon.style.color = 'var(--blue-1)';
|
|
358
|
+
return [shareIcon, deleteIcon];
|
|
163
359
|
};
|
|
164
360
|
|
|
165
|
-
const campaignsInfo = Object.values(
|
|
361
|
+
const campaignsInfo = Object.values(grouppedCampaigns).flat();
|
|
166
362
|
const table = ui.table(campaignsInfo, (info) =>
|
|
167
|
-
([ui.link(info.name, () => this.setCampaign(info.name), '', ''),
|
|
168
|
-
|
|
169
|
-
|
|
363
|
+
([ui.link(info.friendlyName ?? info.name, () => this.setCampaign(info.name), 'Continue Campaign', ''),
|
|
364
|
+
...(shownColumns.map((col) => col.startsWith('campaignFields.') ?
|
|
365
|
+
info.campaignFields?.[col.replace('campaignFields.', '')] ?? '' :
|
|
366
|
+
HTDefaultCampaignTableInfoGetters[col as unknown as keyof typeof HTDefaultCampaignTableInfoGetters]?.(info) ?? '')),
|
|
367
|
+
...(deleteAndShareCampaignIcons(info)),
|
|
170
368
|
]),
|
|
171
|
-
['Name',
|
|
369
|
+
['Name', ...(shownColumns.map((a) => a.replace('campaignFields.', ''))), '', '']);
|
|
172
370
|
table.style.color = 'var(--grey-5)';
|
|
371
|
+
table.style.marginLeft = '24px';
|
|
372
|
+
// add sorting support
|
|
373
|
+
table.querySelectorAll('tr.header > td').forEach((el, i) => {
|
|
374
|
+
if (!el.textContent)
|
|
375
|
+
return;
|
|
376
|
+
const field = i === 0 ? 'Name' : shownColumns[i - 1];
|
|
377
|
+
if (campaignSorting && field === campaignSorting.columnName) {
|
|
378
|
+
// add icon
|
|
379
|
+
const sortIcon = campaignSorting.ascending ? '↑' : '↓';
|
|
380
|
+
el.appendChild(ui.span([sortIcon], {style: {fontSize: '12px', marginLeft: '2px'}}));
|
|
381
|
+
}
|
|
382
|
+
(el as HTMLElement).addEventListener('dblclick', () => {
|
|
383
|
+
let nextSorting: HTSavedCampaignsTableSorting | null = {columnName: field, ascending: true};
|
|
384
|
+
if (campaignSorting && field === campaignSorting.columnName)
|
|
385
|
+
nextSorting = campaignSorting.ascending ? {columnName: field, ascending: false} : null;
|
|
386
|
+
setHTSavedCampaignsSorting(nextSorting);
|
|
387
|
+
this.refreshCampaignsTable();
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
processGroupingTable(table, grouppedCampaigns);
|
|
173
392
|
return table;
|
|
174
393
|
}
|
|
175
394
|
|
|
@@ -178,14 +397,14 @@ export class InfoView extends HitBaseView<HitTriageTemplate, HitTriageApp> {
|
|
|
178
397
|
this.app.campaign = campaign;
|
|
179
398
|
}
|
|
180
399
|
|
|
181
|
-
|
|
400
|
+
protected async getNewCampaignAccordeon(template: HitTriageTemplate, campaignDetailsDiv: HTMLElement) {
|
|
182
401
|
ui.setUpdateIndicator(campaignDetailsDiv, true);
|
|
183
|
-
const {root, promise, cancelPromise} = await newCampaignAccordeon(template, this.
|
|
402
|
+
const {root, promise, cancelPromise} = await newCampaignAccordeon(template, this.getDataSourceFunctionsMap(), this.getDataSourceTag());
|
|
184
403
|
ui.setUpdateIndicator(campaignDetailsDiv, false);
|
|
185
404
|
promise.then(async (camp) => {
|
|
186
405
|
this.app.dataFrame = camp.df;
|
|
187
406
|
this.app._fileInputType = camp.type;
|
|
188
|
-
await this.app.setTemplate(template);
|
|
407
|
+
await this.app.setTemplate(template, undefined, undefined, undefined, camp.friendlyName);
|
|
189
408
|
this.app.campaignProps = camp.campaignProps;
|
|
190
409
|
await this.app.saveCampaign(undefined, false);
|
|
191
410
|
if (template.layoutViewState && this.app.campaign)
|
|
@@ -198,8 +417,8 @@ export class InfoView extends HitBaseView<HitTriageTemplate, HitTriageApp> {
|
|
|
198
417
|
return root;
|
|
199
418
|
}
|
|
200
419
|
|
|
201
|
-
|
|
202
|
-
const newTemplateAccordeon = await createTemplateAccordeon(this.app, this.
|
|
420
|
+
protected async createNewTemplate(preset?: HitTriageTemplate) {
|
|
421
|
+
const newTemplateAccordeon = await createTemplateAccordeon(this.app, this.getDataSourceFunctionsMap(), preset);
|
|
203
422
|
|
|
204
423
|
const newView = new DG.ViewBase();
|
|
205
424
|
const curView = grok.shell.v;
|
|
@@ -209,7 +428,7 @@ export class InfoView extends HitBaseView<HitTriageTemplate, HitTriageApp> {
|
|
|
209
428
|
grok.shell.addView(newView);
|
|
210
429
|
newView.path = new URL(this.app.baseUrl).pathname + '/new-template';
|
|
211
430
|
newView.parentView = curView;
|
|
212
|
-
const {sub} = addBreadCrumbsToRibbons(grok.shell.v,
|
|
431
|
+
const {sub} = addBreadCrumbsToRibbons(grok.shell.v, this.app.appName, i18n.createNewTemplate, () => {
|
|
213
432
|
grok.shell.v = curView;
|
|
214
433
|
newView.close();
|
|
215
434
|
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
import * as grok from 'datagrok-api/grok';
|
|
3
|
+
import * as DG from 'datagrok-api/dg';
|
|
4
|
+
import {HitTriageApp} from './hit-triage-app';
|
|
5
|
+
import {PepTriageTemplate, HitTriageTemplate} from './types';
|
|
6
|
+
import {PepTriageInfoView} from './pep-triage-views/info-view';
|
|
7
|
+
import {getSeqHelper} from '@datagrok-libraries/bio/src/utils/seq-helper';
|
|
8
|
+
import {_package} from '../package';
|
|
9
|
+
|
|
10
|
+
export class PepTriageApp extends HitTriageApp {
|
|
11
|
+
private _seqColName?: string;
|
|
12
|
+
|
|
13
|
+
constructor(c: DG.FuncCall) {
|
|
14
|
+
super(c, 'PepTriage', (app) => new PepTriageInfoView(app as PepTriageApp));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get seqColName(): string | undefined {return this._seqColName;}
|
|
18
|
+
|
|
19
|
+
protected override async prepareDataFrame(template: HitTriageTemplate): Promise<void> {
|
|
20
|
+
const ptTemplate = template as PepTriageTemplate;
|
|
21
|
+
if (!this.dataFrame)
|
|
22
|
+
return;
|
|
23
|
+
await this.dataFrame.meta.detectSemanticTypes();
|
|
24
|
+
|
|
25
|
+
// 1. Find sequence column by configured name or by semtype
|
|
26
|
+
const seqColName = ptTemplate.sequenceColumnName;
|
|
27
|
+
let seqCol = seqColName ? this.dataFrame.col(seqColName) : null;
|
|
28
|
+
if (!seqCol)
|
|
29
|
+
seqCol = this.dataFrame.columns.bySemType(DG.SEMTYPE.MACROMOLECULE);
|
|
30
|
+
if (!seqCol) {
|
|
31
|
+
throw new Error(`Sequence column '${seqColName ?? 'Macromolecule'}' not found in the dataset. ` +
|
|
32
|
+
'Make sure the data contains a column with sequences.');
|
|
33
|
+
}
|
|
34
|
+
this._seqColName = seqCol.name;
|
|
35
|
+
|
|
36
|
+
// 2. Initialize SeqHandler for proper notation detection
|
|
37
|
+
const pg = DG.TaskBarProgressIndicator.create('Initializing sequences...');
|
|
38
|
+
try {
|
|
39
|
+
const seqHelper = await getSeqHelper();
|
|
40
|
+
const tempSH = seqHelper.getSeqHandler(seqCol);
|
|
41
|
+
await tempSH.refinerPromise;
|
|
42
|
+
// re-init after refinement
|
|
43
|
+
seqHelper.getSeqHandler(seqCol);
|
|
44
|
+
|
|
45
|
+
// 3. Check if molecule column already exists
|
|
46
|
+
const configuredMolColName = ptTemplate.moleculeColumnName;
|
|
47
|
+
let molCol = configuredMolColName ? this.dataFrame.col(configuredMolColName) : null;
|
|
48
|
+
if (!molCol)
|
|
49
|
+
molCol = this.dataFrame.columns.bySemType(DG.SEMTYPE.MOLECULE);
|
|
50
|
+
|
|
51
|
+
if (!molCol) {
|
|
52
|
+
// 4. Convert sequences to molecules via Bio:toAtomicLevel
|
|
53
|
+
pg.update(50, 'Converting sequences to molecules...');
|
|
54
|
+
await grok.functions.call('Bio:toAtomicLevel', {table: this.dataFrame, seqCol: seqCol, nonlinear: true});
|
|
55
|
+
await this.dataFrame.meta.detectSemanticTypes();
|
|
56
|
+
molCol = this.dataFrame.columns.bySemTypeAll(DG.SEMTYPE.MOLECULE).find((a) => a.name.toLowerCase().includes(seqCol.name.toLowerCase())) ?? null;
|
|
57
|
+
if (!molCol) {
|
|
58
|
+
grok.shell.warning('Failed to convert sequences to molecules. Calculations may not work.');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 5. Reorder columns: sequence first, molecule second, rest follows
|
|
64
|
+
this.reorderColumns(seqCol.name, molCol.name);
|
|
65
|
+
} catch (e) {
|
|
66
|
+
_package.logger.error(e);
|
|
67
|
+
grok.shell.error('Error preparing sequence data: ' + (e instanceof Error ? e.message : e));
|
|
68
|
+
} finally {
|
|
69
|
+
pg.close();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private reorderColumns(seqColName: string, molColName: string) {
|
|
74
|
+
if (!this.dataFrame)
|
|
75
|
+
return;
|
|
76
|
+
const seqCol = this.dataFrame.col(seqColName);
|
|
77
|
+
const molCol = this.dataFrame.col(molColName);
|
|
78
|
+
if (seqCol) {
|
|
79
|
+
this.dataFrame.columns.remove(seqColName);
|
|
80
|
+
this.dataFrame.columns.insert(seqCol, 0);
|
|
81
|
+
}
|
|
82
|
+
if (molCol) {
|
|
83
|
+
this.dataFrame.columns.remove(molColName);
|
|
84
|
+
this.dataFrame.columns.insert(molCol, 1);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
import * as grok from 'datagrok-api/grok';
|
|
3
|
+
import * as ui from 'datagrok-api/ui';
|
|
4
|
+
import * as DG from 'datagrok-api/dg';
|
|
5
|
+
import {u2} from '@datagrok-libraries/utils/src/u2';
|
|
6
|
+
import {_package} from '../../package';
|
|
7
|
+
import {PepTriageTemplate, HitTriageTemplate} from '../types';
|
|
8
|
+
import {PepTriageDataSourceTag, i18n} from '../consts';
|
|
9
|
+
import {InfoView} from '../hit-triage-views/info-view';
|
|
10
|
+
import {PepTriageApp} from '../pep-triage-app';
|
|
11
|
+
import {addBreadCrumbsToRibbons, popRibbonPannels} from '../utils';
|
|
12
|
+
import {newCampaignAccordeon} from '../accordeons/new-campaign-accordeon';
|
|
13
|
+
import {createPepTriageTemplateAccordeon} from '../accordeons/new-pep-triage-template-accordeon';
|
|
14
|
+
|
|
15
|
+
export class PepTriageInfoView extends InfoView {
|
|
16
|
+
private pepTriageDataSourceFunctionsMap: {[key: string]: DG.Func | DG.DataQuery} = {};
|
|
17
|
+
|
|
18
|
+
constructor(app: PepTriageApp) {
|
|
19
|
+
super(app);
|
|
20
|
+
this.name = 'PepTriage';
|
|
21
|
+
grok.shell.windows.showHelp = true;
|
|
22
|
+
grok.shell.windows.help.showHelp(_package.webRoot + 'README_HT.md');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
override onActivated(): void {
|
|
26
|
+
grok.shell.windows.showHelp = true;
|
|
27
|
+
grok.shell.windows.help.showHelp(_package.webRoot + 'README_HT.md');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
protected override getAppHeader() {
|
|
31
|
+
return u2.appHeader({
|
|
32
|
+
iconPath: _package.webRoot + '/images/icons/hit-triage-icon.png',
|
|
33
|
+
learnMoreUrl: 'https://github.com/datagrok-ai/public/blob/master/packages/HitTriage/README_HT.md',
|
|
34
|
+
description:
|
|
35
|
+
'- Configure your own workflow using the template editor\n' +
|
|
36
|
+
'- Load sequence datasets and auto-convert to molecules\n' +
|
|
37
|
+
'- Calculate different molecular properties\n' +
|
|
38
|
+
'- Filter sequences using different criteria\n' +
|
|
39
|
+
'- Save campaigns and continue any time from where you left off\n' +
|
|
40
|
+
'- Submit final selection to the function of your choice',
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
protected override getTemplatesFolder(): string {
|
|
45
|
+
return `${this.app.appName}/templates`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
protected override getDataSourceTag(): string {
|
|
49
|
+
return PepTriageDataSourceTag;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
protected override getDataSourceFunctionsMap(): {[key: string]: DG.Func | DG.DataQuery} {
|
|
53
|
+
return this.pepTriageDataSourceFunctionsMap;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
protected override async getNewCampaignAccordeon(template: HitTriageTemplate, campaignDetailsDiv: HTMLElement) {
|
|
57
|
+
const ptTemplate = template as PepTriageTemplate;
|
|
58
|
+
const seqColInput = ui.input.string('Sequence Column', {value: ptTemplate.sequenceColumnName ?? '', nullable: false});
|
|
59
|
+
seqColInput.setTooltip('Name of the sequence column in the dataset');
|
|
60
|
+
const molColInput = ui.input.string('Molecule Column', {value: ptTemplate.moleculeColumnName ?? '', nullable: true});
|
|
61
|
+
molColInput.setTooltip('Name of the molecule column (leave empty to auto-convert from sequences)');
|
|
62
|
+
|
|
63
|
+
ui.setUpdateIndicator(campaignDetailsDiv, true);
|
|
64
|
+
const {root, promise, cancelPromise} = await newCampaignAccordeon(
|
|
65
|
+
template, this.getDataSourceFunctionsMap(), this.getDataSourceTag(), {
|
|
66
|
+
extraFormElements: [seqColInput.root, molColInput.root],
|
|
67
|
+
getExtraData: () => ({
|
|
68
|
+
sequenceColumnName: seqColInput.value?.trim() || ptTemplate.sequenceColumnName,
|
|
69
|
+
moleculeColumnName: molColInput.value?.trim() || undefined,
|
|
70
|
+
}),
|
|
71
|
+
});
|
|
72
|
+
ui.setUpdateIndicator(campaignDetailsDiv, false);
|
|
73
|
+
promise.then(async (camp) => {
|
|
74
|
+
// Override template column names with user-specified values
|
|
75
|
+
const modifiedTemplate = {...ptTemplate,
|
|
76
|
+
sequenceColumnName: camp.extraData?.sequenceColumnName ?? ptTemplate.sequenceColumnName,
|
|
77
|
+
moleculeColumnName: camp.extraData?.moleculeColumnName ?? ptTemplate.moleculeColumnName,
|
|
78
|
+
};
|
|
79
|
+
this.app.dataFrame = camp.df;
|
|
80
|
+
this.app._fileInputType = camp.type;
|
|
81
|
+
await this.app.setTemplate(modifiedTemplate, undefined, undefined, undefined, camp.friendlyName);
|
|
82
|
+
this.app.campaignProps = camp.campaignProps;
|
|
83
|
+
await this.app.saveCampaign(undefined, false);
|
|
84
|
+
if (modifiedTemplate.layoutViewState && this.app.campaign)
|
|
85
|
+
this.app.campaign.layout = modifiedTemplate.layoutViewState;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
cancelPromise.then(() => {
|
|
89
|
+
this.init();
|
|
90
|
+
});
|
|
91
|
+
return root;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
protected override async createNewTemplate(preset?: HitTriageTemplate): Promise<void> {
|
|
95
|
+
const newTemplateAccordeon = await createPepTriageTemplateAccordeon(this.app, this.getDataSourceFunctionsMap(), preset as PepTriageTemplate);
|
|
96
|
+
|
|
97
|
+
const newView = new DG.ViewBase();
|
|
98
|
+
const curView = grok.shell.v;
|
|
99
|
+
newView.name = 'New Template';
|
|
100
|
+
newView.root.appendChild(newTemplateAccordeon.root);
|
|
101
|
+
newView.parentCall = this.app.parentCall;
|
|
102
|
+
grok.shell.addView(newView);
|
|
103
|
+
newView.path = new URL(this.app.baseUrl).pathname + '/new-template';
|
|
104
|
+
newView.parentView = curView;
|
|
105
|
+
const {sub} = addBreadCrumbsToRibbons(grok.shell.v, this.app.appName, i18n.createNewTemplate, () => {
|
|
106
|
+
grok.shell.v = curView;
|
|
107
|
+
newView.close();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
newTemplateAccordeon.template.then(async (t) => {
|
|
111
|
+
await this.init(t as any);
|
|
112
|
+
newView.close();
|
|
113
|
+
popRibbonPannels(newView);
|
|
114
|
+
grok.shell.v = curView;
|
|
115
|
+
sub.unsubscribe();
|
|
116
|
+
});
|
|
117
|
+
newTemplateAccordeon.cancelPromise.then(() => {
|
|
118
|
+
sub.unsubscribe();
|
|
119
|
+
newView.close();
|
|
120
|
+
grok.shell.v = curView;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|