From c1b0296b139769acd33bf65a06ecd232c93d671a Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Tue, 19 Dec 2017 10:32:19 +0100
Subject: [PATCH] handling of the situation when layout ids are not unique for
 reactions

---
 .../model/sbml/SbmlReactionParser.java        | 22 +++++++++----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlReactionParser.java b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlReactionParser.java
index 3a633ce4f7..88c9883007 100644
--- a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlReactionParser.java
+++ b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlReactionParser.java
@@ -72,26 +72,27 @@ public class SbmlReactionParser {
     return sbmlModel.getListOfReactions();
   }
 
-  protected void mergeLayout(Collection<Reaction> elements, Layout sbmlLayout, Model sbmlModel)
+  protected void mergeLayout(Collection<Reaction> reactions, Layout sbmlLayout, Model sbmlModel)
       throws InvalidInputDataExecption {
     Set<Reaction> used = new HashSet<>();
-    Map<String, Reaction> elementById = new HashMap<>();
-    for (Reaction species : elements) {
-      if (elementById.get(species.getIdReaction()) != null) {
-        throw new InvalidInputDataExecption("Duplicated reaction id: " + species.getIdReaction());
+    Map<String, Reaction> reactionById = new HashMap<>();
+    for (Reaction reaction : reactions) {
+      if (reactionById.get(reaction.getIdReaction()) != null) {
+        throw new InvalidInputDataExecption("Duplicated reaction id: " + reaction.getIdReaction());
       }
-      elementById.put(species.getIdReaction(), species);
+      reactionById.put(reaction.getIdReaction(), reaction);
     }
 
     for (ReactionGlyph glyph : sbmlLayout.getListOfReactionGlyphs()) {
-      Reaction source = elementById.get(glyph.getReaction());
+      Reaction source = reactionById.get(glyph.getReaction());
       if (source == null) {
         throw new InvalidInputDataExecption("Layout contains invalid Species id: " + glyph.getReaction());
       }
       used.add(source);
       try {
         Reaction reactionWithLayout = source.copy();
-        reactionWithLayout.setIdReaction(glyph.getId());
+        // getId doesn't have to be unique, therefore we concatenate with reaction
+        reactionWithLayout.setIdReaction(glyph.getId() + "_" + glyph.getReaction());
         for (SpeciesReferenceGlyph speciesRefernceGlyph : glyph.getListOfSpeciesReferenceGlyphs()) {
           SpeciesGlyph speciesGlyph = layout.getSpeciesGlyph(speciesRefernceGlyph.getSpeciesGlyph());
           ReactionNode minervaNode = null;
@@ -206,16 +207,15 @@ public class SbmlReactionParser {
           operator.setLine(line);
           reactionWithLayout.addNode(operator);
         }
-
         minervaModel.addReaction(new StateTransitionReaction(reactionWithLayout));
       } catch (InvalidArgumentException e) {
         throw new InvalidInputDataExecption(e);
       }
     }
     Set<Reaction> elementsToRemove = new HashSet<>();
-    for (Reaction reaction : elements) {
+    for (Reaction reaction : reactions) {
       if (!used.contains(reaction)) {
-        logger.warn("Layout doesn't contain information about Element: " + reaction.getIdReaction());
+        logger.warn("Layout doesn't contain information about Reaction: " + reaction.getIdReaction());
       } else {
         elementsToRemove.add(reaction);
       }
-- 
GitLab