Skip to content

Commit

Permalink
#424 sorting still not what a human expects: needs to sort by *inferr…
Browse files Browse the repository at this point in the history
…ed* number, not just by string
  • Loading branch information
Adriána Kohanová committed Sep 30, 2020
1 parent 0eb143a commit 833b39e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
8 changes: 8 additions & 0 deletions js/components/preview/molecule/helperConstants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
const main_identifier = 'x';
const sub_identifier = '_';

export const constants = {
MAIN_IDENTIFIER: main_identifier,
SUB_IDENTIFIER: sub_identifier
};

export const moleculeProperty = {
mw: 'MW',
logP: 'logP',
Expand Down
2 changes: 1 addition & 1 deletion js/components/preview/molecule/moleculeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export const MoleculeList = memo(({ height, setFilterItemsHeight, filterItemsHei
joinedMoleculeLists = filterMolecules(joinedMoleculeLists, filter);
} else {
// default sort is by site
joinedMoleculeLists.sort((a, b) => a.site - b.site);
joinedMoleculeLists.sort((a, b) => a.site - b.site || a.number - b.number);
}

const loadNextMolecules = () => {
Expand Down
10 changes: 8 additions & 2 deletions js/components/preview/molecule/redux/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const prefix = 'PREVIEW_MOLECULE_';

export const constants = {
SET_SORT_DIALOG_OPEN: prefix + 'SET_SORT_DIALOG_OPEN',

RELOAD_REDUCER: prefix + 'RELOAD_REDUCER'
};

Expand All @@ -14,12 +13,19 @@ export const MOL_ATTR = {
color: '#72e5be',
filter: false
},
HID: {
/* HID: {
key: 'id',
name: 'Hit ID (HID)',
isFloat: false,
color: '#daa520',
filter: false
}, */
HID: {
key: 'number',
name: 'Hit ID (HID)',
isFloat: true,
color: '#daa520',
filter: false
},
MW: {
key: 'MW',
Expand Down
40 changes: 39 additions & 1 deletion js/components/preview/molecule/redux/selectors.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,44 @@
import { createSelector } from 'reselect';
import { constants } from '../helperConstants';

const getCachedMoleculeLists = state => state.apiReducers.cached_mol_lists;
const getMoleculeGroupLists = state => state.apiReducers.mol_group_list;
const getMoleculeGroupSelection = state => state.selectionReducers.mol_group_selection;
const getObjectSelection = state => state.selectionReducers.object_selection;

export function getNumberFromCode(inputCode) {
let number = 0;
let subNumber = 0;

let code = inputCode.toLowerCase();
let codeAfterIdentifier = code.split(constants.MAIN_IDENTIFIER)[1];

if (codeAfterIdentifier != null) {
let startingNumber = (codeAfterIdentifier.match(/\d+/) || [0])
.map(function(v) {
return +v;
})
.shift();

number = startingNumber;

if (codeAfterIdentifier.includes(constants.SUB_IDENTIFIER)) {
let codeAfterSubIdentifier = codeAfterIdentifier.split(constants.sub_identifier)[1];
if (codeAfterSubIdentifier != null) {
let startingSubNumber = (codeAfterSubIdentifier.match(/\d+/) || [0])
.map(function(v) {
return +v;
})
.shift();
subNumber = startingSubNumber;
}
}
}

let numberWithSub = +(number + '.' + subNumber);
return { number: numberWithSub };
}

export const selectJoinedMoleculeList = createSelector(
getCachedMoleculeLists,
getMoleculeGroupLists,
Expand All @@ -17,13 +51,17 @@ export const selectJoinedMoleculeList = createSelector(
object_selection.forEach(obj => {
const cachedData = cached_mol_lists[obj];
const site = (mol_group_list || []).findIndex(group => group.id === obj) + 1;

let cachedDataArray = [];
if (cachedData && Array.isArray(cachedData)) {
cachedDataArray = cachedData;
} else if (cachedData && cachedData.results && Array.isArray(cachedData.results)) {
cachedDataArray = cachedData.results;
}
cachedDataArray.forEach(r => joinedMoleculeLists.push(Object.assign({ site: site }, r)));
cachedDataArray.forEach(r => {
let result = getNumberFromCode(r.protein_code);
joinedMoleculeLists.push(Object.assign({ site: site, number: result.number }, r));
});
});
}
return joinedMoleculeLists;
Expand Down

0 comments on commit 833b39e

Please sign in to comment.