This is a test version of Biostars. For the public version, visit https://www.biostars.org.
converting an edge list of genes to a full matrix(adjacency)

Hi

I have an edge list derived from a gene regulatory network inferring algorithm like below

edge_list <- read.table("dream_GENIE3_predictions.txt", header = T, sep = "\t")
edge_list <- edge_list[!duplicated(edge_list),]

AT2G03750    AT5G16030    0.036228
AT5G05410    AT2G26150    0.035889
AT4G29780    AT4G34410    0.035248
AT2G22500    AT4G29780    0.034398
AT3G43120    AT3G01270    0.033944
AT1G07000    AT1G10340    0.033512
AT4G14090    AT5G42800    0.032743
AT4G39480    AT1G24260    0.032410
AT4G29780    AT2G46400    0.032203
AT1G21460    AT5G15800    0.031520
AT5G02030    AT3G50640    0.031176
AT1G30350    AT1G28430    0.031169
AT1G74930    AT4G29780    0.030951

I found this syntax to convert my list to an adjacency matrix but I can't adapt the code to my data

library(dils)

edgelist <- cbind(expand.grid(letters[1:2], letters[1:2]), runif(4))
AdjacencyFromEdgelist(edgelist)

who will help me?

gene software-error r

1 answer

Use the igraph library:

library(igraph);
edge_list <- read.delim("data_file.txt", header = TRUE, sep = "\t");
G <- graph.data.frame(edge_list,directed=FALSE);
A <- as_adjacency_matrix(G,type="both",names=TRUE,sparse=FALSE,attr="weight");

Thank you, I did so but telling

Error in get.adjacency.dense(graph, type = type, attr = attr, edges = edges,  : 
  no such edge attribute

Make sure that you replace weight in attr="weight" with the name of the column that contains the weights.

Thank you, you all right it worked but my values converted to most 0 for example 0.036228 converted to 0

It looks like a type conversion problem. You can coerce the column types with colClasses e.g.

edge_list <- read.delim("data_file.txt", header = TRUE, sep = "\t",colClasses=c("character","character","numeric");

Thank you so much, your kindly helps always work well

Log in to answer this question.