private void realizeChemEdge( Graph2D graph, Edge newEdge, Attachment sourceAttachment, Attachment targetAttachment) { EdgeMap edgeTypeMap = (EdgeMap) graph.getDataProvider(EdgeMapKeys.EDGE_INFO); EdgeRealizer er = graph.getRealizer(newEdge); er.setLineColor(Color.BLACK); er.setLineType(LineType.LINE_1); edgeTypeMap.set(newEdge, new SViewEdgeInfo(EdgeType.CHEM, sourceAttachment, targetAttachment)); }
private void test(int seed) { RandomGraphGenerator rg = new RandomGraphGenerator(seed); rg.setNodeCount(100); rg.setEdgeCount(300); rg.allowCycles(true); Graph graph1 = rg.generate(); EdgeMap cycleEdge = Maps.createIndexEdgeMap(new boolean[graph1.E()]); // find a set of edges whose reversal make the given graph // acyclic. reverse whose edges t1.start(); Cycles.findCycleEdges(graph1, cycleEdge); int count1 = 0; for (EdgeCursor ec = graph1.edges(); ec.ok(); ec.next()) { if (cycleEdge.getBool(ec.edge())) { graph1.reverseEdge(ec.edge()); count1++; } } t1.stop(); // check acyclicity of graph if (GraphChecker.isCyclic(graph1)) { D.bug("graph1 still contains cycles!!!"); EdgeList cycle = Cycles.findCycle(graph1, true); error("cycle = " + cycle); } rg.setSeed(seed); Graph graph2 = rg.generate(); // use alternative DFS based method to detect // with a set of cyclicity edges. t2.start(); Cycles.findCycleEdgesDFS(graph2, cycleEdge); int count2 = 0; for (EdgeCursor ec = graph2.edges(); ec.ok(); ec.next()) { if (cycleEdge.getBool(ec.edge())) { graph2.reverseEdge(ec.edge()); count2++; } } t2.stop(); if (GraphChecker.isCyclic(graph2)) { D.bug("graph2 still contains cycles!!!"); EdgeList cycle = Cycles.findCycle(graph2, true); error("cycle = " + cycle); } akku1 += count1; akku2 += count2; }
private void addBranchToBranchEdge( Edge currentEdge, Attachment sourceAttachment, Attachment targetAttachment) { EdgeMap edgeTypeMap = (EdgeMap) _graph.getDataProvider(EdgeMapKeys.EDGE_INFO); Node sourceNode = _viewModel.getViewNode(currentEdge.source()); Node targetNode = _viewModel.getViewNode(currentEdge.target()); Edge newEdge = _graph.createEdge(sourceNode, targetNode); edgeTypeMap.set( newEdge, new SViewEdgeInfo(EdgeType.BRANCH_BRANCH, sourceAttachment, targetAttachment)); sourceNode = getViewStartingNode(newEdge.source(), _graph); targetNode = getViewStartingNode(newEdge.target(), _graph); _viewModel.addComplentaryViewNodes(sourceNode, targetNode); }
/** * get the starting node of the sequence in where the current node is sitting in * * @deprecated use getViewStartingNode * @param node * @param graph * @return */ @Deprecated private Node getStartingNode(Node node, Graph2D graph) { if (_viewModel.getStartingViewNodeList().contains(node)) { return node; } else { NodeCursor pres = node.predecessors(); Edge edge; Node currentNode = node; EdgeMap edgeMap = (EdgeMap) graph.getDataProvider(EdgeMapKeys.EDGE_INFO); Node preNode = currentNode; while (pres.ok()) { for (; pres.ok(); pres.next()) { edge = currentNode.getEdge(pres.node()); EdgeType edgeType = ((SViewEdgeInfo) edgeMap.get(edge)).getType(); if ((edgeType == EdgeType.REGULAR) || (edgeType == EdgeType.MODIFIED_P)) { currentNode = pres.node(); break; } } if (currentNode != preNode) { pres = currentNode.predecessors(); preNode = currentNode; } else { break; } } if (_viewModel.getStartingViewNodeList().contains(currentNode)) { return currentNode; } else { return null; } } }
/** * Create a standard graph. Each graph contains 3 nodes, base<-R->P where R and P are standard * monomers * * @param notation : the base monomer id. A, T, C, G, U * @return a graph that represents a notation */ @Deprecated public static Graph2D createNucleictideNodeGraph(String notation) throws MonomerException, IOException, JDOMException { // a graph is used in here because we need to associate data with every nodes Graph2D graph = new Graph2D(); graph.setDefaultNodeRealizer(new MonomerNodeRealizer()); NodeMap nodePropertiesNodeMap = graph.createNodeMap(); graph.addDataProvider(NodeMapKeys.MONOMER_REF, nodePropertiesNodeMap); EdgeMap edgeMap = graph.createEdgeMap(); graph.addDataProvider(EdgeMapKeys.EDGE_INFO, edgeMap); GraphCopier copier = new GraphCopier(graph.getGraphCopyFactory()); copier.setDataProviderContentCopying(true); copier.setEdgeMapCopying(true); copier.setNodeMapCopying(true); String baseMonomerID = notation.substring(notation.indexOf("(") + 1, notation.indexOf(")")); baseMonomerID = baseMonomerID.replace("[", ""); baseMonomerID = baseMonomerID.replace("]", ""); Node baseNode = copier.copy(createNucleicAcidBaseNode(baseMonomerID), graph).firstNode(); NodeRealizer baseNodeRealizer = graph.getRealizer(baseNode); baseNodeRealizer.setCenter(centerX, centerY + size + distance); String r = notation.substring(0, notation.indexOf("(")); r = r.replace("[", ""); r = r.replace("]", ""); Node rNode = copier.copy(createNucleicAcidBackboneNode(r, Monomer.ID_R), graph).firstNode(); NodeRealizer rNodeRealizer = graph.getRealizer(rNode); rNodeRealizer.setCenter(centerX, centerY); String p = notation.substring(notation.indexOf(")") + 1); p = p.replace("[", ""); p = p.replace("]", ""); Node pNode = copier.copy(createNucleicAcidBackboneNode(p, Monomer.ID_P), graph).firstNode(); NodeRealizer pNodeRealizer = graph.getRealizer(pNode); pNodeRealizer.setCenter(centerX + size + distance, centerY); MonomerInfo pKeys = (MonomerInfo) nodePropertiesNodeMap.get(pNode); MonomerInfo rKeys = (MonomerInfo) nodePropertiesNodeMap.get(rNode); MonomerInfo baseKeys = (MonomerInfo) nodePropertiesNodeMap.get(baseNode); // r->p Edge edge = graph.createEdge(rNode, pNode); Attachment sourceAttachment = rKeys.getAttachment(Attachment.BACKBONE_MONOMER_RIGHT_ATTACHEMENT); Attachment targetAttachment = pKeys.getAttachment(Attachment.BACKBONE_MONOMER_LEFT_ATTACHEMENT); rKeys.setConnection(sourceAttachment, true); pKeys.setConnection(targetAttachment, true); edgeMap.set(edge, new EditorEdgeInfoData(sourceAttachment, targetAttachment)); // r->base edge = graph.createEdge(rNode, baseNode); sourceAttachment = rKeys.getAttachment(Attachment.BACKBONE_MONOMER_BRANCH_ATTACHEMENT); targetAttachment = baseKeys.getAttachment(Attachment.BRANCH_MONOMER_ATTACHEMENT); rKeys.setConnection(sourceAttachment, true); baseKeys.setConnection(targetAttachment, true); edgeMap.set(edge, new EditorEdgeInfoData(sourceAttachment, targetAttachment)); return graph; }