将 SQL 邻接表转换为 R 邻接矩阵
我有一个 MySQL 表 pedigree
,它将所有互连的出身数据存储为 2 个邻接列表:
Pedigree 表
org_id INT UNSIGNED NOT NULL PRIMARY KEY,
dam_id INT UNSIGNED,
sire_id INT UNSIGNED,
FOREIGN KEY (org_id) REFERENCES organisms(org_id)
FOREIGN KEY (dam_id) REFERENCES organisms(org_id),
FOREIGN KEY (sire_id) REFERENCES organisms(org_id)
- 任何
org_id
可能有也可能没有孩子。儿童数量不限。 pedigree
表中的每个org_id
都必须至少有一个 dam_id 或一个 sire_id- 如果
org_id
没有父母,则不会列出在谱系表中,除了作为父亲或母亲之外 org_id
可能有dam_id==sire_id
示例数据
Org Dam Sire
23, 42, 57
26, 25, 25
27, 43, 43
28, 44, 44
30, 25, 25
31, 45, 25
32, 45, 45
33, 31, 32
34, 28, 59
35, 27, 28
36, 28, 28
39, 38, 34
41, 27, 24
我想使用 R 的igraph 包(除非有更合适的东西)用于显示我的谱系的有向 DAG,其中祖先节点出现在子节点之上。我不清楚 igraph 究竟需要什么来做到这一点。我认为我需要从邻接列表中生成邻接矩阵,但我不知道如何有效地做到这一点。
有想法吗?
I have a MySQL table pedigree
that stores all my interconnecting parentage data as 2 adjacency lists:
Pedigree table
org_id INT UNSIGNED NOT NULL PRIMARY KEY,
dam_id INT UNSIGNED,
sire_id INT UNSIGNED,
FOREIGN KEY (org_id) REFERENCES organisms(org_id)
FOREIGN KEY (dam_id) REFERENCES organisms(org_id),
FOREIGN KEY (sire_id) REFERENCES organisms(org_id)
- Any
org_id
may or may not have children. Number of children is unlimited. - Each
org_id
in thepedigree
table is required to have at least a dam_id OR a sire_id - If an
org_id
has no parents, it will not be listed in the pedigree table except as a sire or dam - An
org_id
may havedam_id==sire_id
Sample Data
Org Dam Sire
23, 42, 57
26, 25, 25
27, 43, 43
28, 44, 44
30, 25, 25
31, 45, 25
32, 45, 45
33, 31, 32
34, 28, 59
35, 27, 28
36, 28, 28
39, 38, 34
41, 27, 24
I want to use R's igraph
package (unless there is something more appropriate) to display a directed DAG of my pedigrees with ancestor nodes occurring above child nodes. I am unclear about exactly what igraph needs to do this. I think I need to generate an adjacency matrix from my adjacency list, but I'm at a loss as to how to do this efficiently.
Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑使用边缘列表。两列矩阵,每条边作为矩阵中的一行。 igraph 也会从边列表中的值中提取节点的名称。
如果您出于某种原因需要邻接矩阵
Consider using an edge list. Two column matrix with each edge as a row in the matrix. igraph will pull the names for the nodes from the values in the edge list as well.
And if you need the adjacency matrix for some reason