igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[igraph] how to create a graph from an adjacency - like matrix


From: Tony Larson
Subject: [igraph] how to create a graph from an adjacency - like matrix
Date: Mon, 04 Mar 2013 17:32:56 +0000
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130215 Thunderbird/17.0.3

Hello,
I have a large numeric matrix in R as follows:

> dim(libfactor.mat)
[1] 40523    10
> head(libfactor.mat)
      [,1]  [,2]  [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 20884 19184 19185   NA   NA   NA   NA   NA   NA    NA
[2,] 18330 13979 13978   NA   NA   NA   NA   NA   NA    NA
[3,]   176 17101 21455   NA   NA   NA   NA   NA   NA    NA
[4,] 15166 15165 15166   NA   NA   NA   NA   NA   NA    NA
[5,] 14190 14306  7450   NA   NA   NA   NA   NA   NA    NA
[6,]  9196  1513  4054   NA   NA   NA   NA   NA   NA    NA

Each row represents a putative compound and each column the possible library hit IDs for that compound. NAs represent no hits (there may be variable numbers of these per row). Multiple compounds will have the same hits.

What I want to do is build a graph from this and decompose it so all compounds sharing any hits form unique clusters. I can do this by using apply() and the combn() functions in R to row-by-row generate a 2-column "from-to" data frame, strip out the NAs, rbind() them all together, then use graph.data.frame(), ...... but the large number of rows makes this extremely slow.

Is there a better way to do this more directly in igraph using the existing matrix?

thanks
Tony

sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=C                 LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] Matrix_1.0-10   lattice_0.20-13 igraph_0.6.4    plyr_1.8
[5] xcms_1.34.0     mzR_1.4.6       Rcpp_0.10.2

loaded via a namespace (and not attached):
[1] Biobase_2.18.0     BiocGenerics_0.4.0 codetools_0.2-8 grid_2.15.2
[5] tools_2.15.2






reply via email to

[Prev in Thread] Current Thread [Next in Thread]