Discussion:
[igraph] Adjacency list to edgelist
anupam sinha
2010-03-09 12:39:47 UTC
Permalink
Dear all,

I have a number of graphs in this format (adjacency list)
:

PABPC4 PABPC4 EEF1A1 SETDB1 XRN1 RIF1
AHCY AHCY
PSCDBP PSCDBP PSCD1
ITSN2 ITSN2 WAS RAD9A LSM8 SYNJ2
TICAM2 TICAM2 IL1R1 IRAK1 TRAF6 IRF3 TLR4 IL1RAP
IRAK3 IRF7 TIRAP
ADCY3 CAMK2G ADCY3
ADCY6 ADCY6 CHRNA7 GNAS RAF1
FHL3 FHL3 ACTB CDC25B MAPK1 LASP1 KLF8 CTBP2
FHL2 ZNF42 SRF CDC42EP1 PHC2 PCQAP
TM9SF2 TM9SF2 RAB9A

where the alphanumeric id represents the node name (gene name). The first
column contains the source node and the other columns have the destination
nodes. How do I convert this into an edgelist format using R implementation
of igraph ? Thanks in advance for any suggestions.


Regards,


Anupam
Gábor Csárdi
2010-03-09 12:52:17 UTC
Permalink
Dear Anupam,

you don't really need igraph for this:

lines <- readLines("adjlist.txt")
lines <- gsub("[ ]+$", "", gsub("[ ]+", " ", lines)) # remove
trailing and multiple spaces
adjlist <- strsplit(lines, " ")

col1 <- unlist(lapply(adjlist, function(x) rep(x[1], length(x)-1)))
col2 <- unlist(lapply(adjlist, "[", -1))

edgelist <- cbind(col1, col2)

Best,
Gabor
Post by anupam sinha
Dear all,
                   I have a number of graphs in this format (adjacency list)
PABPC4    PABPC4    EEF1A1    SETDB1    XRN1    RIF1
AHCY         AHCY
PSCDBP   PSCDBP    PSCD1
ITSN2        ITSN2    WAS    RAD9A    LSM8    SYNJ2
TICAM2     TICAM2    IL1R1    IRAK1    TRAF6    IRF3    TLR4    IL1RAP
IRAK3    IRF7    TIRAP
ADCY3      CAMK2G    ADCY3
ADCY6      ADCY6    CHRNA7    GNAS    RAF1
FHL3          FHL3    ACTB    CDC25B    MAPK1    LASP1    KLF8    CTBP2
FHL2    ZNF42    SRF    CDC42EP1    PHC2    PCQAP
TM9SF2    TM9SF2    RAB9A
where the alphanumeric id represents the node name (gene name). The first
column contains the source node and the other columns have the destination
nodes. How do I convert this into an edgelist format using R implementation
of igraph ? Thanks in advance for any suggestions.
Regards,
Anupam
_______________________________________________
igraph-help mailing list
http://lists.nongnu.org/mailman/listinfo/igraph-help
--
Gabor Csardi <***@unil.ch> UNIL DGM
anupam sinha
2010-03-09 16:45:06 UTC
Permalink
Dear Gabor,

Thanks a lot for your reply.

Regards,

Anupam
Post by Gábor Csárdi
Dear Anupam,
lines <- readLines("adjlist.txt")
lines <- gsub("[ ]+$", "", gsub("[ ]+", " ", lines)) # remove
trailing and multiple spaces
adjlist <- strsplit(lines, " ")
col1 <- unlist(lapply(adjlist, function(x) rep(x[1], length(x)-1)))
col2 <- unlist(lapply(adjlist, "[", -1))
edgelist <- cbind(col1, col2)
Best,
Gabor
Post by anupam sinha
Dear all,
I have a number of graphs in this format (adjacency
list)
Post by anupam sinha
PABPC4 PABPC4 EEF1A1 SETDB1 XRN1 RIF1
AHCY AHCY
PSCDBP PSCDBP PSCD1
ITSN2 ITSN2 WAS RAD9A LSM8 SYNJ2
TICAM2 TICAM2 IL1R1 IRAK1 TRAF6 IRF3 TLR4 IL1RAP
IRAK3 IRF7 TIRAP
ADCY3 CAMK2G ADCY3
ADCY6 ADCY6 CHRNA7 GNAS RAF1
FHL3 FHL3 ACTB CDC25B MAPK1 LASP1 KLF8 CTBP2
FHL2 ZNF42 SRF CDC42EP1 PHC2 PCQAP
TM9SF2 TM9SF2 RAB9A
where the alphanumeric id represents the node name (gene name). The first
column contains the source node and the other columns have the
destination
Post by anupam sinha
nodes. How do I convert this into an edgelist format using R
implementation
Post by anupam sinha
of igraph ? Thanks in advance for any suggestions.
Regards,
Anupam
_______________________________________________
igraph-help mailing list
http://lists.nongnu.org/mailman/listinfo/igraph-help
--
_______________________________________________
igraph-help mailing list
http://lists.nongnu.org/mailman/listinfo/igraph-help
--
Graduate Student,
Laboratory of Computtational Biology,
Centre For DNA Fingerprinting And Diagnostics,
4-1-714 to 725/2, Tuljaguda complex
Mozamzahi Road, Nampally,
Hyderabad-500001
anupam sinha
2010-03-09 17:07:43 UTC
Permalink
Hi Gabor,
Tried your code but it is giving an empty edgelist
object. Any suggestions ?

Regards,

Anupam
Post by anupam sinha
Dear Gabor,
Thanks a lot for your reply.
Regards,
Anupam
Post by Gábor Csárdi
Dear Anupam,
lines <- readLines("adjlist.txt")
lines <- gsub("[ ]+$", "", gsub("[ ]+", " ", lines)) # remove
trailing and multiple spaces
adjlist <- strsplit(lines, " ")
col1 <- unlist(lapply(adjlist, function(x) rep(x[1], length(x)-1)))
col2 <- unlist(lapply(adjlist, "[", -1))
edgelist <- cbind(col1, col2)
Best,
Gabor
Post by anupam sinha
Dear all,
I have a number of graphs in this format (adjacency
list)
Post by anupam sinha
PABPC4 PABPC4 EEF1A1 SETDB1 XRN1 RIF1
AHCY AHCY
PSCDBP PSCDBP PSCD1
ITSN2 ITSN2 WAS RAD9A LSM8 SYNJ2
TICAM2 TICAM2 IL1R1 IRAK1 TRAF6 IRF3 TLR4 IL1RAP
IRAK3 IRF7 TIRAP
ADCY3 CAMK2G ADCY3
ADCY6 ADCY6 CHRNA7 GNAS RAF1
FHL3 FHL3 ACTB CDC25B MAPK1 LASP1 KLF8 CTBP2
FHL2 ZNF42 SRF CDC42EP1 PHC2 PCQAP
TM9SF2 TM9SF2 RAB9A
where the alphanumeric id represents the node name (gene name). The
first
Post by anupam sinha
column contains the source node and the other columns have the
destination
Post by anupam sinha
nodes. How do I convert this into an edgelist format using R
implementation
Post by anupam sinha
of igraph ? Thanks in advance for any suggestions.
Regards,
Anupam
_______________________________________________
igraph-help mailing list
http://lists.nongnu.org/mailman/listinfo/igraph-help
--
_______________________________________________
igraph-help mailing list
http://lists.nongnu.org/mailman/listinfo/igraph-help
--
Graduate Student,
Laboratory of Computtational Biology,
Centre For DNA Fingerprinting And Diagnostics,
4-1-714 to 725/2, Tuljaguda complex
Mozamzahi Road, Nampally,
Hyderabad-500001
--
Graduate Student,
Laboratory of Computtational Biology,
Centre For DNA Fingerprinting And Diagnostics,
4-1-714 to 725/2, Tuljaguda complex
Mozamzahi Road, Nampally,
Hyderabad-500001
Gábor Csárdi
2010-03-09 17:49:23 UTC
Permalink
You might have a different file format than I used, e.g. tabulators
instead of spaces. (This is why it is better to attach an example
file, than putting it into the mail.)

Gábor
Post by anupam sinha
Hi Gabor,
                   Tried your code but it is giving an empty edgelist
object. Any suggestions ?
Regards,
Anupam
Post by anupam sinha
Dear Gabor,
                         Thanks a lot for your reply.
Regards,
Anupam
Post by Gábor Csárdi
Dear Anupam,
lines <- readLines("adjlist.txt")
lines <- gsub("[ ]+$", "", gsub("[ ]+", " ", lines))   # remove
trailing and multiple spaces
adjlist <- strsplit(lines, " ")
col1 <- unlist(lapply(adjlist, function(x) rep(x[1], length(x)-1)))
col2 <- unlist(lapply(adjlist, "[", -1))
edgelist <- cbind(col1, col2)
Best,
Gabor
Post by anupam sinha
Dear all,
                   I have a number of graphs in this format (adjacency
list)
PABPC4    PABPC4    EEF1A1    SETDB1    XRN1    RIF1
AHCY         AHCY
PSCDBP   PSCDBP    PSCD1
ITSN2        ITSN2    WAS    RAD9A    LSM8    SYNJ2
TICAM2     TICAM2    IL1R1    IRAK1    TRAF6    IRF3    TLR4    IL1RAP
IRAK3    IRF7    TIRAP
ADCY3      CAMK2G    ADCY3
ADCY6      ADCY6    CHRNA7    GNAS    RAF1
FHL3          FHL3    ACTB    CDC25B    MAPK1    LASP1    KLF8    CTBP2
FHL2    ZNF42    SRF    CDC42EP1    PHC2    PCQAP
TM9SF2    TM9SF2    RAB9A
where the alphanumeric id represents the node name (gene name). The first
column contains the source node and the other columns have the destination
nodes. How do I convert this into an edgelist format using R implementation
of igraph ? Thanks in advance for any suggestions.
Regards,
Anupam
_______________________________________________
igraph-help mailing list
http://lists.nongnu.org/mailman/listinfo/igraph-help
--
_______________________________________________
igraph-help mailing list
http://lists.nongnu.org/mailman/listinfo/igraph-help
--
Graduate Student,
Laboratory of Computtational Biology,
Centre For DNA Fingerprinting And Diagnostics,
4-1-714 to 725/2, Tuljaguda complex
Mozamzahi Road, Nampally,
Hyderabad-500001
--
Graduate Student,
Laboratory of Computtational Biology,
Centre For DNA Fingerprinting And Diagnostics,
4-1-714 to 725/2, Tuljaguda complex
Mozamzahi Road, Nampally,
Hyderabad-500001
_______________________________________________
igraph-help mailing list
http://lists.nongnu.org/mailman/listinfo/igraph-help
--
Gabor Csardi <***@unil.ch> UNIL DGM
anupam sinha
2010-03-10 08:49:34 UTC
Permalink
Hi Gabor,
As per your suggestion I changed the space to tab (as
it was the delimiter in my file and apologies for not mentioning that fact)
and now the code works fine. Thanks a million.

Regards,

Anupam
Post by Gábor Csárdi
You might have a different file format than I used, e.g. tabulators
instead of spaces. (This is why it is better to attach an example
file, than putting it into the mail.)
Gábor
Post by anupam sinha
Hi Gabor,
Tried your code but it is giving an empty edgelist
object. Any suggestions ?
Regards,
Anupam
Post by anupam sinha
Dear Gabor,
Thanks a lot for your reply.
Regards,
Anupam
Post by Gábor Csárdi
Dear Anupam,
lines <- readLines("adjlist.txt")
lines <- gsub("[ ]+$", "", gsub("[ ]+", " ", lines)) # remove
trailing and multiple spaces
adjlist <- strsplit(lines, " ")
col1 <- unlist(lapply(adjlist, function(x) rep(x[1], length(x)-1)))
col2 <- unlist(lapply(adjlist, "[", -1))
edgelist <- cbind(col1, col2)
Best,
Gabor
Post by anupam sinha
Dear all,
I have a number of graphs in this format
(adjacency
Post by anupam sinha
Post by anupam sinha
Post by Gábor Csárdi
Post by anupam sinha
list)
PABPC4 PABPC4 EEF1A1 SETDB1 XRN1 RIF1
AHCY AHCY
PSCDBP PSCDBP PSCD1
ITSN2 ITSN2 WAS RAD9A LSM8 SYNJ2
TICAM2 TICAM2 IL1R1 IRAK1 TRAF6 IRF3 TLR4
IL1RAP
Post by anupam sinha
Post by anupam sinha
Post by Gábor Csárdi
Post by anupam sinha
IRAK3 IRF7 TIRAP
ADCY3 CAMK2G ADCY3
ADCY6 ADCY6 CHRNA7 GNAS RAF1
FHL3 FHL3 ACTB CDC25B MAPK1 LASP1 KLF8
CTBP2
Post by anupam sinha
Post by anupam sinha
Post by Gábor Csárdi
Post by anupam sinha
FHL2 ZNF42 SRF CDC42EP1 PHC2 PCQAP
TM9SF2 TM9SF2 RAB9A
where the alphanumeric id represents the node name (gene name). The first
column contains the source node and the other columns have the destination
nodes. How do I convert this into an edgelist format using R implementation
of igraph ? Thanks in advance for any suggestions.
Regards,
Anupam
_______________________________________________
igraph-help mailing list
http://lists.nongnu.org/mailman/listinfo/igraph-help
--
_______________________________________________
igraph-help mailing list
http://lists.nongnu.org/mailman/listinfo/igraph-help
--
Graduate Student,
Laboratory of Computtational Biology,
Centre For DNA Fingerprinting And Diagnostics,
4-1-714 to 725/2, Tuljaguda complex
Mozamzahi Road, Nampally,
Hyderabad-500001
--
Graduate Student,
Laboratory of Computtational Biology,
Centre For DNA Fingerprinting And Diagnostics,
4-1-714 to 725/2, Tuljaguda complex
Mozamzahi Road, Nampally,
Hyderabad-500001
_______________________________________________
igraph-help mailing list
http://lists.nongnu.org/mailman/listinfo/igraph-help
--
_______________________________________________
igraph-help mailing list
http://lists.nongnu.org/mailman/listinfo/igraph-help
--
Graduate Student,
Laboratory of Computtational Biology,
Centre For DNA Fingerprinting And Diagnostics,
4-1-714 to 725/2, Tuljaguda complex
Mozamzahi Road, Nampally,
Hyderabad-500001
Loading...