From 56cf1072fad8f92f17ef1b997e3af549f664621e Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Tue, 20 Mar 2018 10:53:55 +0100
Subject: [PATCH] self reactions are layouted properly

---
 .../sbml/reaction/SBOTermReactionType.java    |  2 +-
 .../small/reaction/self_reaction.xml          | 57 +++++++++++++++++++
 .../layout/ApplySimpleLayoutModelCommand.java |  9 ++-
 3 files changed, 65 insertions(+), 3 deletions(-)
 create mode 100644 converter-sbml/testFiles/small/reaction/self_reaction.xml

diff --git a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/reaction/SBOTermReactionType.java b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/reaction/SBOTermReactionType.java
index 5424c1e616..aa0f9c7eba 100644
--- a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/reaction/SBOTermReactionType.java
+++ b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/reaction/SBOTermReactionType.java
@@ -60,7 +60,7 @@ public enum SBOTermReactionType {
       }
     }
     if (result == null) {
-      logger.warn("Don't know how to handle SBOTerm " + sboTerm + " for modifier");
+      logger.warn("Don't know how to handle SBOTerm " + sboTerm + " for reaction");
       result = StateTransitionReaction.class;
     }
     return result;
diff --git a/converter-sbml/testFiles/small/reaction/self_reaction.xml b/converter-sbml/testFiles/small/reaction/self_reaction.xml
new file mode 100644
index 0000000000..eb9932349c
--- /dev/null
+++ b/converter-sbml/testFiles/small/reaction/self_reaction.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sbml xmlns="http://www.sbml.org/sbml/level2/version4" level="2" version="4">
+  <model id="TestGEN">
+    <annotation/>
+    <listOfCompartments>
+      <compartment constant="true" id="default" name="cell" sboTerm="SBO:0000290" size="1">
+        <annotation>
+          <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:bqmodel="http://biomodels.net/model-qualifiers/" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/">
+            <rdf:Description rdf:about="#">
+              <bqbiol:isVersionOf>
+                <rdf:Bag>
+                  <rdf:li rdf:resource="urn:miriam:obo.go:GO:0005623"/>
+                </rdf:Bag>
+              </bqbiol:isVersionOf>
+            </rdf:Description>
+          </rdf:RDF>
+        </annotation>
+      </compartment>
+    </listOfCompartments>
+    <listOfSpecies>
+      <species boundaryCondition="false" compartment="default" initialConcentration="1" id="s1588" name="NGFR" sboTerm="SBO:0000252">
+        <annotation>
+          <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:bqmodel="http://biomodels.net/model-qualifiers/" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/">
+            <rdf:Description rdf:about="#">
+              <bqbiol:isEncodedBy>
+                <rdf:Bag>
+                  <rdf:li rdf:resource="urn:miriam:hgnc.symbol:NGFR"/>
+                </rdf:Bag>
+              </bqbiol:isEncodedBy>
+            </rdf:Description>
+          </rdf:RDF>
+        </annotation>
+      </species>
+    </listOfSpecies>
+    <listOfReactions>
+<reaction reversible="false" id="r2149" sboTerm="SBO:0000170">
+        <annotation>
+          <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:bqmodel="http://biomodels.net/model-qualifiers/" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/">
+            <rdf:Description rdf:about="#">
+              <bqbiol:isDescribedBy>
+                <rdf:Bag>
+                  <rdf:li rdf:resource="urn:miriam:pubmed:22236693 "/>
+                </rdf:Bag>
+              </bqbiol:isDescribedBy>
+            </rdf:Description>
+          </rdf:RDF>
+        </annotation>
+        <listOfReactants>
+          <speciesReference species="s1588" stoichiometry="1"/>
+        </listOfReactants>
+        <listOfProducts>
+          <speciesReference species="s1588" stoichiometry="1"/>
+        </listOfProducts>
+      </reaction>
+    </listOfReactions>
+  </model>
+</sbml>
diff --git a/model-command/src/main/java/lcsb/mapviewer/commands/layout/ApplySimpleLayoutModelCommand.java b/model-command/src/main/java/lcsb/mapviewer/commands/layout/ApplySimpleLayoutModelCommand.java
index fa528d3bf2..3a426da477 100644
--- a/model-command/src/main/java/lcsb/mapviewer/commands/layout/ApplySimpleLayoutModelCommand.java
+++ b/model-command/src/main/java/lcsb/mapviewer/commands/layout/ApplySimpleLayoutModelCommand.java
@@ -120,10 +120,10 @@ public class ApplySimpleLayoutModelCommand extends ApplyLayoutModelCommand {
     Set<Species> elementToAlign = new HashSet<>();
     Map<Compartment, Set<Element>> elementsByStaticCompartment = new HashMap<>();
     for (Element element : elements) {
-      if (element.getWidth()==0) {
+      if (element.getWidth() == 0) {
         element.setWidth(SPECIES_WIDTH);
         element.setHeight(SPECIES_HEIGHT);
-        
+
       }
       if (element.getCompartment() == null || element.getCompartment() == parent) {
         if (element instanceof Compartment) {
@@ -218,6 +218,11 @@ public class ApplySimpleLayoutModelCommand extends ApplyLayoutModelCommand {
 
     Point2D middle = getMiddlePoint(productElement.getCenter(), reactantElement.getCenter());
 
+    //for self reactions
+    if (productElement.equals(reactantElement)) {
+      middle.setLocation(middle.getX(), middle.getY() + 50);
+    }
+
     modifyProducts(reaction, middle);
     modifyReactants(reaction, middle);
     modifyModifiers(reaction, middle);
-- 
GitLab