From 3f3fd7fd0952613bc5fe00cb52c291f5efb872b2 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Tue, 13 Feb 2018 17:40:31 +0100
Subject: [PATCH] fix on matching reactions

---
 .../mapviewer/commands/ColorModelCommand.java |  8 ++--
 .../commands/ColorModelCommandTest.java       | 46 +++++++++++++++++++
 2 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/model-command/src/main/java/lcsb/mapviewer/commands/ColorModelCommand.java b/model-command/src/main/java/lcsb/mapviewer/commands/ColorModelCommand.java
index f6ff490e8d..43df86700d 100644
--- a/model-command/src/main/java/lcsb/mapviewer/commands/ColorModelCommand.java
+++ b/model-command/src/main/java/lcsb/mapviewer/commands/ColorModelCommand.java
@@ -137,16 +137,16 @@ public class ColorModelCommand extends ModelCommand {
     if (schema.getGeneralIdentifier() != null && !schema.getGeneralIdentifier().equals("")) {
       MiriamData md = MiriamType.getMiriamDataFromIdentifier(schema.getGeneralIdentifier());
 
-      if (reaction.getMiriamData().contains(md)) {
-        return true;
+      if (!reaction.getMiriamData().contains(md)) {
+        return false;
       }
     }
     for (Pair<MiriamType, String> pair : schema.getIdentifierColumns()) {
       if (pair.getRight() != null && !pair.getRight().equals("")) {
 
         MiriamData md = new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, pair.getLeft(), pair.getRight());
-        if (reaction.getMiriamData().contains(md)) {
-          return true;
+        if (!reaction.getMiriamData().contains(md)) {
+          return false;
         }
       }
     }
diff --git a/model-command/src/test/java/lcsb/mapviewer/commands/ColorModelCommandTest.java b/model-command/src/test/java/lcsb/mapviewer/commands/ColorModelCommandTest.java
index d240a93b7c..b8d977f446 100644
--- a/model-command/src/test/java/lcsb/mapviewer/commands/ColorModelCommandTest.java
+++ b/model-command/src/test/java/lcsb/mapviewer/commands/ColorModelCommandTest.java
@@ -17,6 +17,7 @@ import org.junit.Test;
 
 import lcsb.mapviewer.common.Pair;
 import lcsb.mapviewer.model.map.BioEntity;
+import lcsb.mapviewer.model.map.MiriamData;
 import lcsb.mapviewer.model.map.MiriamType;
 import lcsb.mapviewer.model.map.layout.ColorSchema;
 import lcsb.mapviewer.model.map.layout.GenericColorSchema;
@@ -363,6 +364,51 @@ public class ColorModelCommandTest extends CommandTestFunctions {
 
   }
 
+  @Test
+  public void testReactionMatchWithProteinMiriamData() throws Exception {
+    try {
+      GenericColorSchema colorSchema = new GenericColorSchema();
+      colorSchema.setGeneralIdentifier(MiriamType.HGNC_SYMBOL.getCommonName()+":SNCA");
+
+      Reaction reaction = new Reaction();
+
+      List<ColorSchema> schemas = new ArrayList<>();
+      schemas.add(colorSchema);
+
+      ColorModelCommand factory = new ColorModelCommand(new ModelFullIndexed(null), schemas, colorExtractor);
+
+      assertFalse(factory.match(reaction, colorSchema));
+
+    } catch (Exception e) {
+      e.printStackTrace();
+      throw e;
+    }
+
+  }
+
+  @Test
+  public void testReactionMatchWithMiriamData() throws Exception {
+    try {
+      GenericColorSchema colorSchema = new GenericColorSchema();
+      colorSchema.setGeneralIdentifier(MiriamType.PUBMED.getCommonName()+":1234");
+
+      Reaction reaction = new Reaction();
+      reaction.addMiriamData(new MiriamData(MiriamType.PUBMED, "1234"));
+
+      List<ColorSchema> schemas = new ArrayList<>();
+      schemas.add(colorSchema);
+
+      ColorModelCommand factory = new ColorModelCommand(new ModelFullIndexed(null), schemas, colorExtractor);
+
+      assertTrue(factory.match(reaction, colorSchema));
+
+    } catch (Exception e) {
+      e.printStackTrace();
+      throw e;
+    }
+
+  }
+
   @Test
   public void testReactionColoringWithModelNotMatching() throws Exception {
     try {
-- 
GitLab