图形示例 - 蛋白质相互作用数据集(最小化)#

导入 cuxfilter#

[1]:
import cuxfilter
import cudf
import cugraph

ITERATIONS=500
THETA=1.0
OPTIMIZE=True

加载所需数据集#

[ ]:
edges = cudf.read_csv('./data/edges.csv',)[['Source','Destination', 'edgeColor']]
nodes = cudf.read_csv('./data/nodes.csv',)[['x', 'y', 'SYMBOL', 'Color']]
nodes.Color = nodes.Color - nodes.Color.min()
[ ]:
nodes.head()
[ ]:
edges.head()

预处理数据#

[ ]:
edges.columns=["source", "destination", 'color']

G = cugraph.Graph()
G.from_cudf_edgelist(edges)

nodes_ = cugraph.layout.force_atlas2(G, max_iter=500,
                strong_gravity_mode=False,
                outbound_attraction_distribution=True,
                lin_log_mode=False,
                barnes_hut_optimize=OPTIMIZE, barnes_hut_theta=THETA, verbose=True)
[ ]:
nodes_1 = nodes_.merge(nodes, left_on='vertex', right_on='SYMBOL', suffixes=('', '_y'))[list(nodes.columns)]
[ ]:
nodes_1.head()

定义图表#

[ ]:
cux_df = cuxfilter.DataFrame.load_graph((nodes_1, edges))
[ ]:
chart0 = cuxfilter.charts.graph(edge_target='destination',edge_color_palette=['gray', 'black'],
                                            node_id='SYMBOL', timeout=200, edge_aggregate_col='color',
                                            node_aggregate_col='Color', node_aggregate_fn='mean', node_pixel_shade_type='linear',
                                            edge_render_type='direct',#other option available -> 'curved'
                                            edge_transparency=0.5, unselected_alpha=0.2
                                          )

chart1 = cuxfilter.charts.bar('Color', title="Mean Color")

创建一个控制面板对象#

[ ]:
d = cux_df.dashboard([chart0, chart1], layout=cuxfilter.layouts.double_feature)

启动控制面板#

  1. d.show(‘current_notebook_url:current_notebook_port’) 远程控制面板

  2. d.app() 在笔记本单元格内嵌显示

如果您需要停止服务器

  • d.stop()

[ ]:
d.show()

graphs

图形图表引入了两个新的自定义工具:#

  1. 显示边:有时渲染的边会完全遮挡图中的节点,并减慢控制面板的速度。“显示边”工具允许用户切换图中边的可见性。

  2. 检查相邻边:“检查相邻边”工具允许用户在图中选择一个节点并突出显示连接到该节点的边。这对于探索特定节点周围的图结构非常有用。

    注意:目前边的渲染支持有限,对于边数超过一百万的大图可能存在性能问题,而节点渲染可以达到数千万个节点。对于大图,我们建议使用“显示边”开关禁用边的渲染。

graphs-in-action

将查询到的数据导出到数据框#

[ ]:
queried_df = d.export()