Question: converting a list of genes and interaction to a graph
0
gravatar for A
3.9 years ago by
A3.6k
A3.6k wrote:

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

i want to convert this data frame to graph by igraph package, i did like so
mycounts <- read.table("Ara_GoldST.txt", header = T, sep = "\t")
mycounts <- graph.data.frame(mycounts, directed=TRUE, vertices=NULL)
mycounts <- get.data.frame(mycounts, what=c("edges", "vertices", "both"))

then i want to convert the graph to adjacency matrix

but 

> get.adjacency(mycounts, type=c("both", "upper", "lower"),
+               attr=NULL, names=TRUE, binary=FALSE, sparse=FALSE)
Error in get.adjacency(mycounts, type = c("both", "upper", "lower"), attr = NULL,  : 
  unused argument (binary = FALSE)

how i can convert my data frame to a graph that can be converted to an adjacency matrix please?

thank you

 

 

myposts R gene • 2.3k views
ADD COMMENTlink modified 3.9 years ago • written 3.9 years ago by A3.6k
4
gravatar for Jean-Karim Heriche
3.9 years ago by
EMBL Heidelberg, Germany
Jean-Karim Heriche21k wrote:

You're reusing the variable mycounts. First, it contains your data frame then it contains your graph then you convert your graph to a data frame again that you put into mycounts again. In essence you've done nothing and you end up with mycounts being a data frame again. Converting your data frame to a graph is done by graph.data.frame. Read the igraph doc. What you want is something like:

## 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
## attr="InteractionType", for an unweighted graph, use attr=NULL
A<-as_adjacency_matrix(G,type="both",names=TRUE,sparse=FALSE,attr="InteractionType")
ADD COMMENTlink modified 3.9 years ago • written 3.9 years ago by Jean-Karim Heriche21k

thank you so much,

now i have an adjacency matrix By your and Amir's code and another adjacency matrix inferred from minet package. by your previous code i made both of matrices the same dimension but rownames and colnames also shoud be the same and match,

please consider the head of my matrices

> head(A[,1:4])
          AT5G10140 AT5G11260 AT5G62020 AT5G20240
AT5G10140         0         0         0         0
AT5G11260         0         0         1         0
AT5G62020         0         0         0         0
AT5G20240         0         0         0         0
AT3G54340         0         0         0         0
AT3G62420         0         0         0         0
> dim(A)
[1] 3123 3123

My another matrix

> head(mycounts1[,1:4])
          AT1G01060 AT1G01170 AT1G01180 AT1G01260
AT1G01060 0.0000000 0.6174969  1.410928 0.0000000
AT1G01170 0.6174969 0.0000000  0.000000 0.2309380
AT1G01180 1.4109279 0.0000000  0.000000 0.0000000
AT1G01260 0.0000000 0.2309380  0.000000 0.0000000
AT1G01380 2.6555107 0.0000000  1.363213 0.5188701
AT1G01490 2.4668978 2.5065047  1.513176 1.5809029
> dim(mycounts)
[1] 3123 3123

as you consider the matrices are not match. how i can make them match please?

thank you

 

ADD REPLYlink modified 3.9 years ago • written 3.9 years ago by A3.6k

sorry my list contain both +1 and -1. if this causes your suggested code go wrong?? actually i need a symmetric adjacency matrix contains only 0 and 1 might it comes from a directed graph. getting together can i use still your code again?

thank you

ADD REPLYlink modified 3.9 years ago • written 3.9 years ago by A3.6k
1

As I wrote, if you don't want edge weights, then set attr=NULL. In general a directed graph has an asymmetric adjacency matrix. If you require the adjacency matrix to be symmetric, consider your graph as being undirected.

ADD REPLYlink written 3.9 years ago by Jean-Karim Heriche21k

thank you so much

ADD REPLYlink written 3.9 years ago by A3.6k

sorry I did based on your suggested codes

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

thank you

ADD REPLYlink written 3.9 years ago by A3.6k
1

Then you need to decide what you want to be 0 and what you want to be 1. 0 will mean no interaction and 1 will mean interaction between the nodes. So you need to decide if you want interactionType = -1 to mean interaction (replace 1 with 0 and replace -1 with 1) or no interaction (replace it with 0, keep the 1s). Because you're dealing with transcription factors and their targets, my guess is that interactionType indicates whether the TF represses (-1) or activates (1) expression of the target gene. If that's the case, you probably want to keep the -1/1 weights for your directed graph.

ADD REPLYlink written 3.9 years ago by Jean-Karim Heriche21k

thank you so much

you all right but I have to use this adjacency matrix as a true net by validate function in minet package to compute fscore of my inferred network. but my true net (the adjacency matrix I derived by your code) is undirected and weighted. then I stock in this step.  

ADD REPLYlink written 3.9 years ago by A3.6k
1

The code in my first reply has directed=TRUE and thus makes a directed network. You then wrote that you wanted a symmetric adjacency matrix which means an undirected graph so check what code you're using. You need to decide if you want weights and if so what you want them to be. If not, set attr=NULL as already mentioned.

ADD REPLYlink modified 3.9 years ago • written 3.9 years ago by Jean-Karim Heriche21k

thanks a lot 

ADD REPLYlink written 3.9 years ago by A3.6k
2
gravatar for Amir Hajian
3.9 years ago by
Amir Hajian40
Tehran
Amir Hajian40 wrote:

If your third column has only one value (-1), then do the following:

1.install "igraph package"

2.run the code, below

input <- read.delim("Ara_GoldST.txt", header=TRUE) #reading the file

input_matrix <- as.matrix(input) # converting the input file to a matrix

input_matrix = input_matrix[,1:2] #deleting the extra column (InteractionType)

adjacency = get.adjacency(graph.edgelist(input_matrix)) #using igraph's methods to extract an adjacency object

adjacency_matrix = as.matrix(adjacency) #create the adjacency matrix from adjacency value

View(adjacency_matrix)

Note: try to use UI functionalities in RStudio to import and view the data and install packages, rather that coding them.

Sincerely, Ms. Fereshteh!

ADD COMMENTlink modified 3.9 years ago • written 3.9 years ago by Amir Hajian40

thank you both Amir and Jean

ADD REPLYlink written 3.9 years ago by A3.6k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1447 users visited in the last hour