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

parsing of colors in boolean gate reaction added

parent 7a8ac224
No related branches found
No related tags found
1 merge request!897Resolve "boolean reaction colouring not working"
...@@ -409,6 +409,9 @@ public class ReactionFromXml { ...@@ -409,6 +409,9 @@ public class ReactionFromXml {
} }
applyStylingToLine(line, result.getLine()); applyStylingToLine(line, result.getLine());
if (booleanLogicGateType!=null) {
assignColorFromGateMembers(result, gateMembers);
}
if (reactantsLinkNode != null) { if (reactantsLinkNode != null) {
parseReactantLinks(result, reactantsLinkNode, model); parseReactantLinks(result, reactantsLinkNode, model);
} }
...@@ -927,6 +930,36 @@ public class ReactionFromXml { ...@@ -927,6 +930,36 @@ public class ReactionFromXml {
} }
} }
private void assignColorFromGateMembers(Reaction result, Node gateMembers) {
int elementIndex = 0;
for (int i = 0; i < gateMembers.getChildNodes().getLength(); i++) {
Node child = gateMembers.getChildNodes().item(i);
if (child.getNodeType() == Node.ELEMENT_NODE) {
if (child.getNodeName().equalsIgnoreCase("celldesigner:GateMember")) {
Node lineNode = XmlParser.getNode("celldesigner:line", child);
if (lineNode != null) {
LineProperties line = getLineProperties(lineNode);
PolylineData polyline = null;
if (elementIndex == 0) {
if (result.getOperators().size() > 0) {
polyline = result.getOperators().get(result.getOperators().size() - 1).getLine();
}
} else {
if (result.getReactants().size() >= elementIndex) {
polyline = result.getReactants().get(elementIndex - 1).getLine();
}
}
if (polyline != null) {
polyline.setColor(line.getColor());
polyline.setWidth(line.getWidth());
}
}
elementIndex++;
}
}
}
}
/** /**
* Creates lines for reaction that belongs to * Creates lines for reaction that belongs to
* {@link TwoProductReactionInterface}. * {@link TwoProductReactionInterface}.
......
...@@ -759,4 +759,19 @@ public class CellDesignerXmlParserTest extends CellDesignerTestFunctions { ...@@ -759,4 +759,19 @@ public class CellDesignerXmlParserTest extends CellDesignerTestFunctions {
assertEquals(0, new ModelComparator().compare(model, model2)); assertEquals(0, new ModelComparator().compare(model, model2));
} }
@Test
public void testParseBooleanReactionWithColors() throws Exception {
CellDesignerXmlParser parser = new CellDesignerXmlParser();
Model model = parser.createModel(new ConverterParams().filename("testFiles/reactions/boolean-colors.xml"));
Reaction r1 = model.getReactionByReactionId("re1");
Set<Color> colors = new HashSet<>();
for (AbstractNode node : r1.getNodes()) {
colors.add(node.getLine().getColor());
}
assertEquals("Three different colors were used to draw the reaction", 3, colors.size());
assertFalse("Black wasn't used in reaction coloring", colors.contains(Color.BLACK));
}
} }
<?xml version="1.0" encoding="UTF-8"?>
<sbml xmlns="http://www.sbml.org/sbml/level2/version4" xmlns:celldesigner="http://www.sbml.org/2001/ns/celldesigner" level="2" version="4">
<model metaid="untitled" id="untitled">
<annotation>
<celldesigner:extension>
<celldesigner:modelVersion>4.0</celldesigner:modelVersion>
<celldesigner:modelDisplay sizeX="600" sizeY="400"/>
<celldesigner:listOfCompartmentAliases/>
<celldesigner:listOfComplexSpeciesAliases/>
<celldesigner:listOfSpeciesAliases>
<celldesigner:speciesAlias id="sa1" species="s1">
<celldesigner:activity>inactive</celldesigner:activity>
<celldesigner:bounds x="86.0" y="110.0" w="80.0" h="40.0"/>
<celldesigner:font size="12"/>
<celldesigner:view state="usual"/>
<celldesigner:usualView>
<celldesigner:innerPosition x="0.0" y="0.0"/>
<celldesigner:boxSize width="80.0" height="40.0"/>
<celldesigner:singleLine width="1.0"/>
<celldesigner:paint color="ffccffcc" scheme="Color"/>
</celldesigner:usualView>
<celldesigner:briefView>
<celldesigner:innerPosition x="0.0" y="0.0"/>
<celldesigner:boxSize width="80.0" height="60.0"/>
<celldesigner:singleLine width="0.0"/>
<celldesigner:paint color="3fff0000" scheme="Color"/>
</celldesigner:briefView>
<celldesigner:info state="empty" angle="-1.5707963267948966"/>
</celldesigner:speciesAlias>
<celldesigner:speciesAlias id="sa2" species="s2">
<celldesigner:activity>inactive</celldesigner:activity>
<celldesigner:bounds x="91.0" y="220.0" w="80.0" h="40.0"/>
<celldesigner:font size="12"/>
<celldesigner:view state="usual"/>
<celldesigner:usualView>
<celldesigner:innerPosition x="0.0" y="0.0"/>
<celldesigner:boxSize width="80.0" height="40.0"/>
<celldesigner:singleLine width="1.0"/>
<celldesigner:paint color="ffccffcc" scheme="Color"/>
</celldesigner:usualView>
<celldesigner:briefView>
<celldesigner:innerPosition x="0.0" y="0.0"/>
<celldesigner:boxSize width="80.0" height="60.0"/>
<celldesigner:singleLine width="0.0"/>
<celldesigner:paint color="3fff0000" scheme="Color"/>
</celldesigner:briefView>
<celldesigner:info state="empty" angle="-1.5707963267948966"/>
</celldesigner:speciesAlias>
<celldesigner:speciesAlias id="sa3" species="s3">
<celldesigner:activity>inactive</celldesigner:activity>
<celldesigner:bounds x="371.0" y="157.0" w="80.0" h="40.0"/>
<celldesigner:font size="12"/>
<celldesigner:view state="usual"/>
<celldesigner:usualView>
<celldesigner:innerPosition x="0.0" y="0.0"/>
<celldesigner:boxSize width="80.0" height="40.0"/>
<celldesigner:singleLine width="1.0"/>
<celldesigner:paint color="ffccffcc" scheme="Color"/>
</celldesigner:usualView>
<celldesigner:briefView>
<celldesigner:innerPosition x="0.0" y="0.0"/>
<celldesigner:boxSize width="80.0" height="60.0"/>
<celldesigner:singleLine width="0.0"/>
<celldesigner:paint color="3fff0000" scheme="Color"/>
</celldesigner:briefView>
<celldesigner:info state="empty" angle="-1.5707963267948966"/>
</celldesigner:speciesAlias>
</celldesigner:listOfSpeciesAliases>
<celldesigner:listOfGroups/>
<celldesigner:listOfProteins>
<celldesigner:protein id="pr1" name="s1" type="GENERIC"/>
<celldesigner:protein id="pr2" name="s2" type="GENERIC"/>
<celldesigner:protein id="pr3" name="s3" type="GENERIC"/>
</celldesigner:listOfProteins>
<celldesigner:listOfGenes/>
<celldesigner:listOfRNAs/>
<celldesigner:listOfAntisenseRNAs/>
<celldesigner:listOfLayers/>
<celldesigner:listOfBlockDiagrams/>
</celldesigner:extension>
</annotation>
<listOfUnitDefinitions>
<unitDefinition metaid="substance" id="substance" name="substance">
<listOfUnits>
<unit metaid="CDMT00004" kind="mole"/>
</listOfUnits>
</unitDefinition>
<unitDefinition metaid="volume" id="volume" name="volume">
<listOfUnits>
<unit metaid="CDMT00005" kind="litre"/>
</listOfUnits>
</unitDefinition>
<unitDefinition metaid="area" id="area" name="area">
<listOfUnits>
<unit metaid="CDMT00006" kind="metre" exponent="2"/>
</listOfUnits>
</unitDefinition>
<unitDefinition metaid="length" id="length" name="length">
<listOfUnits>
<unit metaid="CDMT00007" kind="metre"/>
</listOfUnits>
</unitDefinition>
<unitDefinition metaid="time" id="time" name="time">
<listOfUnits>
<unit metaid="CDMT00008" kind="second"/>
</listOfUnits>
</unitDefinition>
</listOfUnitDefinitions>
<listOfCompartments>
<compartment metaid="default" id="default" size="1" units="volume"/>
</listOfCompartments>
<listOfSpecies>
<species metaid="s1" id="s1" name="s1" compartment="default" initialAmount="0">
<annotation>
<celldesigner:extension>
<celldesigner:positionToCompartment>inside</celldesigner:positionToCompartment>
<celldesigner:speciesIdentity>
<celldesigner:class>PROTEIN</celldesigner:class>
<celldesigner:proteinReference>pr1</celldesigner:proteinReference>
</celldesigner:speciesIdentity>
</celldesigner:extension>
</annotation>
</species>
<species metaid="s2" id="s2" name="s2" compartment="default" initialAmount="0">
<annotation>
<celldesigner:extension>
<celldesigner:positionToCompartment>inside</celldesigner:positionToCompartment>
<celldesigner:speciesIdentity>
<celldesigner:class>PROTEIN</celldesigner:class>
<celldesigner:proteinReference>pr2</celldesigner:proteinReference>
</celldesigner:speciesIdentity>
</celldesigner:extension>
</annotation>
</species>
<species metaid="s3" id="s3" name="s3" compartment="default" initialAmount="0">
<annotation>
<celldesigner:extension>
<celldesigner:positionToCompartment>inside</celldesigner:positionToCompartment>
<celldesigner:speciesIdentity>
<celldesigner:class>PROTEIN</celldesigner:class>
<celldesigner:proteinReference>pr3</celldesigner:proteinReference>
</celldesigner:speciesIdentity>
</celldesigner:extension>
</annotation>
</species>
</listOfSpecies>
<listOfReactions>
<reaction metaid="re1" id="re1" reversible="false">
<annotation>
<celldesigner:extension>
<celldesigner:reactionType>BOOLEAN_LOGIC_GATE</celldesigner:reactionType>
<celldesigner:baseReactants>
<celldesigner:baseReactant species="s2" alias="sa2"/>
<celldesigner:baseReactant species="s1" alias="sa1"/>
</celldesigner:baseReactants>
<celldesigner:baseProducts>
<celldesigner:baseProduct species="s3" alias="sa3"/>
</celldesigner:baseProducts>
<celldesigner:connectScheme connectPolicy="direct"/>
<celldesigner:editPoints>264.66666666666663,177.0</celldesigner:editPoints>
<celldesigner:line width="1.0" color="ffff00ff"/>
<celldesigner:listOfGateMember>
<celldesigner:GateMember type="BOOLEAN_LOGIC_GATE_AND" aliases="sa2,sa1" modificationType="REDUCED_TRIGGER" targetLineIndex="-1,-1" editPoints="264.66666666666663,177.0">
<celldesigner:connectScheme connectPolicy="direct">
<celldesigner:listOfLineDirection>
<celldesigner:lineDirection index="0" value="unknown"/>
</celldesigner:listOfLineDirection>
</celldesigner:connectScheme>
<celldesigner:line width="1.0" color="ffff00ff"/>
</celldesigner:GateMember>
<celldesigner:GateMember type="REDUCED_TRIGGER" aliases="sa2">
<celldesigner:connectScheme connectPolicy="direct">
<celldesigner:listOfLineDirection>
<celldesigner:lineDirection index="0" value="unknown"/>
</celldesigner:listOfLineDirection>
</celldesigner:connectScheme>
<celldesigner:linkTarget species="s2" alias="sa2">
<celldesigner:linkAnchor position="INACTIVE"/>
</celldesigner:linkTarget>
<celldesigner:line width="1.0" color="ff00cc33"/>
</celldesigner:GateMember>
<celldesigner:GateMember type="REDUCED_TRIGGER" aliases="sa1" targetLineIndex="-1,0">
<celldesigner:connectScheme connectPolicy="direct">
<celldesigner:listOfLineDirection>
<celldesigner:lineDirection index="0" value="unknown"/>
</celldesigner:listOfLineDirection>
</celldesigner:connectScheme>
<celldesigner:linkTarget species="s1" alias="sa1">
<celldesigner:linkAnchor position="INACTIVE"/>
</celldesigner:linkTarget>
<celldesigner:line width="1.0" color="ffff9999"/>
</celldesigner:GateMember>
</celldesigner:listOfGateMember>
</celldesigner:extension>
</annotation>
<listOfReactants>
<speciesReference metaid="CDMT00001" species="s2">
<annotation>
<celldesigner:extension>
<celldesigner:alias>sa2</celldesigner:alias>
</celldesigner:extension>
</annotation>
</speciesReference>
<speciesReference metaid="CDMT00002" species="s1">
<annotation>
<celldesigner:extension>
<celldesigner:alias>sa1</celldesigner:alias>
</celldesigner:extension>
</annotation>
</speciesReference>
</listOfReactants>
<listOfProducts>
<speciesReference metaid="CDMT00003" species="s3">
<annotation>
<celldesigner:extension>
<celldesigner:alias>sa3</celldesigner:alias>
</celldesigner:extension>
</annotation>
</speciesReference>
</listOfProducts>
</reaction>
</listOfReactions>
</model>
</sbml>
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