def Load(structureID):

    structure = queries.GetStructure(structureID)
    locations = queries.GetLinkedCollection(structure.LocationsURI)

    connGraph = StructureLocations(structure, locations)

    return connGraph
Beispiel #2
0
    def __getitem__(self, key):

        structure = self.get(key, None)
        if structure is None:
            structure = queries.GetStructure(key)
            self[structure.ID] = structure

        return structure
Beispiel #3
0
    def AddHopNodes(self, link):
        '''Add nodes only based on the links we discovered'''

        sourceStructParentID = queries.GetStructure(link.SourceID).ParentID
        targetStructParentID = queries.GetStructure(link.TargetID).ParentID

        if sourceStructParentID is None or targetStructParentID is None:
            print "Invalid edge: " + str(link.SourceID) + " -> " + str(
                link.TargetID)
            return

        sourceParent = queries.GetStructure(sourceStructParentID)
        targetParent = queries.GetStructure(targetStructParentID)

        if not self.NodeInGraph(sourceParent):
            self.AddStructure(sourceParent)

        if not self.NodeInGraph(str(targetStructParentID)):
            self.AddStructure(targetParent)
Beispiel #4
0
def Load(structureID, hops=3, endpoint=None):

    structureConnectivity = StructureConnectivity()
    structure = queries.GetStructure(structureID, endpoint=endpoint)

    structureConnectivity.AddStructure(structure)

    for i in range(0, hops):
        print "Fetching connectivity hop #" + str(i)
        structureConnectivity.GetNextHop()

    structureConnectivity.AddNodeEdges()

    return structureConnectivity
Beispiel #5
0
def Load(structureIDs, hops=3, endpoint=None):
    '''StructureIDs may be a single value or a list'''

    # Converting to a set removes duplicate IDs from the request
    if not isinstance(structureIDs, set):
        structureIDs = set(structureIDs)

    mcgraph = MorphologyConnectivity()

    for sID in structureIDs:
        structure = queries.GetStructure(sID, endpoint=endpoint)

        if structure is None:
            continue

        mcgraph.AddStructure(structure)

    for i in range(0, hops):
        print "Fetching connectivity hop #" + str(i)
        mcgraph.GetNextHop()

    mcgraph.AddNodeEdges()

    return mcgraph
Beispiel #6
0
    def AddChildStructureSourceEdges(self, struct):
        '''Add edges between existing nodes in the graph where the parent structure is the source'''

        numNodesAtStart = len(self.nodes())

        for link in struct.ChildStructureLinks:
            source = queries.GetStructure(link.SourceID)
            sourceStructParentID = source.ParentID
            if sourceStructParentID != struct.ID:
                # To prevent duplication we only add links where our parent structure is the source
                continue

            target = queries.GetStructure(link.TargetID)
            targetStructParentID = target.ParentID

            edgekey = self._CreateEdgeKey(source.ID, target.ID)

            if sourceStructParentID is None or targetStructParentID is None:
                print "Invalid edge: " + str(link.SourceID) + " -> " + str(
                    link.TargetID)
                return

            sourceParent = queries.GetStructure(sourceStructParentID)

            # We do not want to add nodes to the graph at this point.  If a node occurs here it is outside the graph's requested hops.
            # In the original circuit viz these nodes were included as clear "Ghost nodes" to indicate further connections existed
            if not targetStructParentID in self.structures:
                continue

            targetParent = queries.GetStructure(targetStructParentID)

            # print "Add edge: " + str(sourceParent.ID) + " -> " + str(targetParent.ID)

            # Create parent-child structure edge
            #            if not self.has_edge(sourceParent, source):
            #                self.add_edge(sourceParent, source, IsParentChildEdge=True, link=None)
            #
            #            if not self.has_edge(targetParent, target):
            #                self.add_edge(targetParent, target, IsParentChildEdge=True, link=None)

            sourceStruct = queries.GetStructure(link.SourceID)
            sourceType = queries.GetStructureType(sourceStruct.TypeID)

            template = "Add Edge: %d -> %d key=%s" % (sourceParent.ID,
                                                      targetParent.ID, edgekey)
            print template

            try:
                sourceLocations = structurelocations.Load(link.SourceID)
            except:
                sourceLocations = None

            try:
                targetLocations = structurelocations.Load(link.TargetID)
            except:
                targetLocations = None

            # Create edge between child self.structures
            self.add_edge(sourceParent,
                          targetParent,
                          key=edgekey,
                          IsParentChildEdge=False,
                          link=link,
                          edgekey=edgekey,
                          source=sourceLocations,
                          target=targetLocations,
                          type=sourceType)

            # We should not be adding nodes by creating edges.  This means a node was not added which should have been
            assert (numNodesAtStart == len(self.nodes()))