igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Re: network neighborhood


From: Gábor Csárdi
Subject: Re: [igraph] Re: network neighborhood
Date: Fri, 1 Oct 2010 12:21:08 +0200

Dear Anupam,

there are several mistakes in your code. Here is a working version, I
haven't tested it much, sorry, no time right now.

library(igraph)

path <- "/tmp/test/"

## Some test data
dir.create(path)
for (i in 1:10) {
  g <- erdos.renyi.game(10, 1/10)
  write.graph(g, file=paste(sep="", "/tmp/test/graph", i, ".ncol"))
}

####

files <- dir(path)
for(i in 1:length(files)){
  file <- paste(path, files[i], sep="")
  g <- read.graph(file, format="ncol",  directed=FALSE,
                weights=FALSE)
  g <- simplify(g)
  subgraphs <- graph.neighborhood(g, 1, nodes=V(g))
  for(j in subgraphs){
    gr_name <- paste(path, files[i], j, sep="")
    write.graph(j, file=gr_name, format="ncol")
  }
}

Please read it over, compare it to yours, and tell us if something is not clear.

Best,
Gabor


On Fri, Oct 1, 2010 at 9:53 AM, anupam sinha <address@hidden> wrote:
>
>
>
>>
>>
>> Dear all,
>>                  I have a list of network files for which I want to find
>> the network neighborhoods(order=1) of each of the nodes of these networks.
>> And then store all the subgraphs hence obtained in separate files.Another
>> thing that I would like to do is to name them in such a way so as to figure
>> out from which network file have they originated. But what I am getting as
>> output is an empty file.Here's my code :
>>
>>
>> library("igraph")
>> path <- "path/to/network/files/"
>> files <- dir(path)
>> for(i in 1:length(files)){
>>                           file <- paste(path,"/",files[i],sep="")
>>                           g<-read.graph(file,format="ncol",
>> directed=FALSE, weights=FALSE)
>>                           g<-simplify(g)
>>                           subgraphs<-graph.neighborhood(g,1,nodes=V(g))
>> for(j in subgraphs){
>> gr_name <- paste(file,j,sep="")
>> write.graph(gr,"/path/tonetwork/files/gr_name.txt",format="ncol")
>> }}
>>
>> Attached herewith are a couple of network files. Can anyone tell where am
>> I going wrong? Thanks in advance.
>>
>> Here's my sessionInfo():
>>
>> R version 2.11.0 (2010-04-22)
>> x86_64-redhat-linux-gnu
>>
>> 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=C              LC_MESSAGES=en_US.UTF-8
>>  [7] LC_PAPER=en_US.UTF-8       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] igraph_0.5.3
>>
>> loaded via a namespace (and not attached):
>> [1] tools_2.11.0
>>
>>
>> Regards,
>>
>> Anupam Sinha
>>
>>
>>
>>
>>
>
>
> --
> Graduate Student,
> Center For DNA Fingerprinting And Diagnostics,
> 4-1-714 to 725/2, Tuljaguda complex
> Mozamzahi Road, Nampally,
> Hyderabad-500001
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>
>



-- 
Gabor Csardi <address@hidden>     UNIL DGM



reply via email to

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