***** To join INSNA, visit http://www.insna.org ***** great question/answers, if only we had a StackOverflow for SNA... :) 2015-07-10 7:05 GMT+02:00 Moses Boudourides <[log in to unmask]>: > ***** To join INSNA, visit http://www.insna.org ***** > > Yes, Dmitry, this might be the case for huge networks. In that case I > would do what you were doing. Thank you. > > On Fri, Jul 10, 2015 at 8:01 AM, Dmitry Zinoviev <[log in to unmask]> > wrote: > > Moses, > > > > With all my respect, it's the line 2 of your snippet that may not work - > > exactly because the network is huge. One shall use a CSV reader or simply > > read the CSV edge list line by line or block by block and filter out the > > edges that are not in the subset. Assuming that the edges are stored as > two > > columns of nodes and the CSV file has no header, the following snippet > shall > > work: > > > > csvIn = open ("HugeFile.csv") > > csvOut = open ("Subset.csv", "w") > > > > line = csvIn.readline () > > while line: > > node1, node2 = line.strip().split(",") > > if node1 in NodesSmall and node2 in NodesSmall: > > csvOut.write (line) > > line = csvIn.readline () > > > > csvOut.close () > > > > For the sake of performance, the list of nodes in the subset shall be > > converted to a dictionary: > > NodesSmall = dict ((node, node) for node in Gsmall.nodes()) > > > > Hope it helps. > > > > On Fri, Jul 10, 2015 at 12:54 AM, Moses Boudourides > > <[log in to unmask]> wrote: > >> > >> ***** To join INSNA, visit http://www.insna.org ***** > >> > >> Absolutely I would back Dmitry in suggesting the use of Python in > >> order to merge networks as far as one avoids to use the relabelling > >> mapping employed in NetworkX (it's very problematic, I believe it has > >> to be rewritten). However, this is not the case here and so what I > >> would do is something like the following: > >> > >> import networkx as nx > >> Ghuge = nx.read_graphml("HugeNetwork.graphml") > >> Gsmall = nx.read_graphml("SubsetNetwork.graphml") > >> NodesSmall = Gsmall.nodes() > >> G = Ghuge.subgraph(NodesSmall) > >> attributesDictionary = Gsmall.nodes(data=True) > >> nx.set_node_attributes(G, 'attribute', attributesDictionary) > > > > -- > > Dmitry Zinoviev > > Professor of Computer Science > > Suffolk University, Boston, MA 02114 > > _____________________________________________________________________ > SOCNET is a service of INSNA, the professional association for social > network researchers (http://www.insna.org). To unsubscribe, send > an email message to [log in to unmask] containing the line > UNSUBSCRIBE SOCNET in the body of the message. > -- Simone Gabbriellini, PhD PostDoc@DISI, University of Bologna mobile: +39 340 39 75 626 email: [log in to unmask] home: www.digitaldust.it DigitalBrains srl Amministratore mobile: +39 340 39 75 626 email: [log in to unmask] home: www.digitalbrains.it _____________________________________________________________________ SOCNET is a service of INSNA, the professional association for social network researchers (http://www.insna.org). To unsubscribe, send an email message to [log in to unmask] containing the line UNSUBSCRIBE SOCNET in the body of the message.