WIP
This commit is contained in:
+31
-4
@@ -3,6 +3,7 @@ import math
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.collections import LineCollection
|
||||
import numpy as np
|
||||
import squidpy as sq
|
||||
from graph_tool.all import *
|
||||
|
||||
|
||||
@@ -19,6 +20,14 @@ def random_graph(n=5000, seed=None):
|
||||
return rng.random((n, 2)), seed
|
||||
|
||||
|
||||
def mibitof():
|
||||
"""
|
||||
Mibitof dataset from `squidpy`.
|
||||
"""
|
||||
adata = sq.datasets.mibitof()
|
||||
return adata
|
||||
|
||||
|
||||
def spatial_graph(adata):
|
||||
"""
|
||||
Generate the spatial graph using delaunay for the given `adata`.
|
||||
@@ -55,6 +64,11 @@ def draw_graph(G, ax, name):
|
||||
ax.add_collection(LineCollection([np.column_stack([ex, ey])], colors=['k'], linewidths=0.1))
|
||||
|
||||
ax.scatter(x, y, s=1) # map closeness values as color mapping on the verticies
|
||||
# for v in G.vertices():
|
||||
# neighbours = g.get_all_neighbours(v)
|
||||
# if len(neighbours) == 0:
|
||||
# ax.scatter(pos[v][0], pos[v][1], s=1, color=['r'])
|
||||
|
||||
ax.set_title(name)
|
||||
|
||||
|
||||
@@ -66,11 +80,24 @@ def draw_graph(G, ax, name):
|
||||
# - apply centrality measure to the next axis
|
||||
# - Draw the corresponding resulting models into a grid
|
||||
#
|
||||
points, seed = random_graph(n=3000)
|
||||
g, weight = spatial_graph(points)
|
||||
# points, seed = random_graph(n=3000)
|
||||
# g, weight = spatial_graph(points)
|
||||
adata = mibitof()
|
||||
g, weight = spatial_graph(adata.obsm['spatial'])
|
||||
g = GraphView(g)
|
||||
|
||||
for v in g.vertices():
|
||||
neighbours = g.get_all_neighbours(v)
|
||||
if len(neighbours) == 0:
|
||||
g.remove_vertex(v)
|
||||
break
|
||||
|
||||
pos = g.vp["pos"]
|
||||
weight = g.new_edge_property("double")
|
||||
for e in g.edges():
|
||||
weight[e] = math.sqrt(sum(map(abs, pos[e.source()].a - pos[e.target()].a)))**2
|
||||
|
||||
# plot graph with convex_hull
|
||||
fig_graph, ax_graph = plt.subplots(figsize=(15, 12))
|
||||
draw_graph(g, ax_graph, f"Pointcould (seed: {seed} | n: 500)")
|
||||
fig_graph.savefig("point_cloud_example.svg", format='svg')
|
||||
draw_graph(g, ax_graph, f"mibitof")
|
||||
fig_graph.savefig("mibitof_graph.svg", format='svg')
|
||||
|
||||
Reference in New Issue
Block a user