converting a list of genes and interaction to a graph
2
0
Entering edit mode
8.7 years ago
zizigolu ★ 4.3k

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

gene R • 4.8k views
ADD COMMENT
4
Entering edit mode
8.7 years ago

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 COMMENT
0
Entering edit mode

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 REPLY
0
Entering edit mode

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 REPLY
1
Entering edit mode

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 REPLY
0
Entering edit mode

thank you so much

ADD REPLY
0
Entering edit mode

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 REPLY
1
Entering edit mode

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 REPLY
0
Entering edit mode

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 REPLY
1
Entering edit mode

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 REPLY
0
Entering edit mode

thanks a lot

ADD REPLY
2
Entering edit mode
8.7 years ago

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)
    
ADD COMMENT
0
Entering edit mode

thank you both Amir and Jean

ADD REPLY

Login before adding your answer.

Traffic: 1541 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