getting a directed and unweighted adjacency matrix with igraph package
1
0
Entering edit mode
Angel ▴ 40
@angel-7981
Last seen 7.7 years ago
Berlin

hi,

i have a gold standard in Arabidopsis thaliana( genes and transcription factors and their interaction) like below

TFLocus    TargetLocus    InteractionType
AT5G10140    AT1G65480    -1
AT5G11260    AT1G27480    -1
AT5G11260    AT5G53370    -1
AT5G11260    AT1G03630    -1
AT5G11260    AT1G13600    -1
AT5G11260    AT2G41670    -1
AT5G11260    AT2G05160    -1
AT5G11260    AT2G40170    -1
AT5G11260    AT1G62780    -1

using this code i have an adjacency matrix

library(igraph)

## Read edge list with weights
edge_list <- read.table("Ara_GoldST.txt", header = T, sep = "\t", header=FALSE)
## Form undirected graph from edge list
G <- graph.data.frame(edge_list,directed=TRUE)
## Get adjacency matrix
## Set edge weights to values in the InteractionType column by setting
A<-as_adjacency_matrix(G,type="both",names=TRUE,sparse=FALSE)

but max(A) is 5 while I need a directed  adjacency only contains 0 and 1. how I can get that please?

even i tried 

as.directed(G, "mutual")  to make my graph directed but my adjacency matrix is undirected and contains 0, 1, 2, 3, 4 and 5 while i only need 0 and 1

thank you for any suggestion

igraph • 3.0k views
ADD COMMENT
2
Entering edit mode
@herve-pages-1542
Last seen 3 hours ago
Seattle, WA, United States

Hi,

Note that igraph is a CRAN package, not a Bioconductor package. Your graph probably has more than 1 edge between the 2 same nodes. That happens when you have more than 1 interaction type between a given TFLocus and a given TargetLocus. It has nothing to do with the fact that the graph is directed or not. In that case, it seems that as_adjacency_matrix() returns a matrix with not just 0's and 1's but where each cell A[i, j] is the number of edges between nodes i and j. Strictly speaking maybe that doesn't qualify as an "adjacency matrix" . However it's easy enough to turn it into a strict adjacency matrix by replacing values that are > 1 with 1's:

A[A > 1] <- 1

Doing this means that you're not discriminating between different possible types of interaction.

Finally note that it's also easy to compute the adjacency matrix yourself directly from edge_list. You don't really need the igraph package for that:

TFLocus <- as.character(edge_list$TFLocus)
TargetLocus <- as.character(edge_list$TargetLocus)
all_nodes <- unique(c(TFLocus, TargetLocus))
A <- matrix(0L, nrow=length(all_nodes), ncol=length(all_nodes), dimnames=list(all_nodes, all_nodes))
A[cbind(TFLocus, TargetLocus)] <- 1L

Hope this helps,

H.

ADD COMMENT
0
Entering edit mode

thanks a lot for your help 

I did as you mentioned

I used the derived adjacency matrix A as a true net in validate function in minet package to compute confusion matrix with my inferred network (for example derived by aracne),

here is my result

> table <-  validate(inf.net,A)
Warning messages:
1: In validateinf.net,A) :
  networks have not the same node names
2: In validateinf.net, A) :
  true network arcs will be considerd as undirected edges
 

>

ADD REPLY
0
Entering edit mode

Hi,

So you managed to turn the pseudo adjacency matrix returned by as_adjacency_matrix() into a strict adjacency matrix but now you have a problem when trying to use this matrix with the minet package. So we are done with this thread and you should start a new thread by asking a new question that you need to tag with minet. Otherwise the minet maintainers won't get notified and won't help (what are the chances that they are watching this particular thread which is tagged with igraph?).

Thanks,

H.

ADD REPLY
0
Entering edit mode

thank you dear Herve

ADD REPLY

Login before adding your answer.

Traffic: 619 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6