Skip to content

Commit 1b8268b

Browse files
Implements #1373 and f/e part of the #1393 (#421)
* - first implementation of #1354 * - updated message for #1354 * - cleanup for #1354 * - implemented #1361 - improvements for #1354 * - implemented #1376 - also fixed bug in download structures dialog where only first download got added to the dropdown menu * - partial fix for purple release for #1370 * - using official backend version * - DELETE button disabled for #1357 * - added requirements * Squashed commit of the following: commit 07ba57d Author: Boris Kovar <boris.kovar@m2ms.sk> Date: Mon Mar 25 08:23:53 2024 +0100 - #1393 - all columns are now included * Squashed commit of the following: commit e1e3c2c Author: Boris Kovar <boris.kovar@m2ms.sk> Date: Wed Apr 10 15:31:02 2024 +0200 - implemented #1373
1 parent 012895a commit 1b8268b

File tree

5 files changed

+162
-61
lines changed

5 files changed

+162
-61
lines changed
5.87 MB
Binary file not shown.

js/components/datasets/compoundSetList.js

Lines changed: 135 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
import React, { useEffect, memo, useState, useCallback } from 'react';
55
import { useDispatch, useSelector } from 'react-redux';
6-
import { clearDatasetSettings, initializeDatasetFilter } from './redux/dispatchActions';
6+
import { clearDatasetSettings, getInspirationsForMol, initializeDatasetFilter } from './redux/dispatchActions';
77
import { setExpandCompoundSets, setDataset, setSelectedDatasetIndex, setUpdatedDatasets } from './redux/actions';
88
import DatasetMoleculeList from './datasetMoleculeList';
99
import { makeStyles, Table, TableBody, TableCell, TableHead, TableRow, Tooltip } from '@material-ui/core';
@@ -13,6 +13,7 @@ import CloudDownloadOutlinedIcon from '@mui/icons-material/CloudDownloadOutlined
1313
import SearchField from '../common/Components/SearchField';
1414
import { base_url } from '../routes/constants';
1515
import { METHOD, api } from '../../utils/api';
16+
import { compoundsColors } from '../preview/compounds/redux/constants';
1617

1718
const useStyles = makeStyles(theme => ({
1819
table: {
@@ -63,6 +64,23 @@ export const CompoundSetList = () => {
6364
const scoreDatasetMap = useSelector(state => state.datasetsReducers.scoreDatasetMap);
6465
const moleculeLists = useSelector(state => state.datasetsReducers.moleculeLists);
6566

67+
const allInspirations = useSelector(state => state.datasetsReducers.allInspirations);
68+
const compoundColors = useSelector(state => state.datasetsReducers.compoundColorByDataset);
69+
70+
const blueInput = useSelector(state => state.previewReducers.compounds[compoundsColors.blue.key]);
71+
const redInput = useSelector(state => state.previewReducers.compounds[compoundsColors.red.key]);
72+
const greenInput = useSelector(state => state.previewReducers.compounds[compoundsColors.green.key]);
73+
const purpleInput = useSelector(state => state.previewReducers.compounds[compoundsColors.purple.key]);
74+
const apricotInput = useSelector(state => state.previewReducers.compounds[compoundsColors.apricot.key]);
75+
76+
const inputs = {
77+
[compoundsColors.blue.key]: blueInput,
78+
[compoundsColors.red.key]: redInput,
79+
[compoundsColors.green.key]: greenInput,
80+
[compoundsColors.purple.key]: purpleInput,
81+
[compoundsColors.apricot.key]: apricotInput
82+
};
83+
6684
const [isExpanded, setIsExpanded] = useState(false);
6785
const [searchString, setSearchString] = useState(null);
6886
const [defaultSelectedValue, setDefaultSelectedValue] = useState();
@@ -74,13 +92,20 @@ export const CompoundSetList = () => {
7492
* @param {*} scoreName
7593
* @returns {string}
7694
*/
77-
const getCommonScore = useCallback((datasetID, scoreName) => {
78-
let value = '';
79-
if (datasetID && scoreDatasetMap.hasOwnProperty(datasetID) && scoreDatasetMap[datasetID].hasOwnProperty(scoreName)) {
80-
value = scoreDatasetMap[datasetID][scoreName].description;
81-
}
82-
return value;
83-
}, [scoreDatasetMap]);
95+
const getCommonScore = useCallback(
96+
(datasetID, scoreName) => {
97+
let value = '';
98+
if (
99+
datasetID &&
100+
scoreDatasetMap.hasOwnProperty(datasetID) &&
101+
scoreDatasetMap[datasetID].hasOwnProperty(scoreName)
102+
) {
103+
value = scoreDatasetMap[datasetID][scoreName].description;
104+
}
105+
return value;
106+
},
107+
[scoreDatasetMap]
108+
);
84109

85110
/**
86111
* Download molecule list of given dataset as CSV file
@@ -91,12 +116,81 @@ export const CompoundSetList = () => {
91116
const listOfMols = [];
92117
const moleculeList = moleculeLists[datasetID] || [];
93118

119+
let maxNumOfInspirations = 0;
120+
moleculeList.forEach(cmp => {
121+
const inspirations = getInspirationsForMol(allInspirations, datasetID, cmp.id);
122+
if (inspirations?.length > maxNumOfInspirations) {
123+
maxNumOfInspirations = inspirations.length;
124+
}
125+
});
126+
127+
let colorsTemplate = {};
128+
moleculeList.forEach(compound => {
129+
let shoppingCartColors = [];
130+
const cmpColorsForDataset = compoundColors[datasetID];
131+
if (cmpColorsForDataset) {
132+
shoppingCartColors = cmpColorsForDataset[compound.id];
133+
shoppingCartColors.forEach(color => {
134+
if (!colorsTemplate.hasOwnProperty(color)) {
135+
colorsTemplate[color] = '';
136+
if (inputs.hasOwnProperty(color) && inputs[color]) {
137+
colorsTemplate[`${color}-text`] = inputs[color];
138+
}
139+
}
140+
});
141+
}
142+
});
143+
94144
moleculeList.forEach(molecule => {
95145
let molObj = {};
96146

97147
molObj['smiles'] = molecule.smiles;
98148
molObj['name'] = molecule.name;
99149

150+
if (molecule.hasOwnProperty('numerical_scores')) {
151+
Object.keys(molecule.numerical_scores).forEach(key => {
152+
molObj[key] = molecule.numerical_scores[key];
153+
});
154+
}
155+
if (molecule.hasOwnProperty('text_scores')) {
156+
Object.keys(molecule.text_scores).forEach(key => {
157+
molObj[key] = molecule.text_scores[key];
158+
});
159+
}
160+
161+
if (maxNumOfInspirations) {
162+
const inspirations = getInspirationsForMol(allInspirations, datasetID, molecule.id);
163+
for (let i = 0; i < maxNumOfInspirations; i++) {
164+
if (inspirations?.[i]) {
165+
molObj[`inspiration_${i + 1}`] = inspirations[i].code;
166+
} else {
167+
molObj[`inspiration_${i + 1}`] = '';
168+
}
169+
}
170+
}
171+
172+
let shoppingCartColors = [];
173+
174+
const cmpColorsForDataset = compoundColors[datasetID];
175+
if (cmpColorsForDataset) {
176+
shoppingCartColors = cmpColorsForDataset[molecule.id];
177+
let colorsTemplateCopy = { ...colorsTemplate };
178+
shoppingCartColors.forEach(color => {
179+
colorsTemplateCopy[color] = true;
180+
});
181+
182+
Object.keys(colorsTemplateCopy)
183+
.filter(key => key.includes('-text'))
184+
.forEach(key => {
185+
const color = key.split('-')[0];
186+
if (colorsTemplateCopy.hasOwnProperty(color) && !colorsTemplateCopy[color]) {
187+
colorsTemplateCopy[key] = '';
188+
}
189+
});
190+
191+
molObj = { ...molObj, ...colorsTemplateCopy };
192+
}
193+
100194
listOfMols.push(molObj);
101195
});
102196

@@ -118,7 +212,9 @@ export const CompoundSetList = () => {
118212

119213
useEffect(() => {
120214
if (selectedDatasetIndex === 0) {
121-
const filteredDataset = searchString ? customDatasets.filter(dataset => dataset.title.toLowerCase().includes(searchString.toLowerCase())) : customDatasets;
215+
const filteredDataset = searchString
216+
? customDatasets.filter(dataset => dataset.title.toLowerCase().includes(searchString.toLowerCase()))
217+
: customDatasets;
122218
const newDataset = filteredDataset.map((dataSet, index) =>
123219
index === 0 ? { ...dataSet, visibility: true } : { ...dataSet, visibility: false }
124220
);
@@ -138,7 +234,9 @@ export const CompoundSetList = () => {
138234
};
139235

140236
const handleChangeVisibility = index => {
141-
const filteredDataset = searchString ? customDatasets.filter(dataset => dataset.title.toLowerCase().includes(searchString.toLowerCase())) : customDatasets;
237+
const filteredDataset = searchString
238+
? customDatasets.filter(dataset => dataset.title.toLowerCase().includes(searchString.toLowerCase()))
239+
: customDatasets;
142240
const newDataset = filteredDataset.map((dataSetValue, i) =>
143241
i === index ? { ...dataSetValue, visibility: true } : { ...dataSetValue, visibility: false }
144242
);
@@ -171,30 +269,14 @@ export const CompoundSetList = () => {
171269
<Table className={classes.table}>
172270
<TableHead>
173271
<TableRow style={{ padding: 0 }}>
174-
<TableCell style={{ width: 25, padding: 0 }}>
175-
{/* Select */}
176-
</TableCell>
177-
<TableCell style={{ width: 60, padding: 0 }}>
178-
Name
179-
</TableCell>
180-
<TableCell style={{ width: 15, padding: 0 }}>
181-
#
182-
</TableCell>
183-
<TableCell style={{ width: 70, padding: 0 }}>
184-
Submitter
185-
</TableCell>
186-
<TableCell style={{ width: 55, padding: 0 }}>
187-
Institution
188-
</TableCell>
189-
<TableCell style={{ width: 60, padding: 0 }}>
190-
Date
191-
</TableCell>
192-
<TableCell style={{ width: 70, padding: 0 }}>
193-
Method
194-
</TableCell>
195-
<TableCell style={{ width: 30, padding: 0 }}>
196-
CSV
197-
</TableCell>
272+
<TableCell style={{ width: 25, padding: 0 }}>{/* Select */}</TableCell>
273+
<TableCell style={{ width: 60, padding: 0 }}>Name</TableCell>
274+
<TableCell style={{ width: 15, padding: 0 }}>#</TableCell>
275+
<TableCell style={{ width: 70, padding: 0 }}>Submitter</TableCell>
276+
<TableCell style={{ width: 55, padding: 0 }}>Institution</TableCell>
277+
<TableCell style={{ width: 60, padding: 0 }}>Date</TableCell>
278+
<TableCell style={{ width: 70, padding: 0 }}>Method</TableCell>
279+
<TableCell style={{ width: 30, padding: 0 }}>CSV</TableCell>
198280
</TableRow>
199281
</TableHead>
200282
<TableBody>
@@ -220,23 +302,36 @@ export const CompoundSetList = () => {
220302
</TableCell>
221303
</Tooltip>
222304
<Tooltip title="Number of compounds">
223-
<TableCell className={classes.tableCell} style={{ maxWidth: 15 }}>{moleculeList.length}</TableCell>
305+
<TableCell className={classes.tableCell} style={{ maxWidth: 15 }}>
306+
{moleculeList.length}
307+
</TableCell>
224308
</Tooltip>
225309
<Tooltip title={getCommonScore(dataset.id, 'submitter_name')}>
226-
<TableCell className={classes.tableCell} style={{ maxWidth: 100 }}>{getCommonScore(dataset.id, 'submitter_name')}</TableCell>
310+
<TableCell className={classes.tableCell} style={{ maxWidth: 100 }}>
311+
{getCommonScore(dataset.id, 'submitter_name')}
312+
</TableCell>
227313
</Tooltip>
228314
<Tooltip title={getCommonScore(dataset.id, 'submitter_institution')}>
229-
<TableCell className={classes.tableCell} style={{ maxWidth: 70 }}>{getCommonScore(dataset.id, 'submitter_institution')}</TableCell>
315+
<TableCell className={classes.tableCell} style={{ maxWidth: 70 }}>
316+
{getCommonScore(dataset.id, 'submitter_institution')}
317+
</TableCell>
230318
</Tooltip>
231319
<Tooltip title={getCommonScore(dataset.id, 'generation_date')}>
232-
<TableCell className={classes.tableCell} style={{ maxWidth: 60 }}>{getCommonScore(dataset.id, 'generation_date')}</TableCell>
320+
<TableCell className={classes.tableCell} style={{ maxWidth: 60 }}>
321+
{getCommonScore(dataset.id, 'generation_date')}
322+
</TableCell>
233323
</Tooltip>
234324
<Tooltip title={getCommonScore(dataset.id, 'method')}>
235-
<TableCell className={classes.tableCell} style={{ maxWidth: 150 }}>{getCommonScore(dataset.id, 'method')}</TableCell>
325+
<TableCell className={classes.tableCell} style={{ maxWidth: 150 }}>
326+
{getCommonScore(dataset.id, 'method')}
327+
</TableCell>
236328
</Tooltip>
237329
<TableCell style={{ padding: 0 }}>
238330
<Tooltip title="Download as CSV">
239-
<CloudDownloadOutlinedIcon className={classes.downloadIcon} onClick={() => downloadCSV(dataset.id)} />
331+
<CloudDownloadOutlinedIcon
332+
className={classes.downloadIcon}
333+
onClick={() => downloadCSV(dataset.id)}
334+
/>
240335
</Tooltip>
241336
</TableCell>
242337
</TableRow>

js/components/datasets/selectedCompoundsList.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,9 @@ export const SelectedCompoundList = memo(() => {
297297
};
298298
}, [dispatch]);
299299

300-
const getSetOfProps = usedDatasets => {
300+
const getSetOfProps = filteredCompounds => {
301301
const unionOfProps = new Set();
302+
const usedDatasets = {};
302303

303304
unionOfProps.add('smiles');
304305

@@ -313,6 +314,26 @@ export const SelectedCompoundList = memo(() => {
313314
}
314315
});
315316

317+
filteredCompounds.forEach(compound => {
318+
const datasetName = compound.datasetID;
319+
if (!usedDatasets.hasOwnProperty(datasetName)) {
320+
const mol = compound.molecule;
321+
if (mol.hasOwnProperty('numerical_scores')) {
322+
const numericalScores = mol['numerical_scores'];
323+
Object.keys(numericalScores).forEach(key => {
324+
unionOfProps.add(key);
325+
});
326+
}
327+
if (mol.hasOwnProperty('text_scores')) {
328+
const textScores = mol['text_scores'];
329+
Object.keys(textScores).forEach(key => {
330+
unionOfProps.add(key);
331+
});
332+
}
333+
usedDatasets[datasetName] = true;
334+
}
335+
});
336+
316337
return [...unionOfProps];
317338
};
318339

@@ -417,17 +438,6 @@ export const SelectedCompoundList = memo(() => {
417438
return result;
418439
};
419440

420-
const getUsedDatasets = mols => {
421-
const setOfDataSets = {};
422-
mols.forEach(mol => {
423-
if (!setOfDataSets.hasOwnProperty(mol.datasetID)) {
424-
setOfDataSets[mol.datasetID] = mol.datasetID;
425-
}
426-
});
427-
428-
return setOfDataSets;
429-
};
430-
431441
const getEmptyMolObject = (props, ids) => {
432442
let molObj = {};
433443

@@ -470,8 +480,7 @@ export const SelectedCompoundList = memo(() => {
470480
return isVisible;
471481
});
472482

473-
const usedDatasets = getUsedDatasets(filteredCompounds);
474-
const props = getSetOfProps(usedDatasets);
483+
const props = getSetOfProps(filteredCompounds);
475484
const ids = getCompoundIds(filteredCompounds);
476485

477486
const listOfMols = [];
@@ -520,7 +529,7 @@ export const SelectedCompoundList = memo(() => {
520529
const inspirations = getInspirationsForMol(allInspirations, compound.datasetID, compound.molecule.id);
521530
for (let i = 0; i < maxNumOfInspirations; i++) {
522531
if (inspirations?.[i]) {
523-
molObj[`inspiration_${i + 1}`] = inspirations[i].protein_code;
532+
molObj[`inspiration_${i + 1}`] = inspirations[i].code;
524533
} else {
525534
molObj[`inspiration_${i + 1}`] = '';
526535
}
@@ -534,11 +543,9 @@ export const SelectedCompoundList = memo(() => {
534543
const cmpColorsForDataset = compoundColors[compound.datasetID];
535544
shoppingCartColors = cmpColorsForDataset[compound.molecule.id];
536545
}
537-
// let colorTagsToDisplay = '';
538546
let colorsTemplateCopy = { ...colorsTemplate };
539547
shoppingCartColors.forEach(color => {
540548
colorsTemplateCopy[color] = true;
541-
// colorTagsToDisplay = colorTagsToDisplay + `${color}: ${inputs[color] || ''}|`;
542549
});
543550

544551
Object.keys(colorsTemplateCopy)
@@ -550,7 +557,6 @@ export const SelectedCompoundList = memo(() => {
550557
}
551558
});
552559

553-
// molObj['color_groups'] = colorTagsToDisplay;
554560
molObj = { ...molObj, ...colorsTemplateCopy };
555561

556562
listOfMols.push(molObj);

js/components/nglView/generatingObjects.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const assignRepresentationArrayToComp = (representations, comp) => {
2525

2626
export const generateProteinObject = data => {
2727
// Now deal with this target
28-
const prot_to_load = window.location.protocol + '//' + window.location.host + data.template_protein;
28+
const prot_to_load = data.template_protein;
2929
if (JSON.stringify(prot_to_load) !== JSON.stringify(undefined)) {
3030
return {
3131
name: OBJECT_TYPE.PROTEIN + '_' + data.id.toString(),

js/components/preview/tags/details/tagDetails.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ const TagDetails = memo(() => {
198198
const moleculesToEditIds = useSelector(state => state.selectionReducers.moleculesToEdit);
199199
const moleculesToEdit =
200200
moleculesToEditIds &&
201-
moleculesToEditIds.length > 0 &&
202-
!(moleculesToEditIds.length === 1 && moleculesToEditIds[0] === null)
201+
moleculesToEditIds.length > 0 &&
202+
!(moleculesToEditIds.length === 1 && moleculesToEditIds[0] === null)
203203
? moleculesToEditIds.map(id => dispatch(getMoleculeForId(id)))
204204
: [];
205205

0 commit comments

Comments
 (0)