Skip to content
Snippets Groups Projects
Commit e4fb0167 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

featureValues extracted to common function

parent bc2f74f3
No related branches found
No related tags found
2 merge requests!630WIP: Resolve "The privileges of a new user are not saved in some cases",!560Resolve "add support for modifications and states in sbml export/import"
...@@ -21,6 +21,7 @@ import org.sbml.jsbml.ext.multi.PossibleSpeciesFeatureValue; ...@@ -21,6 +21,7 @@ import org.sbml.jsbml.ext.multi.PossibleSpeciesFeatureValue;
import org.sbml.jsbml.ext.multi.SpeciesFeature; import org.sbml.jsbml.ext.multi.SpeciesFeature;
import org.sbml.jsbml.ext.multi.SpeciesFeatureType; import org.sbml.jsbml.ext.multi.SpeciesFeatureType;
import org.sbml.jsbml.ext.multi.SpeciesFeatureValue; 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.multi.SubListOfSpeciesFeature;
import org.sbml.jsbml.ext.render.LocalStyle; import org.sbml.jsbml.ext.render.LocalStyle;
...@@ -127,51 +128,51 @@ public class SbmlSpeciesParser extends SbmlElementParser<org.sbml.jsbml.Species> ...@@ -127,51 +128,51 @@ public class SbmlSpeciesParser extends SbmlElementParser<org.sbml.jsbml.Species>
SpeciesFeature feature) { SpeciesFeature feature) {
String warnPrefix = new ElementUtils().getElementTag(minervaElement); String warnPrefix = new ElementUtils().getElementTag(minervaElement);
String featureTypeString = feature.getSpeciesFeatureType(); String featureTypeString = feature.getSpeciesFeatureType();
List<String> featureValues = getFeatureValues(speciesType, feature);
if (MultiPackageNamingUtils.isFeatureId(featureTypeString, BioEntityFeature.STRUCTURAL_STATE)) { 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) { if (minervaElement instanceof Protein) {
((Protein) minervaElement).setStructuralState(String.join("; ", structuralStates)); ((Protein) minervaElement).setStructuralState(String.join("; ", featureValues));
} else if (minervaElement instanceof Complex) { } else if (minervaElement instanceof Complex) {
((Complex) minervaElement).setStructuralState(String.join("; ", structuralStates)); ((Complex) minervaElement).setStructuralState(String.join("; ", featureValues));
} else { } else {
logger.warn(warnPrefix + "Structural state not supported"); logger.warn(warnPrefix + "Structural state not supported");
} }
} else if (MultiPackageNamingUtils.isFeatureId(featureTypeString, BioEntityFeature.POSITION_TO_COMPARTMENT)) { } else if (MultiPackageNamingUtils.isFeatureId(featureTypeString, BioEntityFeature.POSITION_TO_COMPARTMENT)) {
SpeciesFeatureType featureType = speciesType.getListOfSpeciesFeatureTypes().get(featureTypeString); if (featureValues.size() != 1) {
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) {
logger.warn(warnPrefix + "Position to compartment must exactly one value"); logger.warn(warnPrefix + "Position to compartment must exactly one value");
} else { } else {
minervaElement.setPositionToCompartment(PositionToCompartment.getByString(positionToCompartments.get(0))); minervaElement.setPositionToCompartment(PositionToCompartment.getByString(featureValues.get(0)));
} }
} else if (MultiPackageNamingUtils.isFeatureId(featureTypeString, BioEntityFeature.SYNONYM)) { } 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()) { for (SpeciesFeatureValue featureValue : feature.getListOfSpeciesFeatureValues()) {
PossibleSpeciesFeatureValue possibleSpeciesFeatureValue = featureType.getListOfPossibleSpeciesFeatureValues() PossibleSpeciesFeatureValue possibleSpeciesFeatureValue = featureType.getListOfPossibleSpeciesFeatureValues()
.get(featureValue.getValue()); .get(featureValue.getValue());
synonyms.add(possibleSpeciesFeatureValue.getName()); result.add(possibleSpeciesFeatureValue.getName());
} }
minervaElement.setSynonyms(synonyms);
} else if (MultiPackageNamingUtils.isModificationFeatureId(featureTypeString)) {
createModificationResidues(minervaElement, speciesType, feature);
} else { } 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, private void createModificationResidues(Species minervaElement, MultiSpeciesType speciesType,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment