Commit 837f6c95 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch 'panther-issues' into 'master'

Panther issues

See merge request !1017
parents 1990ff3c f4f3b68e
......@@ -10,6 +10,9 @@ minerva (15.0.0~alpha.1) stable; urgency=medium
* Small improvement: list of genomes is automatically refreshed during genome
upload (#820)
* Small improvement: items in context menu are reorganized (#787)
* Small improvement: CellDesigner files from version 2.5 should be parseable
* Bug fix: compartments limited by corner (left-top corner compartment, etc)
are parsed properly from CellDesigner files
* Bug fix: structural states of proteins are imported properly from SBGNML PD
(#995)
* Bug fix: clear button icon, refresh comments button and show overview
......
......@@ -62,7 +62,7 @@ public class CellDesignerXmlParser extends Converter {
/**
* Default class logger.
*/
private static Logger logger = LogManager.getLogger(CellDesignerXmlParser.class.getName());
private static Logger logger = LogManager.getLogger();
/**
* CellDesigner parser for layers.
......@@ -89,8 +89,11 @@ public class CellDesignerXmlParser extends Converter {
*/
private RestAnnotationParser rap = new RestAnnotationParser();
private boolean oldCellDesignerVersion;
@Override
public Model createModel(ConverterParams params) throws InvalidInputDataExecption {
oldCellDesignerVersion = false;
CellDesignerElementCollection elements = new CellDesignerElementCollection();
FunctionCollectionXmlParser functionParser = new FunctionCollectionXmlParser();
UnitCollectionXmlParser unitParser = new UnitCollectionXmlParser();
......@@ -213,7 +216,7 @@ public class CellDesignerXmlParser extends Converter {
if (reactionsNode != null) {
ReactionCollectionXmlParser reactionCollectionXmlParser = new ReactionCollectionXmlParser(model, elements,
params.isSbgnFormat());
params.isSbgnFormat(), oldCellDesignerVersion);
List<Reaction> reactions = reactionCollectionXmlParser.parseXmlReactionCollection(reactionsNode);
model.addReactions(reactions);
}
......@@ -376,7 +379,11 @@ public class CellDesignerXmlParser extends Converter {
model.addAuthors(xmlAnnotationParser.getAuthorsFromRdf(node));
model.setCreationDate(xmlAnnotationParser.getCreateDateFromRdf(node));
model.addModificationDates(xmlAnnotationParser.getModificationDatesFromRdf(node));
} else {
} else if (node.getNodeName().equalsIgnoreCase("celldesigner:modelVersion")) {
logger.warn("Old version of cell designer found: " + XmlParser.getNodeValue(node));
oldCellDesignerVersion = true;
extensionNode = annotationNode;
} else if (!oldCellDesignerVersion) {
throw new InvalidXmlSchemaException("Unknown element of annotation: " + node.getNodeName());
}
}
......@@ -601,8 +608,9 @@ public class CellDesignerXmlParser extends Converter {
try {
CellDesignerElementCollection elements = new CellDesignerElementCollection();
SpeciesCollectionXmlParser speciesCollectionXmlParser = new SpeciesCollectionXmlParser(elements, model.getUnits());
ReactionCollectionXmlParser reactionCollectionXmlParser = new ReactionCollectionXmlParser(model, elements, false);
SpeciesCollectionXmlParser speciesCollectionXmlParser = new SpeciesCollectionXmlParser(elements,
model.getUnits());
ReactionCollectionXmlParser reactionCollectionXmlParser = new ReactionCollectionXmlParser(model, elements, false, oldCellDesignerVersion);
UnitCollectionXmlParser unitCollectionXmlParser = new UnitCollectionXmlParser();
FunctionCollectionXmlParser functionCollectionXmlParser = new FunctionCollectionXmlParser();
ParameterCollectionXmlParser parameterCollectionXmlParser = new ParameterCollectionXmlParser(model);
......
......@@ -69,11 +69,12 @@ public class CompartmentAliasXmlParser extends AbstractAliasXmlParser<Compartmen
elements.addElement(compartment, aliasId);
NodeList nodes = aliasNode.getChildNodes();
String type = null;
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
if (node.getNodeName().equalsIgnoreCase("celldesigner:class")) {
String type = XmlParser.getNodeValue(node);
type = XmlParser.getNodeValue(node);
if (type.equalsIgnoreCase("SQUARE")) {
result = new SquareCompartment(result);
} else if (type.equalsIgnoreCase("SQUARE_CLOSEUP_NORTH")) {
......@@ -84,6 +85,14 @@ public class CompartmentAliasXmlParser extends AbstractAliasXmlParser<Compartmen
result = new RightSquareCompartment(result, model);
} else if (type.equalsIgnoreCase("SQUARE_CLOSEUP_EAST")) {
result = new LeftSquareCompartment(result, model);
} else if (type.equalsIgnoreCase("SQUARE_CLOSEUP_NORTHWEST")) {
result = new SquareCompartment(result);
} else if (type.equalsIgnoreCase("SQUARE_CLOSEUP_NORTHEAST")) {
result = new SquareCompartment(result);
} else if (type.equalsIgnoreCase("SQUARE_CLOSEUP_SOUTHEAST")) {
result = new SquareCompartment(result);
} else if (type.equalsIgnoreCase("SQUARE_CLOSEUP_SOUTHWEST")) {
result = new SquareCompartment(result);
} else if (type.equalsIgnoreCase("OVAL")) {
result = new OvalCompartment(result);
} else {
......@@ -121,6 +130,26 @@ public class CompartmentAliasXmlParser extends AbstractAliasXmlParser<Compartmen
} else if (result instanceof TopSquareCompartment) {
result.setHeight(XmlParser.getNodeAttr("y", node));
result.setY(0.0);
} else if ("SQUARE_CLOSEUP_NORTHWEST".equals(type)) {
result.setX(XmlParser.getNodeAttr("x", node));
result.setY(XmlParser.getNodeAttr("y", node));
result.setWidth(model.getWidth() - result.getX());
result.setHeight(model.getHeight() - result.getY());
} else if ("SQUARE_CLOSEUP_NORTHEAST".equals(type)) {
result.setWidth(XmlParser.getNodeAttr("x", node));
result.setY(XmlParser.getNodeAttr("y", node));
result.setX(0);
result.setHeight(model.getHeight() - result.getY());
} else if ("SQUARE_CLOSEUP_SOUTHEAST".equals(type)) {
result.setWidth(XmlParser.getNodeAttr("x", node));
result.setHeight(XmlParser.getNodeAttr("y", node));
result.setX(0);
result.setY(0);
} else if ("SQUARE_CLOSEUP_SOUTHWEST".equals(type)) {
result.setX(XmlParser.getNodeAttr("x", node));
result.setHeight(XmlParser.getNodeAttr("y", node));
result.setWidth(model.getWidth() - result.getX());
result.setY(0);
} else {
throw new InvalidXmlSchemaException(
"Don't know what to do with celldesigner:point for class: " + result.getClass());
......
......@@ -137,15 +137,17 @@ public class CompartmentXmlParser extends AbstractElementXmlParser<CellDesignerC
private void parseAnnotationNode(CellDesignerCompartment compartment, Node xmlNode) throws InvalidXmlSchemaException {
NodeList annotationNodes = xmlNode.getChildNodes();
for (int y = 0; y < annotationNodes.getLength(); y++) {
Node annotationNode = annotationNodes.item(y);
if (annotationNode.getNodeType() == Node.ELEMENT_NODE) {
if (annotationNode.getNodeName().equalsIgnoreCase("rdf:RDF")) {
compartment.addMiriamData(xmlAnnotationParser.parseRdfNode(annotationNode));
} else if (annotationNode.getNodeName().equalsIgnoreCase("celldesigner:extension")) {
parseExtensionNode(compartment, annotationNode);
Node node = annotationNodes.item(y);
if (node.getNodeType() == Node.ELEMENT_NODE) {
if (node.getNodeName().equalsIgnoreCase("rdf:RDF")) {
compartment.addMiriamData(xmlAnnotationParser.parseRdfNode(node));
} else if (node.getNodeName().equalsIgnoreCase("celldesigner:extension")) {
parseExtensionNode(compartment, node);
} else if (node.getNodeName().equalsIgnoreCase("celldesigner:name")) {
compartment.setName(decodeName(XmlParser.getNodeValue(node)));
} else {
throw new InvalidXmlSchemaException(
"Unknown xml tag of compartment->annotation: " + annotationNode.getNodeName());
"Unknown xml tag of compartment->annotation: " + node.getNodeName());
}
}
}
......
......@@ -53,9 +53,10 @@ public class ReactionCollectionXmlParser {
* @param model
* model that is parsed/transformed into xml
*/
public ReactionCollectionXmlParser(Model model, CellDesignerElementCollection elements, boolean sbgn) {
public ReactionCollectionXmlParser(Model model, CellDesignerElementCollection elements, boolean sbgn,
boolean oldCellDesignerVersion) {
this.model = model;
xmlStructureFactory = new ReactionXmlParser(elements, sbgn);
xmlStructureFactory = new ReactionXmlParser(elements, sbgn, oldCellDesignerVersion);
}
/**
......
......@@ -96,15 +96,18 @@ public class ReactionFromXml {
*/
private boolean sbgn;
private boolean oldCellDesignerVersion;
/**
* Default constructor.
*
* @param sbgn
* Should the converter use SBGN standard
*/
public ReactionFromXml(CellDesignerElementCollection elements, boolean sbgn) {
public ReactionFromXml(CellDesignerElementCollection elements, boolean sbgn, boolean oldCellDesignerVersion) {
this.elements = elements;
this.sbgn = sbgn;
this.oldCellDesignerVersion = oldCellDesignerVersion;
}
/**
......@@ -276,6 +279,9 @@ public class ReactionFromXml {
private Reaction parseReactionAnnotation(Node annotationNode, Reaction result, Model model)
throws ReactionParserException {
NodeList nodes = annotationNode.getChildNodes();
if (oldCellDesignerVersion) {
result = parseReactionExtension(result, annotationNode, model);
}
for (int x = 0; x < nodes.getLength(); x++) {
Node node = nodes.item(x);
if (node.getNodeType() == Node.ELEMENT_NODE) {
......@@ -288,11 +294,12 @@ public class ReactionFromXml {
} catch (InvalidXmlSchemaException e) {
throw new ReactionParserException("Problem with parsing RDF", result, e);
}
} else {
} else if (!oldCellDesignerVersion) {
throw new ReactionParserException("Unknown element of reaction/annotation: " + node.getNodeName(), result);
}
}
}
return result;
}
......@@ -409,7 +416,7 @@ public class ReactionFromXml {
}
applyStylingToLine(line, result.getLine());
if (booleanLogicGateType!=null) {
if (booleanLogicGateType != null) {
assignColorFromGateMembers(result, gateMembers);
}
if (reactantsLinkNode != null) {
......@@ -954,7 +961,7 @@ public class ReactionFromXml {
polylines.add(result.getReactants().get(elementIndex - 1).getLine());
}
}
for (PolylineData polyline: polylines) {
for (PolylineData polyline : polylines) {
polyline.setColor(line.getColor());
polyline.setWidth(line.getWidth());
}
......
......@@ -39,9 +39,9 @@ public class ReactionXmlParser {
* collection of {@link CellDesignerElement cell designer elements}
* parsed from xml
*/
public ReactionXmlParser(CellDesignerElementCollection elements, boolean sbgn) {
public ReactionXmlParser(CellDesignerElementCollection elements, boolean sbgn, boolean oldCellDesignerVersion) {
reactionToXml = new ReactionToXml(elements, sbgn);
reactionFromXml = new ReactionFromXml(elements, sbgn);
reactionFromXml = new ReactionFromXml(elements, sbgn, oldCellDesignerVersion);
}
/**
......
......@@ -88,6 +88,8 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec
list = annotationNode.getChildNodes();
Node extensionNode = null;
Node rdfNode = null;
Node speciesIdentity = null;
Node positionToCompartment = null;
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
......@@ -96,36 +98,45 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec
extensionNode = node;
} else if (node.getNodeName().equals("rdf:RDF")) {
rdfNode = node;
} else {
throw new InvalidXmlSchemaException("Unknown element of annotation " + node.getNodeName());
}
}
}
if (extensionNode == null) {
throw new InvalidXmlSchemaException(
"No celldesigner:extension node in SBML/model/listOfSpecies/species/annotation");
}
list = extensionNode.getChildNodes();
Node speciesIdentity = null;
Node positionToCompartment = null;
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
if (node.getNodeName().equals("celldesigner:speciesIdentity")) {
speciesIdentity = node;
} else if (node.getNodeName().equals("celldesigner:positionToCompartment")) {
positionToCompartment = node;
} else if (node.getNodeName().equals("celldesigner:speciesIdentity")) {
speciesIdentity = node;
} else if (node.getNodeName().equals("celldesigner:listOfCatalyzedReactions")) {
// we can ignore it - every node on the map contains information about
// itself
continue;
} else {
throw new InvalidXmlSchemaException("[" + XmlParser.getNodeAttr("id", spieciesNode)
+ "]\tUnknown element of celldesigner:extension " + node.getNodeName());
logger.debug(XmlParser.nodeToString(spieciesNode, true));
throw new InvalidXmlSchemaException("Unknown element of annotation " + node.getNodeName());
}
}
}
if (extensionNode != null) {
list = extensionNode.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
if (node.getNodeName().equals("celldesigner:speciesIdentity")) {
speciesIdentity = node;
} else if (node.getNodeName().equals("celldesigner:positionToCompartment")) {
positionToCompartment = node;
} else if (node.getNodeName().equals("celldesigner:listOfCatalyzedReactions")) {
// we can ignore it - every node on the map contains information about
// itself
continue;
} else {
throw new InvalidXmlSchemaException("[" + XmlParser.getNodeAttr("id", spieciesNode)
+ "]\tUnknown element of celldesigner:extension " + node.getNodeName());
}
}
}
} else {
if (speciesIdentity == null) { // speciesIdentity was placed in the parent node in CD 2.5
throw new InvalidXmlSchemaException(
"No celldesigner:extension node in SBML/model/listOfSpecies/species/annotation");
}
}
if (speciesIdentity == null) {
......@@ -213,7 +224,8 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec
}
if (species.getSubstanceUnits() != null) {
if (species.getSubstanceUnits() instanceof SbmlUnit) {
attributesBuilder.append(" substanceUnits=\"" + ((SbmlUnit)species.getSubstanceUnits()).getUnitId().toLowerCase() + "\"");
attributesBuilder
.append(" substanceUnits=\"" + ((SbmlUnit) species.getSubstanceUnits()).getUnitId().toLowerCase() + "\"");
} else {
attributesBuilder.append(" substanceUnits=\"" + species.getSubstanceUnits().toString().toLowerCase() + "\"");
}
......
......@@ -48,7 +48,20 @@ public enum ModifierType {
/**
* Trigger.
*/
TRIGGER_STRING("TRIGGER", Trigger.class, ArrowType.BLANK_CROSSBAR);
TRIGGER_STRING("TRIGGER", Trigger.class, ArrowType.BLANK_CROSSBAR),
/**
* CellDesigner 2.5 modification type.
*/
TRANSCRIPTIONAL_ACTIVATION("TRANSCRIPTIONAL_ACTIVATION", Trigger.class, ArrowType.BLANK_CROSSBAR),
/**
* CellDesigner 2.5 modification type.
*/
TRANSCRIPTIONAL_INHIBITION("TRANSCRIPTIONAL_INHIBITION", Inhibition.class, ArrowType.CROSSBAR, 8.0, ReactionCellDesignerConverter.RECT_SIZE / 2 - 1),
;
/**
* CellDesigner string describing this type.
......
......@@ -78,6 +78,16 @@ public class CellDesignerXmlParserTest extends CellDesignerTestFunctions {
super.testXmlSerialization(model);
}
@Test
public void testCellDesigner2_5() throws Exception {
CellDesignerXmlParser parser = new CellDesignerXmlParser();
Model model = parser
.createModel(new ConverterParams().filename("testFiles/problematic/MYO_signaling_pathway.xml")
.sizeAutoAdjust(false));
assertNotNull(model);
super.testXmlSerialization(model);
}
@Test
public void testUnknownCatalysisWithGate() throws Exception {
CellDesignerXmlParser parser = new CellDesignerXmlParser();
......
......@@ -70,4 +70,60 @@ public class CompartmentParserTests extends CellDesignerTestFunctions {
assertEquals(1, model.getElements().size());
}
@Test
public void testParseCompartmentBottomRight() throws Exception {
Model model = getModelForFile("testFiles/compartment/bottom_right_compartment.xml");
Compartment c = model.getElementByElementId("ca1");
assertTrue(c.getX() > 0);
assertTrue(c.getY() > 0);
assertTrue(c.getWidth() > 0);
assertTrue(c.getHeight() > 0);
assertEquals(1, model.getElements().size());
}
@Test
public void testParseCompartmentBottomLeft() throws Exception {
Model model = getModelForFile("testFiles/compartment/bottom_left_compartment.xml");
Compartment c = model.getElementByElementId("ca1");
assertEquals(c.getX(), 0, Configuration.EPSILON);
assertTrue(c.getY() > 0);
assertTrue(c.getWidth() > 0);
assertTrue(c.getHeight() > 0);
assertEquals(1, model.getElements().size());
}
@Test
public void testParseCompartmentTopLeft() throws Exception {
Model model = getModelForFile("testFiles/compartment/top_left_compartment.xml");
Compartment c = model.getElementByElementId("ca1");
assertEquals(c.getX(), 0, Configuration.EPSILON);
assertEquals(c.getY(), 0, Configuration.EPSILON);
assertTrue(c.getWidth() > 0);
assertTrue(c.getHeight() > 0);
assertEquals(1, model.getElements().size());
}
@Test
public void testParseCompartmentTopRight() throws Exception {
Model model = getModelForFile("testFiles/compartment/top_right_compartment.xml");
Compartment c = model.getElementByElementId("ca1");
assertTrue(c.getX() > 0);
assertEquals(c.getY(), 0, Configuration.EPSILON);
assertTrue(c.getWidth() > 0);
assertTrue(c.getHeight() > 0);
assertEquals(1, model.getElements().size());
}
@Test
public void testOldCellDesignerCompartment() throws Exception {
Model model = getModelForFile("testFiles/compartment/old_compartment.xml");
Compartment c = model.getElementByElementId("ca1");
assertEquals(1, model.getElements().size());
}
}
......@@ -36,7 +36,7 @@ public class ReactionCollectionXmlParserTest extends CellDesignerTestFunctions {
Model model = getModelFilledWithSpecies();
CellDesignerElementCollection elements = new CellDesignerElementCollection();
ReactionCollectionXmlParser parser = new ReactionCollectionXmlParser(model, elements, false);
ReactionCollectionXmlParser parser = new ReactionCollectionXmlParser(model, elements, false, false);
String xmlString = readFile("testFiles/reactions/listOfReactions.xml");
Node node = getNodeFromXmlString(xmlString);
......@@ -56,19 +56,19 @@ public class ReactionCollectionXmlParserTest extends CellDesignerTestFunctions {
Model model = getModelFilledWithSpecies();
CellDesignerElementCollection elements = new CellDesignerElementCollection();
ReactionCollectionXmlParser parser = new ReactionCollectionXmlParser(model, elements, false);
ReactionCollectionXmlParser parser = new ReactionCollectionXmlParser(model, elements, false, false);
String xmlString = readFile("testFiles/reactions/listOfReactions.xml");
Node node = getNodeFromXmlString(xmlString);
List<Reaction> reactions = parser.parseXmlReactionCollection(node);
elements = new CellDesignerElementCollection();
parser = new ReactionCollectionXmlParser(model, elements, false);
parser = new ReactionCollectionXmlParser(model, elements, false, false);
String xmlString2 = parser.reactionCollectionToXmlString(reactions);
assertNotNull(xmlString2);
elements = new CellDesignerElementCollection();
parser = new ReactionCollectionXmlParser(model, elements, false);
parser = new ReactionCollectionXmlParser(model, elements, false, false);
node = getNodeFromXmlString(xmlString2);
List<Reaction> reactions2 = parser.parseXmlReactionCollection(node);
......
......@@ -27,7 +27,7 @@ public class ReactionFromXmlTest extends CellDesignerTestFunctions {
@Before
public void setUp() throws Exception {
elements = new CellDesignerElementCollection();
parser = new ReactionXmlParser(elements, false);
parser = new ReactionXmlParser(elements, false, false);
Species alias = new GenericProtein("sa1");
model.addElement(alias);
......@@ -195,7 +195,7 @@ public class ReactionFromXmlTest extends CellDesignerTestFunctions {
public void testInvalidReaction() throws Exception {
// test situation when createProperTypeReaction returns reaction of
// unknown type
ReactionFromXml parser = new ReactionFromXml(null, false) {
ReactionFromXml parser = new ReactionFromXml(null, false, false) {
Reaction createProperTypeReaction(String type, Reaction result) {
return result;
}
......@@ -209,7 +209,7 @@ public class ReactionFromXmlTest extends CellDesignerTestFunctions {
// test situation when createProperTypeReaction returns reaction of
// unknown type that implements TwoProductReactionInterface
ReactionFromXml parser = new ReactionFromXml(null, false) {
ReactionFromXml parser = new ReactionFromXml(null, false, false) {
Reaction createProperTypeReaction(String type, Reaction reaction) {
Reaction result = Mockito.mock(Reaction.class,
Mockito.withSettings().extraInterfaces(TwoProductReactionInterface.class));
......@@ -229,7 +229,7 @@ public class ReactionFromXmlTest extends CellDesignerTestFunctions {
// test situation when createOperatorsForTwoProductReaction encounter
// reaction with two many base reactants
ReactionFromXml parser = new ReactionFromXml(null, false) {
ReactionFromXml parser = new ReactionFromXml(null, false, false) {
Reaction createProperTypeReaction(String type, Reaction result) throws ReactionParserException {
Reaction r = super.createProperTypeReaction(type, result);
r.addReactant(new Reactant());
......@@ -246,7 +246,7 @@ public class ReactionFromXmlTest extends CellDesignerTestFunctions {
// test situation when createOperatorsForTwoProductReaction encounter
// reaction with two many base products
ReactionFromXml parser = new ReactionFromXml(null, false) {
ReactionFromXml parser = new ReactionFromXml(null, false, false) {
Reaction createProperTypeReaction(String type, Reaction result) throws ReactionParserException {
Reaction r = super.createProperTypeReaction(type, result);
r.addProduct(new Product());
......@@ -263,7 +263,7 @@ public class ReactionFromXmlTest extends CellDesignerTestFunctions {
// test situation when createOperatorsForTwoReactantReaction encounter
// reaction with two many base products
ReactionFromXml parser = new ReactionFromXml(null, false) {
ReactionFromXml parser = new ReactionFromXml(null, false, false) {
Reaction createProperTypeReaction(String type, Reaction result) throws ReactionParserException {
Reaction r = super.createProperTypeReaction(type, result);
r.addProduct(new Product());
......@@ -276,14 +276,14 @@ public class ReactionFromXmlTest extends CellDesignerTestFunctions {
@Test(expected = InvalidArgumentException.class)
public void testParseInvalidEditPointsString() throws Exception {
ReactionFromXml parser = new ReactionFromXml(null, false);
ReactionFromXml parser = new ReactionFromXml(null, false, false);
parser.parseEditPointsString("1");
}
@Test(expected = InvalidArgumentException.class)
public void testParseInvalidEditPointsString2() throws Exception {
ReactionFromXml parser = new ReactionFromXml(null, false);
ReactionFromXml parser = new ReactionFromXml(null, false, false);
parser.parseEditPointsString("1,Infinity");
}
......
......@@ -28,13 +28,13 @@ public class ReactionParserTests extends CellDesignerTestFunctions {
ReactionXmlParser parser;
CellDesignerElementCollection elements;
private Logger logger = LogManager.getLogger(ReactionParserTests.class.getName());
private Logger logger = LogManager.getLogger();
@Before
public void setUp() throws Exception {
elements = new CellDesignerElementCollection();