Commit 320e7719 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

use celldesigner names when dealing with CD files

parent 9486191c
Pipeline #54187 passed with stage
in 22 minutes and 55 seconds
package lcsb.mapviewer.converter.model.celldesigner.species;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.map.species.field.ModificationState;
public enum ModificationStateMapping {
PHOSPHORYLATED(ModificationState.PHOSPHORYLATED, "phosphorylated"),
ACETYLATED(ModificationState.ACETYLATED, "acetylated"),
UBIQUITINATED(ModificationState.UBIQUITINATED, "ubiquitinated"),
METHYLATED(ModificationState.METHYLATED, "methylated"),
HYDROXYLATED(ModificationState.HYDROXYLATED, "hydroxylated"),
MYRISTOYLATED(ModificationState.MYRISTOYLATED, "myristoylated"),
SULFATED(ModificationState.SULFATED, "sulfated"),
PRENYLATED(ModificationState.PRENYLATED, "prenylated"),
GLYCOSYLATED(ModificationState.GLYCOSYLATED, "glycosylated"),
PALMYTOYLATED(ModificationState.PALMYTOYLATED, "palmytoylated"),
UNKNOWN(ModificationState.UNKNOWN, "unknown"),
EMPTY(ModificationState.EMPTY, "empty"),
PROTONATED(ModificationState.PROTONATED, "protonated"),
DONT_CARE(ModificationState.DONT_CARE, "don't care");
private ModificationState state;
private String text;
private ModificationStateMapping(final ModificationState modificationState, final String text) {
this.state = modificationState;
this.text = text;
}
public static ModificationState getStateByName(final String name) {
for (ModificationStateMapping mapping : ModificationStateMapping.values()) {
if (mapping.text.equalsIgnoreCase(name)) {
return mapping.state;
}
}
return null;
}
public static String getStateName(final ModificationState state) {
for (ModificationStateMapping mapping : ModificationStateMapping.values()) {
if (mapping.state.equals(state)) {
return mapping.text;
}
}
throw new InvalidArgumentException("Unknown state: " + state);
}
}
......@@ -628,7 +628,7 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec
modification.setIdModificationResidue(XmlParser.getNodeAttr("residue", rootNode));
String state = XmlParser.getNodeAttr("state", rootNode);
if (state != null) {
ModificationState modificationState = ModificationState.getByName(state);
ModificationState modificationState = ModificationStateMapping.getStateByName(state);
if (modificationState == null) {
throw new InvalidXmlSchemaException("[" + modification.getClass().getSimpleName() + "\t"
+ modification.getIdModificationResidue() + "] Unknown modification state: " + state);
......@@ -660,7 +660,7 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec
private String modificationResidueToXml(final CellDesignerModificationResidue mr, final int number) {
String state = "";
if (mr.getState() != null) {
state = mr.getState().getFullName();
state = ModificationStateMapping.getStateName(mr.getState());
}
if (state == null || state.equals("")) {
return "";
......
......@@ -126,7 +126,7 @@ public class ModificationTest extends CellDesignerTestFunctions {
}
@Test
public void testProtinWithResidues() throws Exception {
public void testProteinWithResidues() throws Exception {
Model model = getModelForFile("testFiles/modifications/protein_with_residues.xml");
Protein protein = (Protein) model.getElementByElementId("sa1");
assertEquals(14, protein.getModificationResidues().size());
......
......@@ -117,22 +117,6 @@ public enum ModificationState {
this.abbreviation = abbreviation;
}
/**
* Returns {@link ModificationState} identified by the full name.
*
* @param name
* full name of the state
* @return {@link ModificationState} identified by the full name
*/
public static ModificationState getByName(final String name) {
for (final ModificationState state : values()) {
if (state.getFullName().equalsIgnoreCase(name)) {
return state;
}
}
return null;
}
/**
* @return the fullName
* @see #fullName
......
package lcsb.mapviewer.model.map.species.field;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.junit.After;
import org.junit.Before;
......@@ -29,10 +28,4 @@ public class ModificationStateTest {
}
}
@Test
public void testGetByName() {
assertNull(ModificationState.getByName("Adasd"));
assertNotNull(ModificationState.getByName("protonated"));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment