Skip to content
Snippets Groups Projects

issues that were discovered during biohackathon 2019 in Paris

Merged Piotr Gawron requested to merge wikipathways-issues into master
1 file
+ 2
4
Compare changes
  • Side-by-side
  • Inline
@@ -21,8 +21,7 @@ import lcsb.mapviewer.converter.model.celldesigner.types.ModifierTypeUtils;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.Drawable;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.*;
import lcsb.mapviewer.model.map.compartment.*;
import lcsb.mapviewer.model.map.layout.graphics.*;
import lcsb.mapviewer.model.map.model.Model;
@@ -31,7 +30,6 @@ import lcsb.mapviewer.model.map.reaction.*;
import lcsb.mapviewer.model.map.reaction.type.*;
import lcsb.mapviewer.model.map.species.*;
import lcsb.mapviewer.model.map.species.field.*;
import lcsb.mapviewer.modelutils.map.ElementUtils;
import lcsb.mapviewer.wikipathway.model.*;
import lcsb.mapviewer.wikipathway.model.biopax.BiopaxFactory;
@@ -70,6 +68,9 @@ public class ModelContructor {
INALID_COMPLEX_SHAPE_CHILDREN.add("Arc");
INALID_COMPLEX_SHAPE_CHILDREN.add("Triangle");
INALID_COMPLEX_SHAPE_CHILDREN.add("Hexagon");
INALID_COMPLEX_SHAPE_CHILDREN.add("None");
INALID_COMPLEX_SHAPE_CHILDREN.add("Pentagon");
INALID_COMPLEX_SHAPE_CHILDREN.add("mim-phosphorylated");
}
/**
@@ -96,11 +97,9 @@ public class ModelContructor {
*
* @param dataNode
* object from which species is created
* @param data
* ...
* @return {@link Species} created from input {@link DataNode}
*/
protected Species createSpecies(DataNode dataNode, Data data) {
protected Species createSpecies(DataNode dataNode) {
Species res = null;
String type = dataNode.getType();
if (type == null || type.equals("")) {
@@ -122,7 +121,7 @@ public class ModelContructor {
} else if (type != null && type.equalsIgnoreCase("None")) {
res = new Unknown(dataNode.getGraphId());
} else {
logger.warn("[" + dataNode.getGraphId() + "]\tUnknown species type: " + type + ". Using Unknown");
logger.warn(dataNode.getLogMarker(), "Unknown species type: " + type + ". Using Unknown");
res = new Unknown(dataNode.getGraphId());
}
@@ -140,37 +139,42 @@ public class ModelContructor {
* This function adds {@link Complex} to model from graph. ComplexName is set as
* groupId from GPML
*
* @param model
* to this model complexes will be added
* @param graph
* gpml data model
* @param groups
* list of groups
* @param data
* ...
*/
protected void addComplex(Model model, Graph graph, Data data) {
for (Group group : graph.getGroups()) {
Complex complex = new Complex(group.getGraphId());
complex.setName(group.getGraphId());
protected List<Element> createElementsFromGroup(Collection<Group> groups, Data data) {
List<Element> result = new ArrayList<>();
for (Group group : groups) {
Element element = null;
if ("Complex".equalsIgnoreCase(group.getStyle())) {
complex.setHypothetical(false);
element = new Complex(group.getGraphId());
((Complex) element).setHypothetical(false);
} else if ("Pathway".equalsIgnoreCase(group.getStyle())) {
element = new PathwayCompartment(group.getGraphId());
} else {
complex.setHypothetical(true);
element = new Complex(group.getGraphId());
((Complex) element).setHypothetical(true);
}
element.setName(group.getGraphId());
Rectangle2D rec = group.getRectangle();
if (rec == null) {
rec = new Rectangle2D.Double(0, 0, 0, 0);
}
complex.setX(rec.getX());
complex.setY(rec.getY());
complex.setWidth((int) rec.getWidth());
complex.setHeight((int) rec.getHeight());
complex.setZ(group.getzOrder());
complex.setFillColor(DEFAULT_COMPLEX_ALIAS_COLOR);
element.setX(rec.getX());
element.setY(rec.getY());
element.setWidth(rec.getWidth());
element.setHeight(rec.getHeight());
element.setZ(group.getzOrder());
element.setFillColor(DEFAULT_COMPLEX_ALIAS_COLOR);
data.id2alias.put(group.getGraphId(), complex);
model.addElement(complex);
data.id2alias.put(group.getGraphId(), element);
result.add(element);
}
return result;
}
/**
@@ -185,7 +189,7 @@ public class ModelContructor {
*/
protected void addElement(Model model, Graph graph, Data data) {
for (DataNode dataNode : graph.getDataNodes()) {
Species species = createSpecies(dataNode, data);
Species species = createSpecies(dataNode);
species.addMiriamData(biopaxFactory.getMiriamData(graph.getBiopaxData(), dataNode.getBiopaxReference()));
Element alias = updateAlias(dataNode, species);
@@ -255,6 +259,11 @@ public class ModelContructor {
if (mr != null) {
mr.setIdModificationResidue(state.getGraphId());
mr.setState(state.getType());
if (state.getTypeName() != null) {
mr.setName(state.getTypeName());
} else {
mr.setName("");
}
Double x = state.getRelX() * species.getWidth() / 2 + species.getCenterX();
Double y = state.getRelY() * species.getHeight() / 2 + species.getCenterY();
@@ -485,8 +494,18 @@ public class ModelContructor {
Rectangle2D rec = gpmlElement.getRectangle();
element.setX(rec.getX());
element.setY(rec.getY());
element.setWidth((int) rec.getWidth());
element.setHeight((int) rec.getHeight());
element.setWidth(rec.getWidth());
if (element.getWidth() <= 0) {
logger.warn(new LogMarker(ProjectLogEntryType.PARSING_ISSUE, element),
"Element width must be positive. Setting to 1.0");
element.setWidth(1.0);
}
element.setHeight(rec.getHeight());
if (element.getHeight() <= 0) {
logger.warn(new LogMarker(ProjectLogEntryType.PARSING_ISSUE, element),
"Element height must be positive. Setting to 1.0");
element.setHeight(1.0);
}
element.setFillColor(gpmlElement.getFillColor());
if (element instanceof Compartment && !Objects.equals(Color.WHITE, gpmlElement.getFillColor())) {
element.setBorderColor(gpmlElement.getFillColor());
@@ -547,29 +566,42 @@ public class ModelContructor {
* GPML data model
* @param data
* ...
* @throws UnknownChildClassException
* thrown when complex contain invalid child
* @throws ConverterException
*/
protected void putSpeciesIntoComplexes(Graph graph, Data data) throws UnknownChildClassException {
protected void putSpeciesIntoComplexes(Graph graph, Data data) throws ConverterException {
for (Group group : graph.getGroups()) {
Complex complex = (Complex) data.id2alias.get(group.getGraphId());
Complex complex = null;
Compartment compartment = null;
Element parent = null;
if (data.id2alias.get(group.getGraphId()) instanceof Complex) {
complex = (Complex) data.id2alias.get(group.getGraphId());
parent = complex;
} else if (data.id2alias.get(group.getGraphId()) instanceof Compartment) {
compartment = (Compartment) data.id2alias.get(group.getGraphId());
parent = compartment;
}
for (PathwayElement pe : group.getNodes()) {
Element element = data.id2alias.get(pe.getGraphId());
if (element != null) {
if (element instanceof Species) {
Species species = (Species) element;
complex.addSpecies(species);
if (complex != null) {
if (element instanceof Species) {
Species species = (Species) element;
complex.addSpecies(species);
}
} else if (compartment != null) {
compartment.addElement(element);
} else {
throw new ConverterException("Parent doesn't exists: " + group.getGraphId());
}
// we have label
} else if (graph.getLabelByGraphId(pe.getGraphId()) != null) {
Label label = graph.getLabelByGraphId(pe.getGraphId());
// if complex has generic name then change it into label
if (complex.getName().equals(group.getGraphId())) {
complex.setName(label.getTextLabel());
if (parent.getName().equals(group.getGraphId())) {
parent.setName(label.getTextLabel());
} else {
// if there are more labels than one then merge labels
complex.setName(complex.getName() + "\n" + label.getTextLabel());
parent.setName(parent.getName() + "\n" + label.getTextLabel());
}
} else if (graph.getShapeByGraphId(pe.getGraphId()) != null) {
Shape shape = graph.getShapeByGraphId(pe.getGraphId());
@@ -828,7 +860,7 @@ public class ModelContructor {
throw new InvalidStateException("This modifier is invalid");
}
Modifier mod = createModifierByType(modifierType, (Species) data.id2alias.get(id));
Modifier mod = createModifierByType(modifierType, data.id2alias.get(id));
ModifierType mt = mtu.getModifierTypeForClazz(mod.getClass());
@@ -863,7 +895,7 @@ public class ModelContructor {
* {@link Species alias } to which modifier is attached
* @return new instance of the modifierType
*/
private Modifier createModifierByType(Class<? extends ReactionNode> modifierType, Species alias) {
private Modifier createModifierByType(Class<? extends ReactionNode> modifierType, Element alias) {
try {
Modifier result = (Modifier) modifierType.getConstructor(Element.class).newInstance(alias);
return result;
@@ -889,7 +921,7 @@ public class ModelContructor {
model.setWidth(graph.getBoardWidth());
model.setHeight(graph.getBoardHeight());
addComplex(model, graph, data);
model.addElements(createElementsFromGroup(graph.getGroups(), data));
addElement(model, graph, data);
putSpeciesIntoComplexes(graph, data);
@@ -900,6 +932,8 @@ public class ModelContructor {
removeEmptyComplexes(model);
removeSelfLoops(model);
fixCompartmentAliases(model);
StringBuilder tmp = new StringBuilder();
@@ -941,6 +975,18 @@ public class ModelContructor {
}
}
void removeSelfLoops(Model model) {
Set<Reaction> toRemove = new HashSet<>();
for (Reaction reaction : model.getReactions()) {
if (reaction.getReactants().get(0).getElement().equals(reaction.getProducts().get(0).getElement())) {
logger.warn(new LogMarker(ProjectLogEntryType.PARSING_ISSUE, reaction),
"Self loops are not supported. Removing");
toRemove.add(reaction);
}
}
model.removeReactions(toRemove);
}
private void putMissingZIndexes(Collection<Drawable> bioEntities) {
int maxZIndex = 0;
for (Drawable bioEntity : bioEntities) {
@@ -1016,31 +1062,39 @@ public class ModelContructor {
* @param model
* model where operation is performed
*/
private void removeEmptyComplexes(Model model) {
void removeEmptyComplexes(Model model) {
Set<Element> aliasesInReaction = new HashSet<>();
for (Reaction reaction : model.getReactions()) {
for (ReactionNode node : reaction.getReactionNodes()) {
aliasesInReaction.add(node.getElement());
}
}
List<Element> toRemove = new ArrayList<>();
ElementUtils eu = new ElementUtils();
Set<BioEntity> toRemove = new HashSet<>();
for (Element element : model.getElements()) {
if (element instanceof Complex) {
Complex complex = (Complex) element;
if (complex.getSize() <= EPSILON && complex.getAllChildren().size() == 0) {
toRemove.add(element);
if (aliasesInReaction.contains(element)) {
logger.warn(new LogMarker(ProjectLogEntryType.PARSING_ISSUE, element),
"Empty element is invalid, but it's a part of reaction.");
for (Reaction reaction : model.getReactions()) {
for (ReactionNode node : reaction.getReactionNodes()) {
if (node.getElement().equals(element)) {
toRemove.add(reaction);
logger.warn(new LogMarker(ProjectLogEntryType.PARSING_ISSUE, reaction),
"Reaction to empty element is invalid.");
}
}
}
} else {
toRemove.add(element);
logger.warn(new LogMarker(ProjectLogEntryType.PARSING_ISSUE, element), "Empty element is invalid");
}
}
}
}
for (Element alias : toRemove) {
model.removeElement(alias);
for (BioEntity bioEntitiy : toRemove) {
model.removeBioEntity(bioEntitiy);
}
}
@@ -1164,7 +1218,7 @@ public class ModelContructor {
*
* @author Jan Badura
*/
private final class Data {
final class Data {
/**
* Map between graphId and aliases created from gpml elements.
*/
@@ -1183,8 +1237,8 @@ public class ModelContructor {
/**
* Default constructor.
*/
private Data() {
id2alias = new HashMap<String, Element>();
Data() {
id2alias = new HashMap<>();
layer = new Layer();
layer.setVisible(true);
layer.setLayerId("1");
Loading