Skip to content

Commit

Permalink
- tweaks added to csv generation
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskovar-m2ms committed Feb 17, 2021
1 parent e4b2117 commit d46c222
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
2 changes: 1 addition & 1 deletion js/components/datasets/datasetMoleculeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ export const DatasetMoleculeView = memo(
onClick={() => {
dispatch(centerOnLigandByMoleculeID(stage, getDatasetMoleculeID(datasetID, currentID)));
}}
disabled={false || !isLigandOn}
disabled={false || !isLigandOn || isCompoundFromVectorSelector(data)}
>
<MyLocation className={classes.myLocation} />
</Button>
Expand Down
51 changes: 33 additions & 18 deletions js/components/datasets/selectedCompoundsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,20 @@ export const SelectedCompoundList = memo(({ height }) => {
};
}, [dispatch]);

const getSetOfProps = () => {
const getSetOfProps = (usedDatasets) => {
const unionOfProps = new Set();

unionOfProps.add('smiles');

Object.keys(filteredScoreProperties).forEach(datasetName => {
const dataset = filteredScoreProperties[datasetName];
dataset.forEach(prop => {
// if (prop.hasOwnProperty('computed_set')) {
unionOfProps.add(prop);
// }
});
if (usedDatasets.hasOwnProperty(datasetName)){
const dataset = filteredScoreProperties[datasetName];
dataset.forEach(prop => {
if (prop.hasOwnProperty('computed_set')) {
unionOfProps.add(prop.name);
}
});
}
});

return [...unionOfProps];
Expand All @@ -171,16 +175,16 @@ export const SelectedCompoundList = memo(({ height }) => {
const prepareHeader = (props, maxIdsCount) => {
let header = getIdsHeader(maxIdsCount);

if (props.length > 0) {
if (header.length > 0 && props.length > 0) {
header += ',';
}

for (let i = 0; i < props.length; i++) {
const prop = props[i];
if (i < props.length - 1) {
header += `${encodeURIComponent(prop.name)},`;
header += `${encodeURIComponent(prop)},`;
} else {
header += `${encodeURIComponent(prop.name)}`;
header += `${encodeURIComponent(prop)}`;
}
}

Expand All @@ -194,16 +198,16 @@ export const SelectedCompoundList = memo(({ height }) => {

line = prepareMolIds(compound, maxIdsCount);

if (props.length > 0) {
if (line.length > 0 && props.length > 0) {
line += ',';
}

let value = '';
for (let i = 0; i < props.length; i++) {
value = '';
const prop = props[i];
if (molecule.hasOwnProperty(prop.name)) {
value = molecule[prop.name];
if (molecule.hasOwnProperty(prop)) {
value = molecule[prop];
} else {
let mapOfNumScores = undefined;
let mapOfTextScores = undefined;
Expand All @@ -214,13 +218,13 @@ export const SelectedCompoundList = memo(({ height }) => {
mapOfTextScores = molecule['text_scores'];
}
if (mapOfNumScores !== undefined) {
if (mapOfNumScores.hasOwnProperty(prop.name)) {
value = mapOfNumScores[prop.name];
if (mapOfNumScores.hasOwnProperty(prop)) {
value = mapOfNumScores[prop];
}
}
if (mapOfTextScores !== undefined) {
if (mapOfTextScores.hasOwnProperty(prop.name)) {
value = mapOfTextScores[prop.name];
if (mapOfTextScores.hasOwnProperty(prop)) {
value = mapOfTextScores[prop];
}
}
}
Expand Down Expand Up @@ -292,8 +296,19 @@ export const SelectedCompoundList = memo(({ height }) => {
return idsHeader;
};

const getUsedDatasets = (mols) => {
const setOfDataSets = {};
mols.forEach(mol => {
if (!setOfDataSets.hasOwnProperty(mol.datasetID))
setOfDataSets[mol.datasetID] = mol.datasetID;
});

return setOfDataSets;
}

const downloadAsCsv = () => {
const props = getSetOfProps();
const usedDatasets = getUsedDatasets(moleculesObjectIDListOfCompoundsToBuy);
const props = getSetOfProps(usedDatasets);
let maxIdsCount = getMaxNumberOfCmpIds(moleculesObjectIDListOfCompoundsToBuy);
let data = prepareHeader(props, maxIdsCount);

Expand Down

0 comments on commit d46c222

Please sign in to comment.