X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=srcjar%2Ffr%2Forsay%2Flri%2Fvarna%2Fmodels%2Ftreealign%2FRNANodeValue2.java;fp=srcjar%2Ffr%2Forsay%2Flri%2Fvarna%2Fmodels%2Ftreealign%2FRNANodeValue2.java;h=6fff9a9b030618ad6e009d33f555d9cfda76405d;hb=2d6292c0377bc6b773c6844a45d3f2c5fac352c7;hp=0000000000000000000000000000000000000000;hpb=954af328a2a6a0055572cd1a09ee035301222574;p=jalview.git diff --git a/srcjar/fr/orsay/lri/varna/models/treealign/RNANodeValue2.java b/srcjar/fr/orsay/lri/varna/models/treealign/RNANodeValue2.java new file mode 100644 index 0000000..6fff9a9 --- /dev/null +++ b/srcjar/fr/orsay/lri/varna/models/treealign/RNANodeValue2.java @@ -0,0 +1,136 @@ +package fr.orsay.lri.varna.models.treealign; +import java.util.ArrayList; +import java.util.List; + + + +/** + * In this model, nodes are either: + * 1. a couple of paired bases, and in that case they may have children, + * in this case singleNode is true + * 2. a single base that comes from a broken base pair + * (broken during planarization), without children, + * in this case singleNode is true + * 3. a list of consecutive non-paired bases, without children. + * in this case singleNode is false + * Note that case 2 happens only if original sequences contained + * pseudoknots, otherwise this case can be ignored. + * + * @author Raphael Champeimont + * + */ +public class RNANodeValue2 implements GraphvizDrawableNodeValue { + /** + * Says whether we have a single node or a list of nodes. + */ + private boolean singleNode = true; + + /** + * Defined if singleNode is true. + */ + private RNANodeValue node; + + /** + * Defined if singleNode is false; + */ + private List nodes; + + public RNANodeValue2(boolean singleNode) { + this.singleNode = singleNode; + if (singleNode) { + node = new RNANodeValue(); + } else { + nodes = new ArrayList(); + } + } + + /** + * In case of a single node, return it. + * Will throw RNANodeValue2WrongTypeException if singleNode = false. + */ + public RNANodeValue getNode() { + if (singleNode) { + return node; + } else { + throw (new RNANodeValue2WrongTypeException()); + } + } + + public void setNode(RNANodeValue node) { + if (singleNode) { + this.node = node; + } else { + throw (new RNANodeValue2WrongTypeException()); + } + } + + /** + * In case of multiple nodes, return them. + * Will throw RNANodeValue2WrongTypeException if singleNode = true. + */ + public List getNodes() { + if (!singleNode) { + return nodes; + } else { + throw (new RNANodeValue2WrongTypeException()); + } + } + /** + * In case of multiple nodes, return the sequence of nucleotides. + */ + public char[] computeSequence() { + if (!singleNode) { + final int n = nodes.size(); + char[] sequence = new char[n]; + for (int i=0; i nodes) { + if (!singleNode) { + this.nodes = nodes; + } else { + throw (new RNANodeValue2WrongTypeException()); + } + } + + public boolean isSingleNode() { + return singleNode; + } + + public String toString() { + if (singleNode) { + return node.toString(); + } else { + String s = ""; + for (RNANodeValue node: nodes) { + if (s != "") { + s += " "; + } + s += node.toString(); + } + return s; + } + } + + public String toGraphvizNodeName() { + if (singleNode) { + return node.toGraphvizNodeName(); + } else { + String s = ""; + for (RNANodeValue node: nodes) { + if (s != "") { + s += " "; + } + s += node.toGraphvizNodeName(); + } + return s; + } + } + +}