Commit 0f328b00 authored by Piotr Gawron's avatar Piotr Gawron

Merge branch '560-logic-gates-with-over-2-inputs' into 'master'

Resolve "Logic Gates with over 2 inputs"

Closes #560

See merge request !811
parents 724d5139 6fde2e81
Pipeline #10661 passed with stage
in 9 minutes and 36 seconds
......@@ -20,7 +20,7 @@ public class CellDesignerPointTransformation extends PointTransformation {
private static Logger logger = LogManager.getLogger(CellDesignerPointTransformation.class.getName());
/**
* This method transform coordinates of pointP in celldesginer format (base:
* This method transform coordinates of pointP in CellDesginer format (base:
* pointA, pointB, pointC) into normal x,y coordinates.
*
* In CellDesigner some points are in different base consisted from three
......
......@@ -119,7 +119,9 @@ public class ReactionToXml {
sb.append("<reaction ");
sb.append("metaid=\"" + reaction.getIdReaction() + "\" ");
sb.append("id=\"" + reaction.getIdReaction() + "\" ");
sb.append("name=\"" + reaction.getName() + "\" ");
if (reaction.getName() != null && !reaction.getName().isEmpty()) {
sb.append("name=\"" + reaction.getName() + "\" ");
}
sb.append("reversible=\"" + reaction.isReversible() + "\" ");
sb.append(">\n");
if (reaction.getNotes() != null && !reaction.getNotes().equals("")) {
......@@ -499,7 +501,7 @@ public class ReactionToXml {
StringBuilder sb = new StringBuilder();
sb.append("<annotation>\n");
sb.append("<celldesigner:extension>\n");
sb.append("<celldesigner:reactionType>" + reactionClassString + "</celldesigner:reactionType>");
sb.append("<celldesigner:reactionType>" + reactionClassString + "</celldesigner:reactionType>\n");
sb.append(getBaseReactantsXmlStringForReaction(reaction));
sb.append(getBaseProductsXmlStringForReaction(reaction));
sb.append(getListOfReactantLinksXmlStringForReaction(reaction));
......@@ -700,7 +702,7 @@ public class ReactionToXml {
sb.append("color=\"" + XmlParser.colorToString(reactant.getLine().getColor()) + "\" ");
sb.append("type=\"Straight\" ");
sb.append("/>\n");
sb.append("</celldesigner:reactantLink>");
sb.append("</celldesigner:reactantLink>\n");
return sb.toString();
}
......@@ -733,7 +735,7 @@ public class ReactionToXml {
sb.append("color=\"" + XmlParser.colorToString(product.getLine().getColor()) + "\" ");
sb.append("type=\"Straight\" ");
sb.append("/>\n");
sb.append("</celldesigner:productLink>");
sb.append("</celldesigner:productLink>\n");
return sb.toString();
}
......@@ -807,10 +809,10 @@ public class ReactionToXml {
private String getEditPointsXmlStringForLine(PolylineData[] lines, Point2D centerPoint, Integer centerIndex) {
StringBuilder sb = new StringBuilder();
sb.append("<celldesigner:editPoints ");
sb.append("<celldesigner:editPoints");
if (lines.length > 1) {
for (int i = 0; i < lines.length; i++) {
sb.append(" num" + i + "=\"" + (lines[i].getPoints().size() - 2) + "\" ");
sb.append(" num" + i + "=\"" + (lines[i].getPoints().size() - 2) + "\"");
}
if (centerIndex != null) {
sb.append(" tShapeIndex=\"" + centerIndex + "\"");
......
......@@ -13,162 +13,75 @@ import java.util.List;
*/
public class EditPoints {
/**
* List of internal points in CellDesigner format. Usually it means that edge
* values represents base in which the interanal points are stored. However,
* it doesn't have to be true in all case. For more detail analysie usage of
* this class in the parser.
*
* @see lcsb.mapviewer.converter.model.celldesigner.geometry.helper.PolylineDataFactory#createPolylineDataFromEditPoints(Point2D,
* Point2D, EditPoints)
*/
private List<Point2D> points;
/**
* This value in reactions with three base reactants+products (reactions that
* implements
* {@link lcsb.mapviewer.db.model.map.reaction.type.TwoReactantReactionInterface
* TwoReactantReactionInterface} or
* {@link lcsb.mapviewer.db.model.map.reaction.type.TwoProductReactionInterface
* TwoProductReactionInterface}) define where starts the first line in this
* strange line description. See also usage of this field in CellDesigner
* parser.
*/
private int num0;
/**
* This value in reactions with three base reactants+products (reactions that
* implements
* {@link lcsb.mapviewer.db.model.map.reaction.type.TwoReactantReactionInterface
* TwoReactantReactionInterface} or
* {@link lcsb.mapviewer.db.model.map.reaction.type.TwoProductReactionInterface
* TwoProductReactionInterface}) define where starts the second line in this
* strange line description. See also usage of this field in CellDesigner
* parser.
*/
private int num1;
/**
* This value in reactions with three base reactants+products (reactions that
* implements
* {@link lcsb.mapviewer.db.model.map.reaction.type.TwoReactantReactionInterface
* TwoReactantReactionInterface} or
* {@link lcsb.mapviewer.db.model.map.reaction.type.TwoProductReactionInterface
* TwoProductReactionInterface}) define where starts the third line in this
* strange line description. See also usage of this field in CellDesigner
* parser.
*/
private int num2;
/**
* This value defines in which segment center of the reaction is put.
*/
private Integer index;
/**
* Default constructor.
*/
public EditPoints() {
points = new ArrayList<Point2D>();
num0 = 0;
num1 = 0;
num2 = 0;
index = null;
}
/**
* @return the points
* @see #points
*/
public List<Point2D> getPoints() {
return points;
}
/**
* @param points
* the points to set
* @see #points
*/
public void setPoints(List<Point2D> points) {
this.points = points;
}
/**
* @return the num0
* @see #num0
*/
public int getNum0() {
return num0;
}
/**
* @param num0
* the num0 to set
* @see #num0
*/
public void setNum0(int num0) {
this.num0 = num0;
}
/**
* @return the num1
* @see #num1
*/
public int getNum1() {
return num1;
}
/**
* @param num1
* the num1 to set
* @see #num1
*/
public void setNum1(int num1) {
this.num1 = num1;
}
/**
* @return the num2
* @see #num2
*/
public int getNum2() {
return num2;
}
/**
* @param num2
* the num2 to set
* @see #num2
*/
public void setNum2(int num2) {
this.num2 = num2;
}
/**
* @return the index
* @see #index
*/
public Integer getIndex() {
return index;
}
/**
* @param index
* the index to set
* @see #index
*/
public void setIndex(Integer index) {
this.index = index;
}
/**
* Returns number of points in the line.
*
* @return number of points in the line
*/
public int size() {
return points.size();
}
/**
* List of internal points in CellDesigner format. Usually it means that edge
* values represents base in which the internal points are stored. However, it
* doesn't have to be true in all case. For more detail analyze usage of this
* class in the parser.
*
* @see lcsb.mapviewer.converter.model.celldesigner.geometry.helper.PolylineDataFactory#createPolylineDataFromEditPoints(Point2D,
* Point2D, EditPoints)
*/
private List<Point2D> points = new ArrayList<>();
/**
* This list in reactions with three base reactants+products (reactions that
* implements
* {@link lcsb.mapviewer.db.model.map.reaction.type.TwoReactantReactionInterface
* TwoReactantReactionInterface} or
* {@link lcsb.mapviewer.db.model.map.reaction.type.TwoProductReactionInterface
* TwoProductReactionInterface}) defines where the different lines start in this
* strange line description. See also usage of this field in CellDesigner
* parser.
*/
private List<Integer> lineStartingPoints = new ArrayList<>();
/**
* This value defines in which segment center of the reaction is put.
*/
private Integer reactionCenterLineIndex = null;
/**
* @return the points
* @see #points
*/
public List<Point2D> getPoints() {
return points;
}
/**
* @param points
* the points to set
* @see #points
*/
public void setPoints(List<Point2D> points) {
this.points = points;
}
public void addNum(int num) {
lineStartingPoints.add(num);
}
public Integer getReactionCenterLineIndex() {
return reactionCenterLineIndex;
}
public void setReactionCenterLineIndex(Integer index) {
this.reactionCenterLineIndex = index;
}
/**
* Returns number of points in the line.
*
* @return number of points in the line
*/
public int size() {
return points.size();
}
public List<Integer> getLineStartingPoints() {
return lineStartingPoints;
}
}
......@@ -204,19 +204,6 @@ public class ReactionFromXmlTest extends CellDesignerTestFunctions {
}
}
@Test
public void testInvalid13() throws Exception {
try {
parser.getReaction(super.getNodeFromXmlString(readFile("testFiles/invalid/reaction13.xml")), model);
fail("Exception expected");
} catch (ReactionParserException e) {
assertTrue(e.getMessage().contains("Too many gate members"));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testInvalid14() throws Exception {
try {
......@@ -578,30 +565,6 @@ public class ReactionFromXmlTest extends CellDesignerTestFunctions {
}
}
@Test
public void testInvalidReaction6() throws Exception {
try {
// test situation when createOperatorsForTwoReactantReaction encounter
// reaction with two many base reactants
ReactionFromXml parser = new ReactionFromXml(null, false) {
Reaction createProperTypeReaction(String type, Reaction result) throws ReactionParserException {
Reaction r = super.createProperTypeReaction(type, result);
r.addReactant(new Reactant());
return r;
}
};
parser.getReaction(super.getNodeFromXmlString(readFile("testFiles/xmlNodeTestExamples/reaction_heterodimer.xml")),
model);
fail("Exception expected");
} catch (ReactionParserException e) {
assertTrue(e.getMessage().contains("Too many reactants"));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testInvalidReaction7() throws Exception {
......
......@@ -854,7 +854,7 @@ public class ReactionParserTests extends CellDesignerTestFunctions {
}
}
assertNotNull(r);
// I think there is still a bug becaue it should work with smaller delta
// I think there is still a bug because it should work with smaller delta
// :)
assertEquals(r.getLine().getPoints().get(1).getX(), r.getLine().getPoints().get(2).getX(), 1);
......@@ -1913,4 +1913,27 @@ public class ReactionParserTests extends CellDesignerTestFunctions {
}
}
@Test
public void testGateReactionWithMoreParticipants() throws Exception {
Model model;
try {
model = getModelForFile("testFiles/reactions/logicGateWithMoreParticipants.xml");
Reaction reaction = model.getReactionByReactionId("re1");
assertEquals(3, reaction.getReactants().size());
Reactant r1 = reaction.getReactants().get(0);
Reactant r2 = reaction.getReactants().get(1);
Reactant r3 = reaction.getReactants().get(2);
Product p = reaction.getProducts().get(0);
assertEquals(3, r1.getLine().getPoints().size());
assertEquals(2, r2.getLine().getPoints().size());
assertEquals(3, r3.getLine().getPoints().size());
assertEquals(2, p.getLine().getPoints().size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
<reaction metaid="re2" id="re2" reversible="false">
<annotation>
<celldesigner:extension>
<celldesigner:reactionType>BOOLEAN_LOGIC_GATE</celldesigner:reactionType>
<celldesigner:baseReactants>
<celldesigner:baseReactant species="s1" alias="sa1"/>
<celldesigner:baseReactant species="s2" alias="sa2"/>
</celldesigner:baseReactants>
<celldesigner:baseProducts>
<celldesigner:baseProduct species="s3" alias="sa3"/>
</celldesigner:baseProducts>
<celldesigner:connectScheme connectPolicy="direct"/>
<celldesigner:editPoints>0.2457561456645776,0.36940903007677645 0.4616468267943936,-8.326672684688674E-16 0.6022046911319296,0.37050081003028695 1.0170811819801924,0.3513278718497636 200.0,127.0</celldesigner:editPoints>
<celldesigner:line width="1.0" color="ff000000"/>
<celldesigner:listOfGateMember>
<celldesigner:GateMember type="BOOLEAN_LOGIC_GATE_AND" aliases="sa1,sa2" modificationType="REDUCED_TRIGGER" editPoints="0.2457561456645776,0.36940903007677645 0.4616468267943936,-8.326672684688674E-16 0.6022046911319296,0.37050081003028695 1.0170811819801924,0.3513278718497636 200.0,127.0">
<celldesigner:connectScheme connectPolicy="direct">
<celldesigner:listOfLineDirection>
<celldesigner:lineDirection index="0" value="unknown"/>
<celldesigner:lineDirection index="1" value="unknown"/>
<celldesigner:lineDirection index="2" value="unknown"/>
<celldesigner:lineDirection index="3" value="unknown"/>
<celldesigner:lineDirection index="4" value="unknown"/>
</celldesigner:listOfLineDirection>
</celldesigner:connectScheme>
<celldesigner:line width="1.0" color="ff000000"/>
</celldesigner:GateMember>
<celldesigner:GateMember type="REDUCED_TRIGGER" aliases="sa1" targetLineIndex="-1,0" editPoints="0.9925303887909439,-0.7288670316414586 0.47916819439335245,0.25844368507993626">
<celldesigner:connectScheme connectPolicy="direct">
<celldesigner:listOfLineDirection>
<celldesigner:lineDirection index="0" value="unknown"/>
<celldesigner:lineDirection index="1" value="unknown"/>
<celldesigner:lineDirection index="2" value="unknown"/>
</celldesigner:listOfLineDirection>
</celldesigner:connectScheme>
<celldesigner:line width="1.0" color="ff000000"/>
</celldesigner:GateMember>
<celldesigner:GateMember type="REDUCED_TRIGGER" aliases="sa1" targetLineIndex="-1,0" editPoints="0.9925303887909439,-0.7288670316414586 0.47916819439335245,0.25844368507993626">
<celldesigner:connectScheme connectPolicy="direct">
<celldesigner:listOfLineDirection>
<celldesigner:lineDirection index="0" value="unknown"/>
<celldesigner:lineDirection index="1" value="unknown"/>
<celldesigner:lineDirection index="2" value="unknown"/>
</celldesigner:listOfLineDirection>
</celldesigner:connectScheme>
<celldesigner:line width="1.0" color="ff000000"/>
</celldesigner:GateMember>
<celldesigner:GateMember type="REDUCED_TRIGGER" aliases="sa2" targetLineIndex="-1,0" editPoints="0.24060913705583764,0.46548223350253837">
<celldesigner:connectScheme connectPolicy="direct">
<celldesigner:listOfLineDirection>
<celldesigner:lineDirection index="0" value="unknown"/>
<celldesigner:lineDirection index="1" value="unknown"/>
</celldesigner:listOfLineDirection>
</celldesigner:connectScheme>
<celldesigner:line width="1.0" color="ff000000"/>
</celldesigner:GateMember>
</celldesigner:listOfGateMember>
</celldesigner:extension>
</annotation>
<listOfReactants>
<speciesReference metaid="CDMT00001" species="s1">
<annotation>
<celldesigner:extension>
<celldesigner:alias>sa1</celldesigner:alias>
</celldesigner:extension>
</annotation>
</speciesReference>
<speciesReference metaid="CDMT00002" species="s2">
<annotation>
<celldesigner:extension>
<celldesigner:alias>sa2</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>
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