From 4b4b1c4b1a2bb21c2c6506f143d1c59c24fb6d33 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Fri, 9 Feb 2018 16:02:04 +0100 Subject: [PATCH] visualization of kinetics elements --- frontend-js/src/main/js/map/data/Alias.js | 42 +- .../main/js/map/window/ReactionInfoWindow.js | 19 + .../js/map/window/ReactionInfoWindow-test.js | 16 + .../elements/ElementsRestImpl.java | 511 +++++++++--------- 4 files changed, 341 insertions(+), 247 deletions(-) diff --git a/frontend-js/src/main/js/map/data/Alias.js b/frontend-js/src/main/js/map/data/Alias.js index e1d30f6f0c..d66344e007 100644 --- a/frontend-js/src/main/js/map/data/Alias.js +++ b/frontend-js/src/main/js/map/data/Alias.js @@ -27,7 +27,7 @@ function Alias(javaObject) { } if (this._modelId === undefined) { - throw new Error("ModelId is not defined for alias"); + throw new Error("ModelId is not defined for alias" + javaObject); } if (javaObject.name === undefined) { @@ -71,10 +71,16 @@ Alias.prototype.update = function (javaObject) { this.setCompartmentId(javaObject.getCompartmentId()); this.setDescription(javaObject.getDescription()); + this.setConstant(javaObject.getConstant()); + this.setBoundaryCondition(javaObject.getBoundaryCondition()); + this.setInitialAmount(javaObject.getInitialAmount()); + this.setInitialConcentration(javaObject.getInitialConcentration()); + this.setX(javaObject.getX()); this.setY(javaObject.getY()); this.setWidth(javaObject.getWidth()); this.setHeight(javaObject.getHeight()); + this.setIsComplete(true); } else { if (javaObject.name === undefined) { @@ -98,6 +104,11 @@ Alias.prototype.update = function (javaObject) { this.setLinkedSubmodelId(javaObject.linkedSubmodel); this.setCompartmentId(javaObject.compartmentId); + this.setConstant(javaObject.constant); + this.setBoundaryCondition(javaObject.boundaryCondition); + this.setInitialAmount(javaObject.initialAmount); + this.setInitialConcentration(javaObject.initialConcentration); + if (javaObject.bounds !== undefined) { this.setX(javaObject.bounds.x); @@ -112,11 +123,38 @@ Alias.prototype.update = function (javaObject) { Alias.prototype.getCharge = function () { return this.charge; }; - Alias.prototype.setCharge = function (charge) { this.charge = charge; }; +Alias.prototype.getConstant = function () { + return this._constant; +}; +Alias.prototype.setConstant = function (constant) { + this._constant = constant; +}; + +Alias.prototype.getBoundaryCondition = function () { + return this._boundaryCondition; +}; +Alias.prototype.setBoundaryCondition = function (boundaryCondition) { + this._boundaryCondition = boundaryCondition; +}; + +Alias.prototype.getInitialAmount = function () { + return this._initialAmount; +}; +Alias.prototype.setInitialAmount = function (initialAmount) { + this._initialAmount = initialAmount; +}; + +Alias.prototype.getInitialConcentration = function () { + return this._initialConcentration; +}; +Alias.prototype.setInitialConcentration = function (initialConcentration) { + this._initialConcentration = initialConcentration; +}; + Alias.prototype.getFormerSymbols = function () { return this.formerSymbols; }; diff --git a/frontend-js/src/main/js/map/window/ReactionInfoWindow.js b/frontend-js/src/main/js/map/window/ReactionInfoWindow.js index f687e2f4a3..1f566037b9 100644 --- a/frontend-js/src/main/js/map/window/ReactionInfoWindow.js +++ b/frontend-js/src/main/js/map/window/ReactionInfoWindow.js @@ -87,7 +87,12 @@ ReactionInfoWindow.prototype.createContentDiv = function () { return Promise.all(promises); }).then(function (parameters) { result.appendChild(self.createSbmlParameterDiv(parameters)); + result.appendChild(self.createKineticsElementsDiv(reaction.getElements())); + if (global.MathJax !== undefined) { + return MathJax.Hub.Queue(["Typeset", MathJax.Hub]); + } + }).then(function () { return Promise.resolve(result); }); } @@ -134,6 +139,20 @@ ReactionInfoWindow.prototype.createSbmlParameterDiv = function (parameters) { return result; }; +ReactionInfoWindow.prototype.createKineticsElementsDiv = function (elements) { + var result = Functions.createElement({type: "div"}); + result.appendChild(Functions.createElement({type: "h5", content: "Elements: "})); + var guiUtils = new GuiUtils(); + var table = Functions.createElement({type: "div", style: "display: table;", className: "borderTable"}); + table.appendChild(guiUtils.createTableRow(["Name", "elementId", "Constant", "Boundary condition", "Initial concentration", "Initial amount"])); + for (var i = 0; i < elements.length; i++) { + var element = elements[i]; + table.appendChild(guiUtils.createTableRow([element.getName(), element.getElementId(), element.getConstant(), element.getBoundaryCondition(), element.getInitialConcentration(), element.getInitialAmount()])); + } + result.appendChild(table); + return result; +}; + ReactionInfoWindow.prototype.init = function () { var self = this; return AbstractInfoWindow.prototype.init.call(this).then(function () { diff --git a/frontend-js/src/test/js/map/window/ReactionInfoWindow-test.js b/frontend-js/src/test/js/map/window/ReactionInfoWindow-test.js index 88705cfd9c..125ab1088d 100644 --- a/frontend-js/src/test/js/map/window/ReactionInfoWindow-test.js +++ b/frontend-js/src/test/js/map/window/ReactionInfoWindow-test.js @@ -116,5 +116,21 @@ describe('ReactionInfoWindow', function () { assert.ok(div.innerHTML.indexOf(sbmlParameter.getValue()[0]) >= 0, "Parameter value doesn't exist in the output div"); }); }); + it("elements", function () { + var map = helper.createCustomMap(); + + var reaction = helper.createReaction(map, true); + reaction.setKineticLaw(helper.createKineticLaw()); + + var reactionWindow = new ReactionInfoWindow({ + reaction: reaction, + map: map + }); + + return reactionWindow.createContentDiv().then(function (div) { + assert.ok(div.innerHTML.indexOf("Elements") >= 0); + assert.ok(div.innerHTML.indexOf(reaction.getElements()[0].getName()) >= 0, "Element name doesn't exist in the output div"); + }); + }); }); }); diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementsRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementsRestImpl.java index 4bfea6bdc2..328584b778 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementsRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementsRestImpl.java @@ -29,268 +29,289 @@ import lcsb.mapviewer.services.view.OverviewImageViewFactory; @Transactional(value = "txManager") public class ElementsRestImpl extends BaseRestImpl { - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private Logger logger = Logger.getLogger(ElementsRestImpl.class); + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private Logger logger = Logger.getLogger(ElementsRestImpl.class); - @Autowired - private OverviewImageViewFactory factory; + @Autowired + private OverviewImageViewFactory factory; - public List<Map<String, Object>> getElements(String projectId, String id, String columns, String modelId, String token, String type, - String includedCompartmentIds, String excludedCompartmentIds) throws UserAccessException, SecurityException { - Set<Integer> ids = new HashSet<>(); - if (!id.equals("")) { - for (String str : id.split(",")) { - ids.add(Integer.valueOf(str)); - } - } - Set<String> types = new HashSet<>(); - if (!type.isEmpty()) { - for (String str : type.split(",")) { - types.add(str.toLowerCase()); - } - } - List<Model> models = getModels(projectId, modelId, token); + public List<Map<String, Object>> getElements(String projectId, String id, String columns, String modelId, + String token, String type, String includedCompartmentIds, String excludedCompartmentIds) + throws UserAccessException, SecurityException { + Set<Integer> ids = new HashSet<>(); + if (!id.equals("")) { + for (String str : id.split(",")) { + ids.add(Integer.valueOf(str)); + } + } + Set<String> types = new HashSet<>(); + if (!type.isEmpty()) { + for (String str : type.split(",")) { + types.add(str.toLowerCase()); + } + } + List<Model> models = getModels(projectId, modelId, token); - Set<Compartment> includedCompartments = getCompartments(includedCompartmentIds, models); - Set<Compartment> excludedCompartments = getCompartments(excludedCompartmentIds, models); - Set<String> columnsSet = createElementColumnSet(columns); + Set<Compartment> includedCompartments = getCompartments(includedCompartmentIds, models); + Set<Compartment> excludedCompartments = getCompartments(excludedCompartmentIds, models); + Set<String> columnsSet = createElementColumnSet(columns); - List<Map<String, Object>> result = new ArrayList<>(); + List<Map<String, Object>> result = new ArrayList<>(); - for (Model model2 : models) { - for (Element element : model2.getElements()) { - if (ids.size() == 0 || ids.contains(element.getId())) { - if (types.size() == 0 || types.contains(element.getStringType().toLowerCase())) { - if (matchIncludedExcludedCompartments(element, includedCompartments, excludedCompartments)) { - result.add(preparedElement(element, columnsSet)); - } - } - } - } - } + for (Model model2 : models) { + for (Element element : model2.getElements()) { + if (ids.size() == 0 || ids.contains(element.getId())) { + if (types.size() == 0 || types.contains(element.getStringType().toLowerCase())) { + if (matchIncludedExcludedCompartments(element, includedCompartments, excludedCompartments)) { + result.add(preparedElement(element, columnsSet)); + } + } + } + } + } - return result; - } + return result; + } - private boolean matchIncludedExcludedCompartments(Element element, Set<Compartment> includedCompartments, Set<Compartment> excludedCompartments) { - boolean matchIncluded = true; - boolean matchExcluded = false; + private boolean matchIncludedExcludedCompartments(Element element, Set<Compartment> includedCompartments, + Set<Compartment> excludedCompartments) { + boolean matchIncluded = true; + boolean matchExcluded = false; - if (includedCompartments.size() > 0) { - matchIncluded = matchCompartments(element, includedCompartments); - } - if (excludedCompartments.size() > 0) { - matchExcluded = matchCompartments(element, excludedCompartments); - } + if (includedCompartments.size() > 0) { + matchIncluded = matchCompartments(element, includedCompartments); + } + if (excludedCompartments.size() > 0) { + matchExcluded = matchCompartments(element, excludedCompartments); + } - return matchIncluded && !matchExcluded; - } + return matchIncluded && !matchExcluded; + } - private boolean matchCompartments(Element element, Set<Compartment> compartmentList) { - boolean isInside = false; - if (element != null) { - for (Compartment compartment : compartmentList) { - if (compartment.contains(element) && element.getModel().getId().equals(compartment.getModel().getId())) { - isInside = true; - } - } - } - return isInside; - } + private boolean matchCompartments(Element element, Set<Compartment> compartmentList) { + boolean isInside = false; + if (element != null) { + for (Compartment compartment : compartmentList) { + if (compartment.contains(element) && element.getModel().getId().equals(compartment.getModel().getId())) { + isInside = true; + } + } + } + return isInside; + } - private Set<Compartment> getCompartments(String includedCompartmentIds, List<Model> models) { - Set<Compartment> includedCompartments = new HashSet<>(); - int count = 0; - if (!includedCompartmentIds.isEmpty()) { - for (String compartmentId : includedCompartmentIds.split(",")) { - Integer integerId = Integer.valueOf(compartmentId); - for (Model model : models) { - Compartment compartment = model.getElementByDbId(integerId); - if (compartment != null) { - includedCompartments.add(compartment); - } - } - count++; - } - if (count > 0 && includedCompartments.size() == 0) { - includedCompartments.add(new Compartment("empty_comp_to_reject_all_elements")); - } - } - return includedCompartments; - } + private Set<Compartment> getCompartments(String includedCompartmentIds, List<Model> models) { + Set<Compartment> includedCompartments = new HashSet<>(); + int count = 0; + if (!includedCompartmentIds.isEmpty()) { + for (String compartmentId : includedCompartmentIds.split(",")) { + Integer integerId = Integer.valueOf(compartmentId); + for (Model model : models) { + Compartment compartment = model.getElementByDbId(integerId); + if (compartment != null) { + includedCompartments.add(compartment); + } + } + count++; + } + if (count > 0 && includedCompartments.size() == 0) { + includedCompartments.add(new Compartment("empty_comp_to_reject_all_elements")); + } + } + return includedCompartments; + } - private Map<String, Object> preparedElement(Element element, Set<String> columnsSet) { - Map<String, Object> result = new HashMap<>(); - for (String string : columnsSet) { - String column = string.toLowerCase(); - Object value = null; - if (column.equals("id") || column.equals("idobject")) { - value = element.getId(); - } else if (column.equals("modelid")) { - value = element.getModelData().getId(); - } else if (column.equals("elementid")) { - value = element.getElementId(); - } else if (column.equals("name")) { - value = element.getName(); - } else if (column.equals("type")) { - value = element.getStringType(); - } else if (column.equals("symbol")) { - value = element.getSymbol(); - } else if (column.equals("fullname")) { - value = element.getFullName(); - } else if (column.equals("abbreviation")) { - value = element.getAbbreviation(); - } else if (column.equals("compartmentid")) { - if (element.getCompartment() != null) { - value = element.getCompartment().getId(); - } - } else if (column.equals("complexid")) { - if (element instanceof Species) { - if (((Species) element).getComplex() != null) { - value = ((Species) element).getComplex().getId(); - } - } - } else if (column.equals("references")) { - value = createAnnotations(element.getMiriamData()); - } else if (column.equals("synonyms")) { - value = element.getSynonyms(); - } else if (column.equals("formula")) { - value = element.getFormula(); - } else if (column.equals("notes")) { - value = element.getNotes(); - } else if (column.equals("other")) { - value = getOthersForElement(element); - } else if (column.equals("formersymbols")) { - value = element.getFormerSymbols(); - } else if (column.equals("hierarchyvisibilitylevel")) { - value = element.getVisibilityLevel(); - } else if (column.equals("linkedsubmodel")) { - if (element.getSubmodel() != null) { - value = element.getSubmodel().getSubmodel().getId(); - } - } else if (column.equals("bounds")) { - value = createBounds(element.getX(), element.getY(), element.getWidth(), element.getHeight()); - } - else { - value = "Unknown column"; - } - result.put(string, value); - } - return result; - } + private Map<String, Object> preparedElement(Element element, Set<String> columnsSet) { + Map<String, Object> result = new HashMap<>(); + for (String string : columnsSet) { + String column = string.toLowerCase(); + Object value = null; + if (column.equals("id") || column.equals("idobject")) { + value = element.getId(); + } else if (column.equals("modelid")) { + value = element.getModelData().getId(); + } else if (column.equals("elementid")) { + value = element.getElementId(); + } else if (column.equals("name")) { + value = element.getName(); + } else if (column.equals("type")) { + value = element.getStringType(); + } else if (column.equals("symbol")) { + value = element.getSymbol(); + } else if (column.equals("fullname")) { + value = element.getFullName(); + } else if (column.equals("abbreviation")) { + value = element.getAbbreviation(); + } else if (column.equals("compartmentid")) { + if (element.getCompartment() != null) { + value = element.getCompartment().getId(); + } + } else if (column.equals("complexid")) { + if (element instanceof Species) { + if (((Species) element).getComplex() != null) { + value = ((Species) element).getComplex().getId(); + } + } + } else if (column.equals("initialconcentration")) { + if (element instanceof Species) { + value = ((Species) element).getInitialConcentration(); + } + } else if (column.equals("initialamount")) { + if (element instanceof Species) { + value = ((Species) element).getInitialAmount(); + } + } else if (column.equals("boundarycondition")) { + if (element instanceof Species) { + value = ((Species) element).getBoundaryCondition(); + } + } else if (column.equals("constant")) { + if (element instanceof Species) { + value = ((Species) element).getConstant(); + } + } else if (column.equals("references")) { + value = createAnnotations(element.getMiriamData()); + } else if (column.equals("synonyms")) { + value = element.getSynonyms(); + } else if (column.equals("formula")) { + value = element.getFormula(); + } else if (column.equals("notes")) { + value = element.getNotes(); + } else if (column.equals("other")) { + value = getOthersForElement(element); + } else if (column.equals("formersymbols")) { + value = element.getFormerSymbols(); + } else if (column.equals("hierarchyvisibilitylevel")) { + value = element.getVisibilityLevel(); + } else if (column.equals("linkedsubmodel")) { + if (element.getSubmodel() != null) { + value = element.getSubmodel().getSubmodel().getId(); + } + } else if (column.equals("bounds")) { + value = createBounds(element.getX(), element.getY(), element.getWidth(), element.getHeight()); + } else { + value = "Unknown column"; + } + result.put(string, value); + } + return result; + } - protected Map<String, Object> getOthersForElement(Element element) { - Map<String, Object> result = new HashMap<>(); - List<Map<String, Object>> modifications = new ArrayList<>(); - String structuralState = null; - Map<String, Object> structures = new HashMap<>(); - if (element instanceof Protein) { - Protein protein = ((Protein) element); - modifications = getModifications(protein.getModificationResidues()); - structuralState = protein.getStructuralState(); - } else if (element instanceof Rna) { - Rna rna = ((Rna) element); - modifications = getModifications(((Rna) element).getRegions()); - structuralState = rna.getState(); - } else if (element instanceof AntisenseRna) { - AntisenseRna antisenseRna = ((AntisenseRna) element); - modifications = getModifications(((AntisenseRna) element).getRegions()); - structuralState = antisenseRna.getState(); - } - if (element instanceof Species) { - structures = getStructures(((Species)element).getUniprots()); - } - result.put("modifications", modifications); - result.put("structuralState", structuralState); - result.put("structures", structures); + protected Map<String, Object> getOthersForElement(Element element) { + Map<String, Object> result = new HashMap<>(); + List<Map<String, Object>> modifications = new ArrayList<>(); + String structuralState = null; + Map<String, Object> structures = new HashMap<>(); + if (element instanceof Protein) { + Protein protein = ((Protein) element); + modifications = getModifications(protein.getModificationResidues()); + structuralState = protein.getStructuralState(); + } else if (element instanceof Rna) { + Rna rna = ((Rna) element); + modifications = getModifications(((Rna) element).getRegions()); + structuralState = rna.getState(); + } else if (element instanceof AntisenseRna) { + AntisenseRna antisenseRna = ((AntisenseRna) element); + modifications = getModifications(((AntisenseRna) element).getRegions()); + structuralState = antisenseRna.getState(); + } + if (element instanceof Species) { + structures = getStructures(((Species) element).getUniprots()); + } + result.put("modifications", modifications); + result.put("structuralState", structuralState); + result.put("structures", structures); - return result; - } + return result; + } - private List<Map<String, Object>> getModifications(List<? extends ElementModification> elements) { - List<Map<String, Object>> result = new ArrayList<>(); - for (ElementModification region : elements) { - if (region.getState() != null) { - Map<String, Object> row = new HashMap<>(); - row.put("name", region.getName()); - String state = region.getState().name(); - row.put("state", state); - result.add(row); - } - } - return result; - } - - private Map<String, Object> getStructures(Set<UniprotRecord> uniprots) { - Map<String, Object> result = new HashMap<>(); - for (UniprotRecord uniprotRec : uniprots) { - Set<Object> structs = new HashSet<>(); - for (Structure struct: uniprotRec.getStructures()) { - structs.add(struct.toMap()); - } - result.put(uniprotRec.getUniprotId(), structs); - } - return result; - } + private List<Map<String, Object>> getModifications(List<? extends ElementModification> elements) { + List<Map<String, Object>> result = new ArrayList<>(); + for (ElementModification region : elements) { + if (region.getState() != null) { + Map<String, Object> row = new HashMap<>(); + row.put("name", region.getName()); + String state = region.getState().name(); + row.put("state", state); + result.add(row); + } + } + return result; + } - private Map<String, Object> createBounds(Double x, Double y, Double width, Double height) { - Map<String, Object> result = new HashMap<>(); - result.put("x", x); - result.put("y", y); - result.put("width", width); - result.put("height", height); - return result; - } + private Map<String, Object> getStructures(Set<UniprotRecord> uniprots) { + Map<String, Object> result = new HashMap<>(); + for (UniprotRecord uniprotRec : uniprots) { + Set<Object> structs = new HashSet<>(); + for (Structure struct : uniprotRec.getStructures()) { + structs.add(struct.toMap()); + } + result.put(uniprotRec.getUniprotId(), structs); + } + return result; + } - private Set<String> createElementColumnSet(String columns) { - Set<String> columnsSet = new HashSet<>(); - if (columns.equals("")) { - columnsSet.add("id"); - columnsSet.add("elementId"); - columnsSet.add("modelId"); - columnsSet.add("name"); - columnsSet.add("type"); - columnsSet.add("notes"); - columnsSet.add("type"); - columnsSet.add("symbol"); - columnsSet.add("complexId"); - columnsSet.add("compartmentId"); - columnsSet.add("fullName"); - columnsSet.add("abbreviation"); - columnsSet.add("formula"); - columnsSet.add("name"); - columnsSet.add("synonyms"); - columnsSet.add("formerSymbols"); - columnsSet.add("references"); - columnsSet.add("bounds"); - columnsSet.add("hierarchyVisibilityLevel"); - columnsSet.add("linkedSubmodel"); - columnsSet.add("other"); - } else { - for (String str : columns.split(",")) { - columnsSet.add(str); - } - } - return columnsSet; - } + private Map<String, Object> createBounds(Double x, Double y, Double width, Double height) { + Map<String, Object> result = new HashMap<>(); + result.put("x", x); + result.put("y", y); + result.put("width", width); + result.put("height", height); + return result; + } - /** - * @return the factory - * @see #factory - */ - public OverviewImageViewFactory getFactory() { - return factory; - } + private Set<String> createElementColumnSet(String columns) { + Set<String> columnsSet = new HashSet<>(); + if (columns.equals("")) { + columnsSet.add("id"); + columnsSet.add("elementId"); + columnsSet.add("modelId"); + columnsSet.add("name"); + columnsSet.add("type"); + columnsSet.add("notes"); + columnsSet.add("type"); + columnsSet.add("symbol"); + columnsSet.add("complexId"); + columnsSet.add("compartmentId"); + columnsSet.add("fullName"); + columnsSet.add("abbreviation"); + columnsSet.add("formula"); + columnsSet.add("name"); + columnsSet.add("synonyms"); + columnsSet.add("formerSymbols"); + columnsSet.add("references"); + columnsSet.add("bounds"); + columnsSet.add("hierarchyVisibilityLevel"); + columnsSet.add("linkedSubmodel"); + columnsSet.add("other"); + columnsSet.add("initialConcentration"); + columnsSet.add("boundaryCondition"); + columnsSet.add("constant"); + columnsSet.add("initialAmount"); + } else { + for (String str : columns.split(",")) { + columnsSet.add(str); + } + } + return columnsSet; + } - /** - * @param factory - * the factory to set - * @see #factory - */ - public void setFactory(OverviewImageViewFactory factory) { - this.factory = factory; - } + /** + * @return the factory + * @see #factory + */ + public OverviewImageViewFactory getFactory() { + return factory; + } + + /** + * @param factory + * the factory to set + * @see #factory + */ + public void setFactory(OverviewImageViewFactory factory) { + this.factory = factory; + } } -- GitLab