def test_findPathZero(self): graphFile = '../data/test_zero.tlp' graph = tlp.loadGraph(graphFile) sourceId = 176 targetId = 606 maxNumHops = 1 sourceNode = tp.getNodeById(sourceId, graph) targetNode = tp.getNodeById(targetId, graph) finder = tp.PathFinder(graph) finder.findPaths(sourceNode, targetNode, maxNumHops) self.assertTrue(len(finder.valid) == 1) self.assertTrue(finder.valid[0].isSane()) self.assertTrue(len(finder.failed) == 0)
def test_findPathOne(self): graphFile = '../data/test_one.tlp' sourceId = 176 targetId = 606 maxNumHops = 4 graph = tlp.loadGraph(graphFile) sourceNode = tp.getNodeById(sourceId, graph) targetNode = tp.getNodeById(targetId, graph) finder = tp.PathFinder(graph) finder.findPaths(sourceNode, targetNode, maxNumHops) self.assertTrue(len(finder.valid) == 4) self.assertTrue(len(finder.failed) == 1) for path in finder.valid: self.assertTrue(path.isSane())
def test_basicStatCounting(self): graphFile = '../data/test_one.tlp' sourceId = 176 targetId = 606 maxNumHops = 4 graph = tlp.loadGraph(graphFile) sourceNode = tp.getNodeById(sourceId, graph) targetNode = tp.getNodeById(targetId, graph) finder = tp.PathFinder(graph) finder.findPaths(sourceNode, targetNode, maxNumHops) stats = tp.PathStats(finder.valid) # Tests of unique path counting self.assertTrue(stats.getNumPathsWithLoop() == 2) self.assertTrue(stats.getNumUniqueTypes() == 4) self.assertTrue(stats.getNumPaths() == len(finder.valid))
def test_findAllPaths(self): graphFile = '../data/test_one.tlp' maxNumHops = 2 sourceId = 176 graph = tlp.loadGraph(graphFile) sourceNode = tp.getNodeById(sourceId, graph) finder = tp.PathFinder(graph) finder.findAllPaths(sourceNode, maxNumHops) self.assertTrue(len(finder.valid) == 3)
def test_intermediateStatCounting(self): graphFile = '../data/test_two.tlp' sourceId = 5860 targetId = 606 maxNumHops = 2 graph = tlp.loadGraph(graphFile) sourceNode = tp.getNodeById(sourceId, graph) targetNode = tp.getNodeById(targetId, graph) finder = tp.PathFinder(graph) finder.findPaths(sourceNode, targetNode, maxNumHops) stats = tp.PathStats(finder.valid) self.assertTrue(stats.getNumPathsWithLoop() == 0) self.assertTrue(stats.getNumPaths() == len(finder.valid)) self.assertTrue(stats.getNumUniqueTypes() == 2) unique = stats.getUniqueTypes() self.assertTrue(unique[0].toStringOfTypes( ) == 'GAC Aii, Gap Junction, CBb3-4i, Ribbon Synapse, GC ON') self.assertTrue(unique[1].toStringOfTypes() == 'GAC Aii, Gap Junction, CBb4w, Ribbon Synapse, GC ON')
def setUp(self): self.graph = tlp.loadGraph('../data/test_one.tlp') self.startNodeId = 606 self.path = tp.Path(self.graph) node = tp.getNodeById(self.startNodeId, self.graph) self.path.addNode(node) edges = self.graph.getOutEdges(node) for edge in edges: self.path.addEdge(edge) self.lastNode = self.graph.target(edge) self.path.addNode(self.lastNode) break
def test_pathTracker(self): tp.VERBOSE = True graphFile = '../data/test_one.tlp' maxNumHops = 2 sourceId = 176 graph = tlp.loadGraph(graphFile) sourceNode = tp.getNodeById(sourceId, graph) finder = tp.PathFinder(graph) finder.findAllPaths(sourceNode, maxNumHops) tracker = tp.PathTracker() for path in finder.valid: tracker.getOrCreatePathTypeID(path) self.assertTrue(tracker.getNumUniquePathTypes() == 3) for i in range(0, len(finder.valid)): self.assertTrue(tracker.getOrCreatePathTypeID(finder.valid[i]) == i)
""" Example of finding paths and visualizing them for debugging. """ from tulip import * from tulipgui import * import tulippaths as tp # Path parameters graphFile = '../data/test_one.tlp' sourceNodeId = 176 maxNumHops = 2 # Load the graph graph = tlp.loadGraph(graphFile) # Find start and end nodes source = tp.getNodeById(sourceNodeId, graph) # Find paths finder = tp.PathFinder(graph) results = finder.findAllPaths(source, maxNumHops) print('The valid paths are:') for path in finder.valid: print((' ' + path.toString())) print((' ' + path.toStringOfTypes())) print((' ' + path.toStringOfIds())) # Make all edges and nodes transparent transparentGrey = tlp.Color(50, 50, 50, 50) tp.setEdgeColor(transparentGrey, graph) tp.setNodeColor(transparentGrey, graph)
""" Example of finding paths and unique types using PathStats """ from tulip import * from tulipgui import * import tulippaths as tp # Path parameters graphFile = '../data/514_4hops.tlp' sourceNodeId = 593 targetNodeId = 514 maxNumHops = 5 graph = tlp.loadGraph(graphFile) # Find start and end nodes source = tp.getNodeById(sourceNodeId, graph) target = tp.getNodeById(targetNodeId, graph) finder = tp.PathFinder(graph) print 'hops, total, valid, unique, num w\ loop' for i in range(0, maxNumHops): finder.reset() finder.findPaths(source, target, i) stats = tp.PathStats(finder.valid) print str(i) + ', ' + str(len(finder.valid) + len(finder.failed)) + ', ' + str(len(finder.valid)) + ', ' + \ str(stats.getNumUniqueTypes()) + ', ' + str(stats.getNumPathsWithLoop()) # Render the graph in a node-link diagram. nodeLinkView = tlpgui.createNodeLinkDiagramView(graph)
""" Example of messing with node color This will turn all nodes black, then set the start node and end node to green and red repsectively. """ from tulip import * from tulipgui import * import tulippaths as tp graph = tlp.loadGraph("../data/test_one.tlp") viewColor = graph.getColorProperty("viewColor") source = tp.getNodeById(176, graph) target = tp.getNodeById(606, graph) # Make all nodes black for node in graph.getNodes(): viewColor[node] = tlp.Color.Black # Make start node green and end node red. viewColor[source] = tlp.Color(0, 255, 0) viewColor[target] = tlp.Color(255, 0, 0) # Render the graph in a node-link diagram. nodeLinkView = tlpgui.createNodeLinkDiagramView(graph) renderingParameters = nodeLinkView.getRenderingParameters()
""" Example of finding paths and unique types using PathStats """ from tulip import * from tulipgui import * import tulippaths as tp # Path parameters graphFile = '../data/514_4hops.tlp' sourceNodeId = 593 targetNodeId = 514 maxNumHops = 5 graph = tlp.loadGraph(graphFile) # Find start and end nodes source = tp.getNodeById(sourceNodeId, graph) target = tp.getNodeById(targetNodeId, graph) finder = tp.PathFinder(graph) print('hops, total, valid, unique, num w\ loop') for i in range(0, maxNumHops): finder.reset() finder.findPaths(source, target, i) stats = tp.PathStats(finder.valid) print((str(i) + ', ' + str(len(finder.valid) + len(finder.failed)) + ', ' + str(len(finder.valid)) + ', ' + \ str(stats.getNumUniqueTypes()) + ', ' + str(stats.getNumPathsWithLoop()))) # Render the graph in a node-link diagram. nodeLinkView = tlpgui.createNodeLinkDiagramView(graph)