将Adjacency Matrix转换为Cytoscape的Edgelist(csv文件) [英] Convert Adjacency Matrix into Edgelist (csv file) for Cytoscape
问题描述
我在csv文件中有一个大(200列/行)邻接矩阵。这详细描述了个人之间的互动。我想把这个文件转换成一个edgelist,它可以手动完成,但会花费大量的时间。
I have a large (200 columns/rows) adjacency matrix in a csv file. This details interactions between individuals. I would like to convert this file into an edgelist, it can be done manually, but would take an enormous amount of time.
一小部分数据如下所示(第一个单元格是一个空格):
A small subset of the data is shown below (the first cell is a space):
A B C
A 0 0 1
B 0 0 1
C 1 0 0
我想将其转换为:
A 1 C
B 1 C
C 1 A
这只是示例数据。基本上我想要的是绘制这些节点如何交互,并从中绘制这些交互的网络。我试过下面的代码在R包PCIT但它返回一个错误:
This is just example data. Essentially what I want is to plot the how these nodes interact, and from it plot a network of these interactions. I have tried the following code in the R package PCIT but it returns an error:
install.packages("PCIT")
library(PCIT)
input=read.csv('mouse.csv',header=TRUE,row.names=1,check.names=FALSE)
setwd('/Users/Plosslab/Documents/PythonStuff')
getEdgeList(input, rm.zero=TRUE)
我得到以下错误:
Error in structure(.Internal(as.vector(x, "double")), Csingle = TRUE) :
(list) object cannot be coerced to type 'double'
推荐答案
获取数据:
m <- as.matrix(read.table(text="
A B C D
A 0 0 0 1
B 0 0 1 0
C 1 0 0 1",
header=TRUE))
w <- which(m==1,arr.ind=TRUE)
data.frame(r=rownames(m)[w[,"row"]],
i=1,
c=colnames(m)[w[,"col"]])
## r i c
## 1 C 1 A
## 2 B 1 C
## 3 A 1 D
## 4 C 1 D
(您关心订单吗? ..?)
(Do you care about the order ... ?)
PCIT
无论如何都是对称的,所以这可能是一个问题。
PCIT
assumes symmetry anyway, so that might be a problem for you.
这篇关于将Adjacency Matrix转换为Cytoscape的Edgelist(csv文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!