Exemplo n.º 1
0
    def test_isInRegexTypeConstraints(self):
        graphFile = '../data/test_one.tlp'
        graph = tlp.loadGraph(graphFile)

        source = tp.utils.getNodeById(176, graph)
        target = tp.utils.getNodeById(5530, graph)

        pathFinder = tp.PathFinder(graph)

        pathFinder.findPaths(source, target, 2)

        for path in pathFinder.valid:
            if path.size() < 3:
                continue
            else:
                # Make sure the path satisfies valid regex constraints
                constrainedEdgeRegexes = [ "R.* Synapse", "Adh[a-z]rens" ]
                constrainedNodeRegexes = [ "CBb3-[1-9]i", "^GZ?C ON$", "C[A-Z]b4w" ]
                self.assertTrue(path.isInRegexTypeConstraints(
                    constrainedNodeRegexes, constrainedEdgeRegexes))
                # Make sure the path does not satisfy invalid regex constraints
                constrainedEdgeRegexes = [ "Cthulhu F'taghn", "R'lyeh Synapse" ]
                constrainedNodeRegexes = [ "^Nyarlathotep$", "^$", "[0-1].*" ]
                self.assertFalse(path.isInRegexTypeConstraints(
                    constrainedNodeRegexes, constrainedEdgeRegexes))
Exemplo n.º 2
0
    def findRegexConstrainedPaths(self, nodeConstraints, edgeConstraints):

        pathFinder = tp.PathFinder(self.graph)

        pathFinder.findRegexConstrainedPaths(edgeConstraints, nodeConstraints)

        return pathFinder.valid
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    def test_findRegexConstrainedPaths(self):
        graphFile = '../data/test_two.tlp'
        graph = tlp.loadGraph(graphFile)

        edgeConstraintRegexes = [".+ Synapse", "^Adhe.+$"]
        nodeConstraintRegexes = ["CBb3-.+$", "^GC ON", "[A-Z]Bb4w"]

        pathFinder = tp.PathFinder(graph)
        pathFinder.findRegexConstrainedPaths(edgeConstraintRegexes,
                                             nodeConstraintRegexes)

        self.assertTrue(len(pathFinder.valid) == 2)

        for path in pathFinder.valid:
            self.assertTrue(
                path.isInRegexTypeConstraints(nodeConstraintRegexes,
                                              edgeConstraintRegexes))
Exemplo n.º 6
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())
Exemplo n.º 7
0
    def test_isInTypeConstraints(self):
        graphFile = '../data/test_one.tlp'
        graph = tlp.loadGraph(graphFile)

        source = tp.utils.getNodeById(176, graph)
        target = tp.utils.getNodeById(5530, graph)

        pathFinder = tp.PathFinder(graph)

        pathFinder.findPaths(source, target, 2)

        for path in pathFinder.valid:
            if path.size() < 3:
                continue
            else:
                constrainedEdges = ["Ribbon Synapse", "Adherens"]
                constrainedNodes = ["CBb3-4i", "GC ON", "CBb4w"]
                self.assertTrue(path.isInTypeConstraints(constrainedEdges, constrainedNodes))
Exemplo n.º 8
0
    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))
Exemplo n.º 9
0
    def test_isSynapticPath(self):

        graphFile = '../data/test_one.tlp'
        graph = tlp.loadGraph(graphFile)

        source = tp.utils.getNodeById(176, graph)
        target = tp.utils.getNodeById(5530, graph)

        pathFinder = tp.PathFinder(graph)

        pathFinder.findPaths(source, target, 2)

        for path in pathFinder.valid:
            if path.toStringOfTypes() == 'CBb3-4i, Unknown, CBb4w':
                self.assertTrue(path.isSynapticPath())
            elif path.toStringOfTypes() == 'CBb3-4i, Ribbon Synapse, GC ON, Adherens, CBb4w':
                self.assertFalse(path.isSynapticPath())
            else:
                self.assertTrue(False) # Should never get here.
Exemplo n.º 10
0
    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')
Exemplo n.º 11
0
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)

# Render the graph in a node-link diagram.
nodeLinkView = tlpgui.createNodeLinkDiagramView(graph)