Skip to content
Snippets Groups Projects
Commit 4b4b1c4b authored by Piotr Gawron's avatar Piotr Gawron
Browse files

visualization of kinetics elements

parent b5a4d8a7
No related branches found
No related tags found
1 merge request!186Resolve "upload of sbml"
...@@ -27,7 +27,7 @@ function Alias(javaObject) { ...@@ -27,7 +27,7 @@ function Alias(javaObject) {
} }
if (this._modelId === undefined) { 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) { if (javaObject.name === undefined) {
...@@ -71,10 +71,16 @@ Alias.prototype.update = function (javaObject) { ...@@ -71,10 +71,16 @@ Alias.prototype.update = function (javaObject) {
this.setCompartmentId(javaObject.getCompartmentId()); this.setCompartmentId(javaObject.getCompartmentId());
this.setDescription(javaObject.getDescription()); 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.setX(javaObject.getX());
this.setY(javaObject.getY()); this.setY(javaObject.getY());
this.setWidth(javaObject.getWidth()); this.setWidth(javaObject.getWidth());
this.setHeight(javaObject.getHeight()); this.setHeight(javaObject.getHeight());
this.setIsComplete(true); this.setIsComplete(true);
} else { } else {
if (javaObject.name === undefined) { if (javaObject.name === undefined) {
...@@ -98,6 +104,11 @@ Alias.prototype.update = function (javaObject) { ...@@ -98,6 +104,11 @@ Alias.prototype.update = function (javaObject) {
this.setLinkedSubmodelId(javaObject.linkedSubmodel); this.setLinkedSubmodelId(javaObject.linkedSubmodel);
this.setCompartmentId(javaObject.compartmentId); this.setCompartmentId(javaObject.compartmentId);
this.setConstant(javaObject.constant);
this.setBoundaryCondition(javaObject.boundaryCondition);
this.setInitialAmount(javaObject.initialAmount);
this.setInitialConcentration(javaObject.initialConcentration);
if (javaObject.bounds !== undefined) { if (javaObject.bounds !== undefined) {
this.setX(javaObject.bounds.x); this.setX(javaObject.bounds.x);
...@@ -112,11 +123,38 @@ Alias.prototype.update = function (javaObject) { ...@@ -112,11 +123,38 @@ Alias.prototype.update = function (javaObject) {
Alias.prototype.getCharge = function () { Alias.prototype.getCharge = function () {
return this.charge; return this.charge;
}; };
Alias.prototype.setCharge = function (charge) { Alias.prototype.setCharge = function (charge) {
this.charge = 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 () { Alias.prototype.getFormerSymbols = function () {
return this.formerSymbols; return this.formerSymbols;
}; };
......
...@@ -87,7 +87,12 @@ ReactionInfoWindow.prototype.createContentDiv = function () { ...@@ -87,7 +87,12 @@ ReactionInfoWindow.prototype.createContentDiv = function () {
return Promise.all(promises); return Promise.all(promises);
}).then(function (parameters) { }).then(function (parameters) {
result.appendChild(self.createSbmlParameterDiv(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); return Promise.resolve(result);
}); });
} }
...@@ -134,6 +139,20 @@ ReactionInfoWindow.prototype.createSbmlParameterDiv = function (parameters) { ...@@ -134,6 +139,20 @@ ReactionInfoWindow.prototype.createSbmlParameterDiv = function (parameters) {
return result; 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 () { ReactionInfoWindow.prototype.init = function () {
var self = this; var self = this;
return AbstractInfoWindow.prototype.init.call(this).then(function () { return AbstractInfoWindow.prototype.init.call(this).then(function () {
......
...@@ -116,5 +116,21 @@ describe('ReactionInfoWindow', function () { ...@@ -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"); 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");
});
});
}); });
}); });
...@@ -29,268 +29,289 @@ import lcsb.mapviewer.services.view.OverviewImageViewFactory; ...@@ -29,268 +29,289 @@ import lcsb.mapviewer.services.view.OverviewImageViewFactory;
@Transactional(value = "txManager") @Transactional(value = "txManager")
public class ElementsRestImpl extends BaseRestImpl { public class ElementsRestImpl extends BaseRestImpl {
/** /**
* Default class logger. * Default class logger.
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
private Logger logger = Logger.getLogger(ElementsRestImpl.class); private Logger logger = Logger.getLogger(ElementsRestImpl.class);
@Autowired @Autowired
private OverviewImageViewFactory factory; private OverviewImageViewFactory factory;
public List<Map<String, Object>> getElements(String projectId, String id, String columns, String modelId, String token, String type, public List<Map<String, Object>> getElements(String projectId, String id, String columns, String modelId,
String includedCompartmentIds, String excludedCompartmentIds) throws UserAccessException, SecurityException { String token, String type, String includedCompartmentIds, String excludedCompartmentIds)
Set<Integer> ids = new HashSet<>(); throws UserAccessException, SecurityException {
if (!id.equals("")) { Set<Integer> ids = new HashSet<>();
for (String str : id.split(",")) { if (!id.equals("")) {
ids.add(Integer.valueOf(str)); for (String str : id.split(",")) {
} ids.add(Integer.valueOf(str));
} }
Set<String> types = new HashSet<>(); }
if (!type.isEmpty()) { Set<String> types = new HashSet<>();
for (String str : type.split(",")) { if (!type.isEmpty()) {
types.add(str.toLowerCase()); for (String str : type.split(",")) {
} types.add(str.toLowerCase());
} }
List<Model> models = getModels(projectId, modelId, token); }
List<Model> models = getModels(projectId, modelId, token);
Set<Compartment> includedCompartments = getCompartments(includedCompartmentIds, models); Set<Compartment> includedCompartments = getCompartments(includedCompartmentIds, models);
Set<Compartment> excludedCompartments = getCompartments(excludedCompartmentIds, models); Set<Compartment> excludedCompartments = getCompartments(excludedCompartmentIds, models);
Set<String> columnsSet = createElementColumnSet(columns); Set<String> columnsSet = createElementColumnSet(columns);
List<Map<String, Object>> result = new ArrayList<>(); List<Map<String, Object>> result = new ArrayList<>();
for (Model model2 : models) { for (Model model2 : models) {
for (Element element : model2.getElements()) { for (Element element : model2.getElements()) {
if (ids.size() == 0 || ids.contains(element.getId())) { if (ids.size() == 0 || ids.contains(element.getId())) {
if (types.size() == 0 || types.contains(element.getStringType().toLowerCase())) { if (types.size() == 0 || types.contains(element.getStringType().toLowerCase())) {
if (matchIncludedExcludedCompartments(element, includedCompartments, excludedCompartments)) { if (matchIncludedExcludedCompartments(element, includedCompartments, excludedCompartments)) {
result.add(preparedElement(element, columnsSet)); result.add(preparedElement(element, columnsSet));
} }
} }
} }
} }
} }
return result; return result;
} }
private boolean matchIncludedExcludedCompartments(Element element, Set<Compartment> includedCompartments, Set<Compartment> excludedCompartments) { private boolean matchIncludedExcludedCompartments(Element element, Set<Compartment> includedCompartments,
boolean matchIncluded = true; Set<Compartment> excludedCompartments) {
boolean matchExcluded = false; boolean matchIncluded = true;
boolean matchExcluded = false;
if (includedCompartments.size() > 0) { if (includedCompartments.size() > 0) {
matchIncluded = matchCompartments(element, includedCompartments); matchIncluded = matchCompartments(element, includedCompartments);
} }
if (excludedCompartments.size() > 0) { if (excludedCompartments.size() > 0) {
matchExcluded = matchCompartments(element, excludedCompartments); matchExcluded = matchCompartments(element, excludedCompartments);
} }
return matchIncluded && !matchExcluded; return matchIncluded && !matchExcluded;
} }
private boolean matchCompartments(Element element, Set<Compartment> compartmentList) { private boolean matchCompartments(Element element, Set<Compartment> compartmentList) {
boolean isInside = false; boolean isInside = false;
if (element != null) { if (element != null) {
for (Compartment compartment : compartmentList) { for (Compartment compartment : compartmentList) {
if (compartment.contains(element) && element.getModel().getId().equals(compartment.getModel().getId())) { if (compartment.contains(element) && element.getModel().getId().equals(compartment.getModel().getId())) {
isInside = true; isInside = true;
} }
} }
} }
return isInside; return isInside;
} }
private Set<Compartment> getCompartments(String includedCompartmentIds, List<Model> models) { private Set<Compartment> getCompartments(String includedCompartmentIds, List<Model> models) {
Set<Compartment> includedCompartments = new HashSet<>(); Set<Compartment> includedCompartments = new HashSet<>();
int count = 0; int count = 0;
if (!includedCompartmentIds.isEmpty()) { if (!includedCompartmentIds.isEmpty()) {
for (String compartmentId : includedCompartmentIds.split(",")) { for (String compartmentId : includedCompartmentIds.split(",")) {
Integer integerId = Integer.valueOf(compartmentId); Integer integerId = Integer.valueOf(compartmentId);
for (Model model : models) { for (Model model : models) {
Compartment compartment = model.getElementByDbId(integerId); Compartment compartment = model.getElementByDbId(integerId);
if (compartment != null) { if (compartment != null) {
includedCompartments.add(compartment); includedCompartments.add(compartment);
} }
} }
count++; count++;
} }
if (count > 0 && includedCompartments.size() == 0) { if (count > 0 && includedCompartments.size() == 0) {
includedCompartments.add(new Compartment("empty_comp_to_reject_all_elements")); includedCompartments.add(new Compartment("empty_comp_to_reject_all_elements"));
} }
} }
return includedCompartments; return includedCompartments;
} }
private Map<String, Object> preparedElement(Element element, Set<String> columnsSet) { private Map<String, Object> preparedElement(Element element, Set<String> columnsSet) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
for (String string : columnsSet) { for (String string : columnsSet) {
String column = string.toLowerCase(); String column = string.toLowerCase();
Object value = null; Object value = null;
if (column.equals("id") || column.equals("idobject")) { if (column.equals("id") || column.equals("idobject")) {
value = element.getId(); value = element.getId();
} else if (column.equals("modelid")) { } else if (column.equals("modelid")) {
value = element.getModelData().getId(); value = element.getModelData().getId();
} else if (column.equals("elementid")) { } else if (column.equals("elementid")) {
value = element.getElementId(); value = element.getElementId();
} else if (column.equals("name")) { } else if (column.equals("name")) {
value = element.getName(); value = element.getName();
} else if (column.equals("type")) { } else if (column.equals("type")) {
value = element.getStringType(); value = element.getStringType();
} else if (column.equals("symbol")) { } else if (column.equals("symbol")) {
value = element.getSymbol(); value = element.getSymbol();
} else if (column.equals("fullname")) { } else if (column.equals("fullname")) {
value = element.getFullName(); value = element.getFullName();
} else if (column.equals("abbreviation")) { } else if (column.equals("abbreviation")) {
value = element.getAbbreviation(); value = element.getAbbreviation();
} else if (column.equals("compartmentid")) { } else if (column.equals("compartmentid")) {
if (element.getCompartment() != null) { if (element.getCompartment() != null) {
value = element.getCompartment().getId(); value = element.getCompartment().getId();
} }
} else if (column.equals("complexid")) { } else if (column.equals("complexid")) {
if (element instanceof Species) { if (element instanceof Species) {
if (((Species) element).getComplex() != null) { if (((Species) element).getComplex() != null) {
value = ((Species) element).getComplex().getId(); value = ((Species) element).getComplex().getId();
} }
} }
} else if (column.equals("references")) { } else if (column.equals("initialconcentration")) {
value = createAnnotations(element.getMiriamData()); if (element instanceof Species) {
} else if (column.equals("synonyms")) { value = ((Species) element).getInitialConcentration();
value = element.getSynonyms(); }
} else if (column.equals("formula")) { } else if (column.equals("initialamount")) {
value = element.getFormula(); if (element instanceof Species) {
} else if (column.equals("notes")) { value = ((Species) element).getInitialAmount();
value = element.getNotes(); }
} else if (column.equals("other")) { } else if (column.equals("boundarycondition")) {
value = getOthersForElement(element); if (element instanceof Species) {
} else if (column.equals("formersymbols")) { value = ((Species) element).getBoundaryCondition();
value = element.getFormerSymbols(); }
} else if (column.equals("hierarchyvisibilitylevel")) { } else if (column.equals("constant")) {
value = element.getVisibilityLevel(); if (element instanceof Species) {
} else if (column.equals("linkedsubmodel")) { value = ((Species) element).getConstant();
if (element.getSubmodel() != null) { }
value = element.getSubmodel().getSubmodel().getId(); } else if (column.equals("references")) {
} value = createAnnotations(element.getMiriamData());
} else if (column.equals("bounds")) { } else if (column.equals("synonyms")) {
value = createBounds(element.getX(), element.getY(), element.getWidth(), element.getHeight()); value = element.getSynonyms();
} } else if (column.equals("formula")) {
else { value = element.getFormula();
value = "Unknown column"; } else if (column.equals("notes")) {
} value = element.getNotes();
result.put(string, value); } else if (column.equals("other")) {
} value = getOthersForElement(element);
return result; } 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) { protected Map<String, Object> getOthersForElement(Element element) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
List<Map<String, Object>> modifications = new ArrayList<>(); List<Map<String, Object>> modifications = new ArrayList<>();
String structuralState = null; String structuralState = null;
Map<String, Object> structures = new HashMap<>(); Map<String, Object> structures = new HashMap<>();
if (element instanceof Protein) { if (element instanceof Protein) {
Protein protein = ((Protein) element); Protein protein = ((Protein) element);
modifications = getModifications(protein.getModificationResidues()); modifications = getModifications(protein.getModificationResidues());
structuralState = protein.getStructuralState(); structuralState = protein.getStructuralState();
} else if (element instanceof Rna) { } else if (element instanceof Rna) {
Rna rna = ((Rna) element); Rna rna = ((Rna) element);
modifications = getModifications(((Rna) element).getRegions()); modifications = getModifications(((Rna) element).getRegions());
structuralState = rna.getState(); structuralState = rna.getState();
} else if (element instanceof AntisenseRna) { } else if (element instanceof AntisenseRna) {
AntisenseRna antisenseRna = ((AntisenseRna) element); AntisenseRna antisenseRna = ((AntisenseRna) element);
modifications = getModifications(((AntisenseRna) element).getRegions()); modifications = getModifications(((AntisenseRna) element).getRegions());
structuralState = antisenseRna.getState(); structuralState = antisenseRna.getState();
} }
if (element instanceof Species) { if (element instanceof Species) {
structures = getStructures(((Species)element).getUniprots()); structures = getStructures(((Species) element).getUniprots());
} }
result.put("modifications", modifications); result.put("modifications", modifications);
result.put("structuralState", structuralState); result.put("structuralState", structuralState);
result.put("structures", structures); result.put("structures", structures);
return result; return result;
} }
private List<Map<String, Object>> getModifications(List<? extends ElementModification> elements) { private List<Map<String, Object>> getModifications(List<? extends ElementModification> elements) {
List<Map<String, Object>> result = new ArrayList<>(); List<Map<String, Object>> result = new ArrayList<>();
for (ElementModification region : elements) { for (ElementModification region : elements) {
if (region.getState() != null) { if (region.getState() != null) {
Map<String, Object> row = new HashMap<>(); Map<String, Object> row = new HashMap<>();
row.put("name", region.getName()); row.put("name", region.getName());
String state = region.getState().name(); String state = region.getState().name();
row.put("state", state); row.put("state", state);
result.add(row); result.add(row);
} }
} }
return result; 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 Map<String, Object> createBounds(Double x, Double y, Double width, Double height) { private Map<String, Object> getStructures(Set<UniprotRecord> uniprots) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
result.put("x", x); for (UniprotRecord uniprotRec : uniprots) {
result.put("y", y); Set<Object> structs = new HashSet<>();
result.put("width", width); for (Structure struct : uniprotRec.getStructures()) {
result.put("height", height); structs.add(struct.toMap());
return result; }
} result.put(uniprotRec.getUniprotId(), structs);
}
return result;
}
private Set<String> createElementColumnSet(String columns) { private Map<String, Object> createBounds(Double x, Double y, Double width, Double height) {
Set<String> columnsSet = new HashSet<>(); Map<String, Object> result = new HashMap<>();
if (columns.equals("")) { result.put("x", x);
columnsSet.add("id"); result.put("y", y);
columnsSet.add("elementId"); result.put("width", width);
columnsSet.add("modelId"); result.put("height", height);
columnsSet.add("name"); return result;
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 Set<String> createElementColumnSet(String columns) {
* @return the factory Set<String> columnsSet = new HashSet<>();
* @see #factory if (columns.equals("")) {
*/ columnsSet.add("id");
public OverviewImageViewFactory getFactory() { columnsSet.add("elementId");
return factory; 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 * @return the factory
* the factory to set * @see #factory
* @see #factory */
*/ public OverviewImageViewFactory getFactory() {
public void setFactory(OverviewImageViewFactory factory) { return factory;
this.factory = factory; }
}
/**
* @param factory
* the factory to set
* @see #factory
*/
public void setFactory(OverviewImageViewFactory factory) {
this.factory = factory;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment