Skip to content

Commit

Permalink
Merge 81ef3f7 into 402e9a5
Browse files Browse the repository at this point in the history
  • Loading branch information
elaubsch committed May 25, 2022
2 parents 402e9a5 + 81ef3f7 commit 2632d4b
Show file tree
Hide file tree
Showing 3 changed files with 344 additions and 364 deletions.
27 changes: 14 additions & 13 deletions deepcell_spots/cluster_vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,38 +74,39 @@ def ca_to_adjacency_matrix(ca_matrix):
return A


def label_graph_ann(G, coords, exclude_last=False):
def label_graph_ann(G, coords_df, exclude_last=False):
"""Labels the annotator associated with each node in the graph
Args:
G (networkx.Graph): Graph with edges indicating clusters of points
assumed to be derived from the same ground truth detection
coords (numpy.array): 2d-array of detected point locations for each
classical algorithm used
exclude_last (bool): Only set as True to exclude a point that has been
included for the purpose of normalization
assumed to be derived from the same ground truth detection
coords_df (DataFrame): Data frame with columns 'x' and 'y' which encode the
spot locations and 'Algorithm' which encodes the algorithm that
corresponds with that spot
exclude_last (bool): Only set as True to exclude a point that has been
included for the purpose of normalization
Returns:
networkx.Graph: Labeled graph
"""

G_new = G.copy()
num_spots = [len(x) for x in coords]
algs = coords_df.Algorithm.unique()
num_spots = [len(coords_df.loc[coords_df['Algorithm'] == alg]) for alg in algs]

# Create list of annotator labels
ann_labels = np.array([0] * num_spots[0])
for i in range(1, len(num_spots)):
temp_labels = np.array([i] * num_spots[i])
ann_labels = np.hstack((ann_labels, temp_labels))
labels = []
for i in range(len(num_spots)):
labels.extend([i] * num_spots[i])

nodes = list(G_new.nodes)

if exclude_last:
for i in range(len(nodes) - 1):
G_new.nodes[i]['name'] = ann_labels[i]
G_new.nodes[i]['name'] = labels[i]
else:
for i in range(len(nodes)):
G_new.nodes[i]['name'] = ann_labels[i]
G_new.nodes[i]['name'] = labels[i]

return G_new

Expand Down
Loading

0 comments on commit 2632d4b

Please sign in to comment.