Skip to content

Commit

Permalink
- #1190 - compounds for LHS
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskovar-m2ms committed Nov 16, 2023
1 parent 2272353 commit 155a96b
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 89 deletions.
8 changes: 7 additions & 1 deletion js/components/preview/molecule/moleculeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import useDisableNglControlButtons from './useDisableNglControlButtons';
import GroupNglControlButtonsContext from './groupNglControlButtonsContext';
import { extractTargetFromURLParam } from '../utils';
import { LoadingContext } from '../../loading';
import { DJANGO_CONTEXT } from '../../../utils/djangoContext';

const useStyles = makeStyles(theme => ({
container: {
Expand Down Expand Up @@ -898,7 +899,12 @@ export const MoleculeList = memo(({ hideProjects }) => {

<IconButton
color={'inherit'}
disabled={!joinedMoleculeListsCopy.length || noTagsReceived || !tags.length}
disabled={
!joinedMoleculeListsCopy.length ||
noTagsReceived ||
!tags.length ||
DJANGO_CONTEXT['username'] === 'NOT_LOGGED_IN'
}
onClick={event => {
if (isTagEditorOpen === false) {
setTagEditorAnchorEl(event.currentTarget);
Expand Down
8 changes: 8 additions & 0 deletions js/components/preview/tags/api/tagsApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ export const getAllDataNew = async targetId => {
});
};

export const getCompoundsLHS = async targetId => {
return api({ url: `${base_url}/api/cmpdimg/?target=${targetId}` }).then(response => {
if (response?.data) {
return response.data?.results;
}
});
};

export const getTagMolecules = targetId => {
return api({ url: `${base_url}/api/siteobservation_tag/?target=${targetId}` })
.then(response => {
Expand Down
123 changes: 38 additions & 85 deletions js/components/preview/tags/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ import {
setCategoryList,
setTargetDataLoadingInProgress,
setAllDataLoaded,
setMoleculeTags
setMoleculeTags,
setLHSCompoundsLIst
} from '../../../../reducers/api/actions';
import { setSortDialogOpen } from '../../molecule/redux/actions';
import { resetCurrentCompoundsSettings } from '../../compounds/redux/actions';
import { updateExistingTag, getTags, getAllDataNew, getTagCategories } from '../api/tagsApi';
import { updateExistingTag, getTags, getAllDataNew, getTagCategories, getCompoundsLHS } from '../api/tagsApi';
import {
getMoleculeTagForTag,
createMoleculeTagObject,
Expand Down Expand Up @@ -169,62 +170,6 @@ export const unselectTag = tag => (dispatch, getState) => {
}
};

// export const loadMoleculesAndTags = targetId => async (dispatch, getState) => {
// return getAllData(targetId).then(data => {
// let tags_info = [];
// if (data.tags_info && data.tags_info.length > 0) {
// dispatch(setNoTagsReceived(false));
// data.tags_info.forEach(tag => {
// let newObject = {};
// Object.keys(tag.data[0]).forEach(prop => {
// newObject[`${prop}`] = tag.data[0][`${prop}`];
// });
// let coords = {};
// if (tag.coords && tag.coords.length > 1) {
// Object.keys(tag.coords[0]).forEach(prop => {
// coords[`${prop}`] = tag.coords[0][`${prop}`];
// });
// }
// newObject['coords'] = coords;

// if (!newObject.additional_info) {
// tags_info.push(newObject);
// }
// });
// }

// let allMolecules = [];
// data.molecules.forEach(mol => {
// let newObject = {};
// Object.keys(mol.data).forEach(prop => {
// newObject[`${prop}`] = mol.data[`${prop}`];
// });
// newObject['tags_set'] = mol.tags_set;

// allMolecules.push(newObject);
// });
// allMolecules.sort((a, b) => {
// if (a.protein_code < b.protein_code) {
// return -1;
// }
// if (a.protein_code > b.protein_code) {
// return 1;
// }
// return 0;
// });
// dispatch(setAllMolLists([...allMolecules]));

// //need to do this this way because only categories which have at least one tag assigned are sent from backend
// const categories = getCategoryIds();
// tags_info = tags_info.sort(compareTagsAsc);
// dispatch(setTagSelectorData(categories, tags_info));
// dispatch(setAllDataLoaded(true));
// // dispatch(setTargetDataLoadingInProgress(false));
// //console.log(tags_info);
// });
// // }
// };

const getTagsForMol = (molId, tagList) => {
const result = tagList.filter(t => t.site_observations.includes(molId));
return result;
Expand All @@ -237,34 +182,42 @@ export const loadMoleculesAndTagsNew = targetId => async (dispatch, getState) =>
dispatch(setNoTagsReceived(false));
}
const tagCategories = await getTagCategories();
return getAllDataNew(targetId).then(data => {
let allMolecules = [];
data?.results?.forEach(mol => {
let newObject = { ...mol };
const tagsForMol = getTagsForMol(mol.id, tags);
if (tagsForMol) {
newObject['tags_set'] = [...tagsForMol.map(t => t.id)];
} else {
newObject['tags_set'] = [];
}
allMolecules.push(newObject);
});

allMolecules?.sort((a, b) => {
if (a.code < b.code) {
return -1;
}
if (a.code > b.code) {
return 1;
}
return 0;
});
const data = await getAllDataNew(targetId);
let allMolecules = [];
data?.results?.forEach(mol => {
let newObject = { ...mol };
const tagsForMol = getTagsForMol(mol.id, tags);
if (tagsForMol) {
newObject['tags_set'] = [...tagsForMol.map(t => t.id)];
} else {
newObject['tags_set'] = [];
}
allMolecules.push(newObject);
});

dispatch(setAllMolLists([...allMolecules]));
//need to do this this way because only categories which have at least one tag assigned are sent from backend
tags = tags.sort(compareTagsAsc);
dispatch(setMoleculeTags(tags));
dispatch(setTagSelectorData(tagCategories, tags));
dispatch(setAllDataLoaded(true));
allMolecules?.sort((a, b) => {
if (a.code < b.code) {
return -1;
}
if (a.code > b.code) {
return 1;
}
return 0;
});

dispatch(setAllMolLists([...allMolecules]));
//need to do this this way because only categories which have at least one tag assigned are sent from backend
tags = tags.sort(compareTagsAsc);
dispatch(setMoleculeTags(tags));
dispatch(setTagSelectorData(tagCategories, tags));
dispatch(setAllDataLoaded(true));

return getCompoundsLHS(targetId).then(compounds => {
compounds?.forEach(c => {
const siteObs = allMolecules.find(m => m.cmpd === c.id);
c['smiles'] = siteObs ? siteObs.smiles : '';
});
dispatch(setLHSCompoundsLIst([...compounds]));
});
};
7 changes: 7 additions & 0 deletions js/reducers/api/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ export const setAllMolLists = all_mol_lists => {
};
};

export const setLHSCompoundsLIst = lhs_compounds_list => {
return {
type: constants.SET_LHS_COMPOUNDS_LIST,
lhs_compounds_list: lhs_compounds_list
};
};

export const setMoleculeTags = moleculeTags => {
return {
type: constants.SET_MOLECULE_TAGS,
Expand Down
9 changes: 7 additions & 2 deletions js/reducers/api/apiReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export const INITIAL_STATE = {
tagList: [],
categoryList: [],
target_data_loading_in_progress: false,
all_data_loaded: false
all_data_loaded: false,
lhs_compounds_list: []
};

export const RESET_TARGET_STATE = {
Expand Down Expand Up @@ -90,7 +91,8 @@ export const RESET_TARGET_STATE = {
tagList: [],
target_data_loading_in_progress: false,
all_data_loaded: false,
snapshotLoadingInProgress: false
snapshotLoadingInProgress: false,
lhs_compounds_list: []
};

export default function apiReducers(state = INITIAL_STATE, action = {}) {
Expand Down Expand Up @@ -174,6 +176,9 @@ export default function apiReducers(state = INITIAL_STATE, action = {}) {
return state;
}

case constants.SET_LHS_COMPOUNDS_LIST:
return { ...state, lhs_compounds_list: action.lhs_compounds_list };

case constants.SET_PANNDA_EVENT_LIST:
return Object.assign({}, state, {
pandda_event_list: action.pandda_event_list
Expand Down
3 changes: 2 additions & 1 deletion js/reducers/api/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ export const constants = {
SET_CATEGORY_LIST: prefix + 'SET_CATEGORY_LIST',
SET_TARGET_DATA_LOADING_IN_PROGRESS: prefix + 'SET_TARGET_DATA_LOADING_IN_PROGRESS',
SET_ALL_DATA_LOADED: prefix + 'SET_ALL_DATA_LOADED',
SET_SNAPSHOT_LOADING_IN_PROGRESS: prefix + 'SET_SNAPSHOT_LOADING_IN_PROGRESS'
SET_SNAPSHOT_LOADING_IN_PROGRESS: prefix + 'SET_SNAPSHOT_LOADING_IN_PROGRESS',
SET_LHS_COMPOUNDS_LIST: prefix + 'SET_LHS_COMPOUNDS_LIST'
};

0 comments on commit 155a96b

Please sign in to comment.