def generate_graph_topology(labels, neighborhood):
    """
    Function generating a topological/spatial graph based on neighbors detection.

    Args:
       labels: (list) - list of labels to be found in the image and added to the topological graph.
       neighborhood: (dict) - dictionary giving neighbors of each object.

    Returns:
       graph: (PropertyGraph) - the topological/spatial graph.
       label2vertex: (dict) - dictionary translating labels into vertex ids (vids).
       edges: (dict) - dictionary associating an edge id to a couple of topologically/spatially related vertex.
    """
    graph = PropertyGraph()
    vertex2label = {}
    for l in labels:
        vertex2label[graph.add_vertex(l)] = l
    label2vertex = dict([(j, i) for i, j in vertex2label.iteritems()])

    labelset = set(labels)
    edges = {}

    for source, targets in neighborhood.iteritems():
        if source in labelset:
            for target in targets:
                if source < target and target in labelset:
                    edges[(source,
                           target)] = graph.add_edge(label2vertex[source],
                                                     label2vertex[target])

    graph.add_vertex_property('label')
    graph.vertex_property('label').update(vertex2label)

    return graph, label2vertex, edges
def create_random_TPG():
    import random
    g = TemporalPropertyGraph()
    # -- First, we create 'PropertyGraph':
    p1, p2 = PropertyGraph(), PropertyGraph()
    vids = range(1,10)
    edges = []
    for i in vids:
        l = range((i+1),10)
        random.shuffle(l)
        for j in l[:3]:
            edges.append((i,j))
    mapping = dict((vid,[vid]) for vid in vids)
    for v in vids:
        p1.add_vertex(v)
        p2.add_vertex(v)
    for s,t in edges:
        p1.add_edge(s,t)
        p2.add_edge(s,t)
    # -- Then we can create the 'TemporalPropertyGraph':
    g.extend([p1,p2],[mapping])
    return g
示例#3
0
def create_random_TPG():
    import random
    g = TemporalPropertyGraph()
    # -- First, we create 'PropertyGraph':
    p1, p2 = PropertyGraph(), PropertyGraph()
    vids = range(1, 10)
    edges = []
    for i in vids:
        l = range((i + 1), 10)
        random.shuffle(l)
        for j in l[:3]:
            edges.append((i, j))
    mapping = dict((vid, [vid]) for vid in vids)
    for v in vids:
        p1.add_vertex(v)
        p2.add_vertex(v)
    for s, t in edges:
        p1.add_edge(s, t)
        p2.add_edge(s, t)
    # -- Then we can create the 'TemporalPropertyGraph':
    g.extend([p1, p2], [mapping])
    return g
def create_TemporalGraph_partial_lineage():
    """
    Create a TemporalPropertyGraph with partial lineage.
    Simulate partial lost of lineage du to daughter cells being out of the acquisition frame.

    Here the is no daughters for TPG_vertex_id #6 (cell_id #4 in g2).
    """
    g = TemporalPropertyGraph()
    g1 = PropertyGraph()
    g2 = PropertyGraph()
    g3 = PropertyGraph()
    # -- Adding vertices to 'PropertyGraph'
    dict_0, dict_1, dict_2 ={}, {}, {}
    for i in range(2):
        g1.add_vertex()
    for i in range(5):
        g2.add_vertex()
    for i in range(13):
        g3.add_vertex()
    # -- Adding STRUCTURAL edges to 'PropertyGraph'
    g1.add_edge(0,1)
    for i in range(4):
        g2.add_edge(i, i+1)
    g2.add_edge(1,3)
    for i in range(12):
        g3.add_edge(i, i+1)
    g3.add_edge(0,3)
    g3.add_edge(2,6)
    g3.add_edge(3,6)
    g3.add_edge(4,6)
    g3.add_edge(8,10)
    g3.add_edge(10,12)
    # -- Creating lineage: TEMPORAL edges
    L12={
        0 : [0, 1, 2],
        1 : [3, 4]
        }
    L23={
        0 : [0, 1],
        1 : [2],
        2 : [3, 4, 5, 6],
        3 : [7, 8],
        }
    # -- Extending TemporalPropertyGraph with structural graph ('PropertyGraph') and linking them with lineage information.
    g.extend([g1, g2, g3], [L12, L23])
    return g
def create_TemporalGraph():
    """create a graph"""
    g = TemporalPropertyGraph()
    g1 = PropertyGraph()
    g2 = PropertyGraph()
    g3 = PropertyGraph()
    # -- Adding vertices to 'PropertyGraph'
    dict_0, dict_1, dict_2 ={}, {}, {}
    for i in range(2):
        g1.add_vertex()
    for i in range(5):
        g2.add_vertex()
    for i in range(13):
        g3.add_vertex()
    # -- Adding STRUCTURAL edges to 'PropertyGraph'
    g1.add_edge(0,1)
    for i in range(4):
        g2.add_edge(i, i+1)
    g2.add_edge(1,3)
    for i in range(12):
        g3.add_edge(i, i+1)
    g3.add_edge(0,3)
    g3.add_edge(2,6)
    g3.add_edge(3,6)
    g3.add_edge(4,6)
    g3.add_edge(8,10)
    g3.add_edge(10,12)
    # -- Creating lineage: TEMPORAL edges
    L12={
        0 : [0, 1, 2],
        1 : [3, 4]
        }
    L23={
        0 : [0, 1],
        1 : [2],
        2 : [3, 4, 5, 6],
        3 : [7, 8],
        4 : [9, 10, 11, 12]
        }
    # -- Extending TemporalPropertyGraph with structural graph ('PropertyGraph') and linking them with lineage information.
    g.extend([g1, g2, g3], [L12, L23])
    return g
def create_TemporalGraph_GraphProperty( set_as_ids = True ):
    """create a TemporalGraph with extra 'graph_property' to test relabbeling of keys and labels as ids"""
    g = TemporalPropertyGraph()
    g1 = PropertyGraph()
    g2 = PropertyGraph()
    g3 = PropertyGraph()
    # -- Adding vertices to 'PropertyGraph'
    dict_1, dict_2, dict_3 ={}, {}, {}
    for i in range(2):
        g1.add_vertex()
        dict_1[i]="t1_vid_"+str(i)
    g1.add_graph_property('time-point_vid',dict_1)
    for i in range(5):
        g2.add_vertex()
        dict_2[i]="t2_vid_"+str(i)
    g2.add_graph_property('time-point_vid',dict_2)
    for i in range(13):
        g3.add_vertex()
        dict_3[i]="t3_vid_"+str(i)
    g3.add_graph_property('time-point_vid',dict_3)
    # -- Setting keys to vid type: will be relabelled when creating the TPG 
    if set_as_ids:
        g1.set_graph_property_key_to_vid_type('time-point_vid')
        g2.set_graph_property_key_to_vid_type('time-point_vid')
        g3.set_graph_property_key_to_vid_type('time-point_vid')
    # -- Adding STRUCTURAL edges to 'PropertyGraph'
    g1.add_edge(0,1)
    for i in range(4):
        g2.add_edge(i, i+1)
    g2.add_edge(1,3)
    for i in range(12):
        g3.add_edge(i, i+1)
    g3.add_edge(0,3)
    g3.add_edge(2,6)
    g3.add_edge(3,6)
    g3.add_edge(4,6)
    g3.add_edge(8,10)
    g3.add_edge(10,12)
    # -- Creating lineage: TEMPORAL edges
    L12={
        0 : [0, 1, 2],
        1 : [3, 4]
        }
    L23={
        0 : [0, 1],
        1 : [2],
        2 : [3, 4, 5, 6],
        3 : [7, 8],
        4 : [9, 10, 11, 12]
        }
    # -- Extending TemporalPropertyGraph with structural graph ('PropertyGraph') and linking them with lineage information.
    g.extend([g1, g2, g3], [L12, L23])
    return g
def toPropertyGraph(self, cell_cell=None, labels=None):
    """
    creates a PropertyGraph
    """
    p=PropertyGraph()
    p.add_edge_property("source-target")
    # -- If the cell neighbours dictionnary is not provided, we create it.
    if not cell_cell:
        cell_cell=cellNeighbours(self, labels=labels)
    
    if labels!=None:
        l=labels
    else:
        l=cell_cell.keys()
    for c in l:
        if not p.has_vertex(c):
            p.add_vertex(c)
        for cv in cell_cell[c]:
            if (not p.has_vertex(cv)) and (cv in l):
                p.add_vertex(cv)
                eid=p.add_edge(c,cv)
                p.edge_property("source-target")[eid]=(c,cv)
    return p
示例#8
0
def create_TemporalGraph_partial_lineage():
    """
    Create a TemporalPropertyGraph with partial lineage.
    Simulate partial lost of lineage du to daughter cells being out of the acquisition frame.

    Here the is no daughters for TPG_vertex_id #6 (cell_id #4 in g2).
    """
    g = TemporalPropertyGraph()
    g1 = PropertyGraph()
    g2 = PropertyGraph()
    g3 = PropertyGraph()
    # -- Adding vertices to 'PropertyGraph'
    dict_0, dict_1, dict_2 = {}, {}, {}
    for i in range(2):
        g1.add_vertex()
    for i in range(5):
        g2.add_vertex()
    for i in range(13):
        g3.add_vertex()
    # -- Adding STRUCTURAL edges to 'PropertyGraph'
    g1.add_edge(0, 1)
    for i in range(4):
        g2.add_edge(i, i + 1)
    g2.add_edge(1, 3)
    for i in range(12):
        g3.add_edge(i, i + 1)
    g3.add_edge(0, 3)
    g3.add_edge(2, 6)
    g3.add_edge(3, 6)
    g3.add_edge(4, 6)
    g3.add_edge(8, 10)
    g3.add_edge(10, 12)
    # -- Creating lineage: TEMPORAL edges
    L12 = {0: [0, 1, 2], 1: [3, 4]}
    L23 = {
        0: [0, 1],
        1: [2],
        2: [3, 4, 5, 6],
        3: [7, 8],
    }
    # -- Extending TemporalPropertyGraph with structural graph ('PropertyGraph') and linking them with lineage information.
    g.extend([g1, g2, g3], [L12, L23])
    return g
示例#9
0
def create_TemporalGraph():
    """create a graph"""
    g = TemporalPropertyGraph()
    g1 = PropertyGraph()
    g2 = PropertyGraph()
    g3 = PropertyGraph()
    # -- Adding vertices to 'PropertyGraph'
    dict_0, dict_1, dict_2 = {}, {}, {}
    for i in range(2):
        g1.add_vertex()
    for i in range(5):
        g2.add_vertex()
    for i in range(13):
        g3.add_vertex()
    # -- Adding STRUCTURAL edges to 'PropertyGraph'
    g1.add_edge(0, 1)
    for i in range(4):
        g2.add_edge(i, i + 1)
    g2.add_edge(1, 3)
    for i in range(12):
        g3.add_edge(i, i + 1)
    g3.add_edge(0, 3)
    g3.add_edge(2, 6)
    g3.add_edge(3, 6)
    g3.add_edge(4, 6)
    g3.add_edge(8, 10)
    g3.add_edge(10, 12)
    # -- Creating lineage: TEMPORAL edges
    L12 = {0: [0, 1, 2], 1: [3, 4]}
    L23 = {0: [0, 1], 1: [2], 2: [3, 4, 5, 6], 3: [7, 8], 4: [9, 10, 11, 12]}
    # -- Extending TemporalPropertyGraph with structural graph ('PropertyGraph') and linking them with lineage information.
    g.extend([g1, g2, g3], [L12, L23])
    return g
示例#10
0
def create_TemporalGraph_GraphProperty(set_as_ids=True):
    """create a TemporalGraph with extra 'graph_property' to test relabbeling of keys and labels as ids"""
    g = TemporalPropertyGraph()
    g1 = PropertyGraph()
    g2 = PropertyGraph()
    g3 = PropertyGraph()
    # -- Adding vertices to 'PropertyGraph'
    dict_1, dict_2, dict_3 = {}, {}, {}
    for i in range(2):
        g1.add_vertex()
        dict_1[i] = "t1_vid_" + str(i)
    g1.add_graph_property('time-point_vid', dict_1)
    for i in range(5):
        g2.add_vertex()
        dict_2[i] = "t2_vid_" + str(i)
    g2.add_graph_property('time-point_vid', dict_2)
    for i in range(13):
        g3.add_vertex()
        dict_3[i] = "t3_vid_" + str(i)
    g3.add_graph_property('time-point_vid', dict_3)
    # -- Setting keys to vid type: will be relabelled when creating the TPG
    if set_as_ids:
        g1.set_graph_property_key_to_vid_type('time-point_vid')
        g2.set_graph_property_key_to_vid_type('time-point_vid')
        g3.set_graph_property_key_to_vid_type('time-point_vid')
    # -- Adding STRUCTURAL edges to 'PropertyGraph'
    g1.add_edge(0, 1)
    for i in range(4):
        g2.add_edge(i, i + 1)
    g2.add_edge(1, 3)
    for i in range(12):
        g3.add_edge(i, i + 1)
    g3.add_edge(0, 3)
    g3.add_edge(2, 6)
    g3.add_edge(3, 6)
    g3.add_edge(4, 6)
    g3.add_edge(8, 10)
    g3.add_edge(10, 12)
    # -- Creating lineage: TEMPORAL edges
    L12 = {0: [0, 1, 2], 1: [3, 4]}
    L23 = {0: [0, 1], 1: [2], 2: [3, 4, 5, 6], 3: [7, 8], 4: [9, 10, 11, 12]}
    # -- Extending TemporalPropertyGraph with structural graph ('PropertyGraph') and linking them with lineage information.
    g.extend([g1, g2, g3], [L12, L23])
    return g