From e4fb01674127a040209af8d2ca6ab31cf8c06810 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Fri, 4 Jan 2019 13:54:50 +0100
Subject: [PATCH] featureValues extracted to common function

---
 .../model/sbml/species/SbmlSpeciesParser.java | 55 ++++++++++---------
 1 file changed, 28 insertions(+), 27 deletions(-)

diff --git a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesParser.java b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesParser.java
index 1b6bfa6afc..b504bb60d5 100644
--- a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesParser.java
+++ b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesParser.java
@@ -21,6 +21,7 @@ import org.sbml.jsbml.ext.multi.PossibleSpeciesFeatureValue;
 import org.sbml.jsbml.ext.multi.SpeciesFeature;
 import org.sbml.jsbml.ext.multi.SpeciesFeatureType;
 import org.sbml.jsbml.ext.multi.SpeciesFeatureValue;
+import org.sbml.jsbml.ext.multi.SpeciesTypeInstance;
 import org.sbml.jsbml.ext.multi.SubListOfSpeciesFeature;
 import org.sbml.jsbml.ext.render.LocalStyle;
 
@@ -127,51 +128,51 @@ public class SbmlSpeciesParser extends SbmlElementParser<org.sbml.jsbml.Species>
       SpeciesFeature feature) {
     String warnPrefix = new ElementUtils().getElementTag(minervaElement);
     String featureTypeString = feature.getSpeciesFeatureType();
+    List<String> featureValues = getFeatureValues(speciesType, feature);
     if (MultiPackageNamingUtils.isFeatureId(featureTypeString, BioEntityFeature.STRUCTURAL_STATE)) {
-      SpeciesFeatureType featureType = speciesType.getListOfSpeciesFeatureTypes().get(featureTypeString);
-
-      List<String> structuralStates = new ArrayList<>();
-      for (SpeciesFeatureValue featureValue : feature.getListOfSpeciesFeatureValues()) {
-        PossibleSpeciesFeatureValue possibleSpeciesFeatureValue = featureType.getListOfPossibleSpeciesFeatureValues()
-            .get(featureValue.getValue());
-        structuralStates.add(possibleSpeciesFeatureValue.getName());
-      }
       if (minervaElement instanceof Protein) {
-        ((Protein) minervaElement).setStructuralState(String.join("; ", structuralStates));
+        ((Protein) minervaElement).setStructuralState(String.join("; ", featureValues));
       } else if (minervaElement instanceof Complex) {
-        ((Complex) minervaElement).setStructuralState(String.join("; ", structuralStates));
+        ((Complex) minervaElement).setStructuralState(String.join("; ", featureValues));
       } else {
         logger.warn(warnPrefix + "Structural state not supported");
       }
     } else if (MultiPackageNamingUtils.isFeatureId(featureTypeString, BioEntityFeature.POSITION_TO_COMPARTMENT)) {
-      SpeciesFeatureType featureType = speciesType.getListOfSpeciesFeatureTypes().get(featureTypeString);
-
-      List<String> positionToCompartments = new ArrayList<>();
-      for (SpeciesFeatureValue featureValue : feature.getListOfSpeciesFeatureValues()) {
-        PossibleSpeciesFeatureValue possibleSpeciesFeatureValue = featureType.getListOfPossibleSpeciesFeatureValues()
-            .get(featureValue.getValue());
-        positionToCompartments.add(possibleSpeciesFeatureValue.getName());
-      }
-      if (positionToCompartments.size() != 1) {
+      if (featureValues.size() != 1) {
         logger.warn(warnPrefix + "Position to compartment must exactly one value");
       } else {
-        minervaElement.setPositionToCompartment(PositionToCompartment.getByString(positionToCompartments.get(0)));
+        minervaElement.setPositionToCompartment(PositionToCompartment.getByString(featureValues.get(0)));
       }
     } else if (MultiPackageNamingUtils.isFeatureId(featureTypeString, BioEntityFeature.SYNONYM)) {
-      SpeciesFeatureType featureType = speciesType.getListOfSpeciesFeatureTypes().get(featureTypeString);
+      minervaElement.setSynonyms(featureValues);
+    } else if (MultiPackageNamingUtils.isModificationFeatureId(featureTypeString)) {
+      createModificationResidues(minervaElement, speciesType, feature);
+    } else {
+      logger.warn(warnPrefix + "Feature not supported: " + featureTypeString);
+    }
+  }
+
+  private List<String> getFeatureValues(MultiSpeciesType speciesType, SpeciesFeature feature) {
+    SpeciesFeatureType featureType = speciesType.getListOfSpeciesFeatureTypes().get(feature.getSpeciesFeatureType());
 
-      List<String> synonyms = new ArrayList<>();
+    List<String> result = new ArrayList<>();
+    if (featureType != null) {
       for (SpeciesFeatureValue featureValue : feature.getListOfSpeciesFeatureValues()) {
         PossibleSpeciesFeatureValue possibleSpeciesFeatureValue = featureType.getListOfPossibleSpeciesFeatureValues()
             .get(featureValue.getValue());
-        synonyms.add(possibleSpeciesFeatureValue.getName());
+        result.add(possibleSpeciesFeatureValue.getName());
       }
-      minervaElement.setSynonyms(synonyms);
-    } else if (MultiPackageNamingUtils.isModificationFeatureId(featureTypeString)) {
-      createModificationResidues(minervaElement, speciesType, feature);
     } else {
-      logger.warn(warnPrefix + "Feature not supported: " + featureTypeString);
+      for (SpeciesTypeInstance speciesTypeInstance : speciesType.getListOfSpeciesTypeInstances()) {
+        speciesType = getMultiPlugin().getSpeciesType(speciesTypeInstance.getSpeciesType());
+        result = getFeatureValues(speciesType, feature);
+        if (result.size() > 0) {
+          return result;
+        }
+      }
+
     }
+    return result;
   }
 
   private void createModificationResidues(Species minervaElement, MultiSpeciesType speciesType,
-- 
GitLab