Skip to content

Commit

Permalink
Merge pull request #236 from m2ms/allfunctionality
Browse files Browse the repository at this point in the history
Allfunctionality
  • Loading branch information
boriskovar-m2ms authored Mar 2, 2021
2 parents ca4517d + 0c2cc4e commit 663dfeb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
43 changes: 28 additions & 15 deletions js/components/datasets/selectedCompoundsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ export const SelectedCompoundList = memo(({ height }) => {
return [...unionOfProps];
};

const populateMolObject = (molObj, compound, props) => {
const populateMolObject = (molObj, compound, props, ids) => {
const molecule = compound.molecule;

molObj = populateMolIds(molObj, compound);
molObj = populateMolIds(molObj, compound, ids);

let value = '';
for (let i = 0; i < props.length; i++) {
Expand Down Expand Up @@ -216,29 +216,41 @@ export const SelectedCompoundList = memo(({ height }) => {
return molObj;
};

const populateMolIds = (molObj, compound) => {
const populateMolIds = (molObj, compound, idsGlobal) => {
if (compound.molecule.hasOwnProperty('compound_ids')) {
const ids = compound.molecule['compound_ids'];
for (let i = 0; i < ids.length; i++) {
const id = ids[i];
molObj[`compound-id${i}`] = id;
const vendorId = id.split(':')[0];
const fieldName = idsGlobal.diffIds[vendorId];
molObj[fieldName] = id;
};
}

return molObj;
};

const getMaxNumberOfCmpIds = (mols) => {
let maxLength = 0;
const getCompoundIds = (mols) => {
let result = {diffIds: {}, namesToIds: {}, idsInOrder: new Set()};

let currentIdIndex = 0;
mols.forEach(mol => {
if (mol.molecule.hasOwnProperty('compound_ids')) {
const ids = mol.molecule['compound_ids'];
maxLength = maxLength < ids.length ? ids.length : maxLength;
ids.forEach(id => {
let vendorId = id.split(':')[0];
if (!result.diffIds.hasOwnProperty(vendorId)) {
const idFieldName = `compound-id${currentIdIndex}`;
result.diffIds[vendorId] = idFieldName;
result.namesToIds[idFieldName] = vendorId;
result.idsInOrder.add(idFieldName);
currentIdIndex++;
}
});
}
});

return maxLength;
return result;
};

const getUsedDatasets = (mols) => {
Expand All @@ -251,12 +263,13 @@ export const SelectedCompoundList = memo(({ height }) => {
return setOfDataSets;
}

const getEmptyMolObject = (props, maxIdsCount) => {
const getEmptyMolObject = (props, ids) => {
let molObj = {};

for (let i = 0; i < maxIdsCount; i++) {
molObj[`compound-id${i}`] = '';
};
ids.idsInOrder.forEach(id => {
molObj[id] = '';
});

props.forEach(prop => {
molObj[prop] = '';
});
Expand All @@ -275,13 +288,13 @@ export const SelectedCompoundList = memo(({ height }) => {

const usedDatasets = getUsedDatasets(moleculesObjectIDListOfCompoundsToBuy);
const props = getSetOfProps(usedDatasets);
let maxIdsCount = getMaxNumberOfCmpIds(moleculesObjectIDListOfCompoundsToBuy);
const ids = getCompoundIds(moleculesObjectIDListOfCompoundsToBuy);

const listOfMols = [];

moleculesObjectIDListOfCompoundsToBuy.forEach(compound => {
let molObj = getEmptyMolObject(props, maxIdsCount);
molObj = populateMolObject(molObj, compound, props);
let molObj = getEmptyMolObject(props, ids);
molObj = populateMolObject(molObj, compound, props, ids);
listOfMols.push(molObj);
});

Expand Down
3 changes: 2 additions & 1 deletion js/components/preview/compounds/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export const selectAllCompounds = () => (dispatch, getState) => {
vector: currentVectorCompoundsFiltered[key].vector.split('_')[0],
mol: smiles,
class: currentCompoundClass,
compoundId: compoundId
compoundId: compoundId,
compound_ids: [...currentVectorCompoundsFiltered[key][index][indexOfCompound].compound_ids]
};

thisObj['index'] = indexOfCompound;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fragalysis-frontend",
"version": "0.9.68",
"version": "0.9.69",
"description": "Frontend for fragalysis",
"main": "webpack.config.js",
"scripts": {
Expand Down

0 comments on commit 663dfeb

Please sign in to comment.