当前位置: 首页>>代码示例>>Python>>正文


Python networkx.write_adjlist函数代码示例

本文整理汇总了Python中networkx.write_adjlist函数的典型用法代码示例。如果您正苦于以下问题:Python write_adjlist函数的具体用法?Python write_adjlist怎么用?Python write_adjlist使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了write_adjlist函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_graph

def generate_graph(n, beta, mean_degree):
    """
    Test Graph generation
    """
    G = nx.empty_graph(n)
    
    degreeArray = utils.degreeDistribution(beta, n, mean_degree)
    
    utils.randPairings(G, degreeArray)
    
    # output of the RGG
    if not os.path.exists('generated'):
        os.mkdir('generated')
    
    txtName = "generated/adj-%s-%s-%s-.txt" % (str(n), str(beta), str(mean_degree))
    nx.write_adjlist(G, txtName)
    
    # plotting
    utils.drawDegreeHistogram(G)
    if n < 1000:
        utils.drawGraph(G)
    pngname = "generated/graph-%s-%s-%s-.png" % (str(n), str(beta), str(mean_degree))
    plt.savefig(pngname)
    
    if not os.path.exists('feed'):
        os.mkdir('feed')
    
    utils.generateFeed(n)
开发者ID:berliozmeister,项目名称:9989879879874983,代码行数:28,代码来源:generator.py

示例2: gnp_survey_benchmark

def gnp_survey_benchmark(path, n_array, p_array):
    with open(path, 'w', newline='\n') as f:
        w = csv.writer(f)
        w.writerow(['n', 'p = 0.2', 'p = 0.4', 'p = 0.5', 'p = 0.6', 'p = 0.8'])
        for n in n_array:
            list = [str(n)]
            for p in p_array:
                print("Starting trial n = " + str(n) + ", p = " + str(p) + ".")
                G = nx.gnp_random_graph(n, p)
                for (i, j) in G.edges_iter():
                    G[i][j]['weight'] = 1
                print("Calling GH algorithm")
                ############ TIMING ############
                start = time.time()
                gh = gomory_hu_tree(G)
                end = time.time()
                t = end-start
                ########## END TIMING ##########
                list.append(t)
                print("Completed trial n = " + str(n) + ", p = " + str(p) + ".")
                print("Time = " + str(t))
                nx.write_adjlist(G, 'Graph(' + str(n) + "," + str(p) + ").csv")
                nx.write_adjlist(gh, 'Gomory_Hu(' + str(n) + "," + str(p) + ").csv")
                print()
            w.writerow(list)
开发者ID:lucasrgagnon,项目名称:Gomory-Hu_Implemenation,代码行数:25,代码来源:benchmarking.py

示例3: construct_HardTh

def construct_HardTh(fCorr, ffMRI):
    #
    # a function to generate hard thresholding networks
    #
    #
    # some parameters
    Target_K = [10, 20, 30, 40, 50]
    # Output directory is relative to fCorr directory
    CorrDir, fCorrMat = os.path.split(fCorr)
    BaseDir, CorrDirName = os.path.split(CorrDir)
    OutBase = os.path.join(BaseDir, 'Adjlist')
    if not os.path.exists(OutBase):
        os.makedirs(OutBase)
    OutDir = os.path.join(OutBase, 'Network_HardTh')
    if not os.path.exists(OutDir):
        os.makedirs(OutDir)
    # loading the correlation matrix
    R, NodeInd = NetUtil.load_corrmat_sparse(fCorr, ffMRI)
    # loop for generating hard-th networks
    for K in Target_K:
        print "Generating a network with threshold <k>=" + str(K)
        # generating the network
        G, RTh = NetUtil.net_builder_HardTh(R, NodeInd, K)
        # saving the network
        fNetFile = "Network_K" + str(K) + ".adjlist"
        fNet = os.path.join(OutDir,fNetFile)
        nx.write_adjlist(G, fNet)
开发者ID:sathayas,项目名称:fMRIConnectome,代码行数:27,代码来源:construct_networks.py

示例4: construct_HardThE

def construct_HardThE(fCorr, ffMRI):
    #
    # a function to generate hard thresholding networks with the same number
    # of edges as rank-thresholded networks.
    #
    #
    # some parameters
    Target_d = [3, 4, 5, 6, 8, 10, 15, 20, 30]
    # Output directory is relative to fCorr directory
    CorrDir, fCorrMat = os.path.split(fCorr)
    BaseDir, CorrDirName = os.path.split(CorrDir)
    OutBase = os.path.join(BaseDir, 'Adjlist')
    if not os.path.exists(OutBase):
        os.makedirs(OutBase)
    OutDir = os.path.join(OutBase, 'Network_HardThE')
    if not os.path.exists(OutDir):
        os.makedirs(OutDir)
    # directory where rank-th networks are
    RankDir = os.path.join(OutBase, 'Network_RankTh')
    # loading the correlation matrix
    R, NodeInd = NetUtil.load_corrmat_sparse(fCorr, ffMRI)
   # loop for generating hard-th networks
    for d in Target_d:
        print "Generating an equivalent hard thresholded network with d=" + str(d)
        # loading the rank thresholded network to determine the number of edges
        fdNetFile = "Network_d" + str(d) + ".adjlist"
        fdNet = os.path.join(RankDir,fdNetFile)
        tmpG = nx.read_adjlist(fdNet)
        E = len(tmpG.edges())
        # generating the network
        G, RTh = NetUtil.net_builder_HardThE(R, NodeInd, E)
        # saving the network
        fNetFile = "Network_EQd" + str(d) + ".adjlist"
        fNet = os.path.join(OutDir,fNetFile)
        nx.write_adjlist(G, fNet)
开发者ID:sathayas,项目名称:fMRIConnectome,代码行数:35,代码来源:construct_networks.py

示例5: construct_RankTh

def construct_RankTh(fCorr, ffMRI):
    #
    # a function to generate rank-based thresholding networks
    #
    #
    # some parameters
    Target_d = [3, 4, 5, 6, 8, 10, 15, 20, 30]
    # Output directory is relative to fCorr directory
    CorrDir, fCorrMat = os.path.split(fCorr)
    BaseDir, CorrDirName = os.path.split(CorrDir)
    OutBase = os.path.join(BaseDir, 'Adjlist')
    if not os.path.exists(OutBase):
        os.makedirs(OutBase)
    OutDir = os.path.join(OutBase, 'Network_RankTh')
    if not os.path.exists(OutDir):
        os.makedirs(OutDir)
    # loading the correlation matrix
    R, NodeInd = NetUtil.load_corrmat_sparse(fCorr, ffMRI)
    # loop for generating rank-th networks
    for iTh in range(len(Target_d)):
        print "Generating a network with threshold d=" + str(Target_d[iTh])
        # generating the network
        if iTh==0:
            G, trR = NetUtil.net_builder_RankTh(R, NodeInd, Target_d[iTh])
            R = [] # releasing the memory
        else:
            # just generate the difference between the previous threshold.
            # then combine the resulting graphs
            deltaG, trR = NetUtil.net_builder_RankTh(trR, NodeInd, 
                                                Target_d[iTh]-Target_d[iTh-1])
            G = nx.compose(G, deltaG)
        # saving the network
        fNetFile = "Network_d" + str(Target_d[iTh]) + ".adjlist"
        fNet = os.path.join(OutDir,fNetFile)
        nx.write_adjlist(G, fNet)
开发者ID:sathayas,项目名称:fMRIConnectome,代码行数:35,代码来源:construct_networks.py

示例6: construct_de_bruijn_velvet

def construct_de_bruijn_velvet(kmers, draw, outfile):
	#make list of k-1mers for quick edge construction
	k1mers = [x[:-1] for x in kmers.keys()]
	k1mers_array = np.array(k1mers)

	#find overlaps
	edge_list = []
	for kmer in kmers.keys():
		matches = np.where(k1mers_array==kmer[1:])
		for match in matches[0]:
			#print match
			edge_list.append((kmer, kmers.keys()[match]))

	#make graph
	G = nx.DiGraph()
	#add seq_kmers as nodes and overlaps as edges
	for kmer in kmers.items():
		G.add_node(kmer[0], num=kmer[1])
	G.add_edges_from(edge_list)

	# draw the graph if desired
	if draw == "True":
		nx.draw_spring(G)
		plt.show()

	#output adjacency list format of the graph if desired
	if outfile != "":
		nx.write_adjlist(G, outfile)

	return G
开发者ID:bsiranosian,项目名称:brown-compbio,代码行数:30,代码来源:de_bruijn_velvet.py

示例7: createMergedGraph

def createMergedGraph(groupSampleDict, processedDataDir, rawModelDir):

    print 'Merging genomes from specified taxonomic group'

# Loop over the keys of the dictionary, one for each group
    for group in groupSampleDict:

# Create an empty graph object
        mergedGraph = nx.DiGraph()

# Read in the graph of the group and merge with the graph from the previous
# iteration
        for sample in groupSampleDict[group]:

# Read in adjacency list and convert to digraph object
            myDiGraph = nx.read_adjlist(rawModelDir+'/'+sample+'/'+sample+'AdjList.txt',
                                create_using=nx.DiGraph())

# Append to the previous graph
            mergedGraph = nx.compose(mergedGraph, myDiGraph)

# Check that the proper output directory exists. It not, create it.
        if not os.path.exists(processedDataDir+'/'+group):
            os.makedirs(processedDataDir+'/'+group)

        nx.write_adjlist(mergedGraph, processedDataDir+'/'+group+'/'+group+'AdjList.txt')
        nx.write_graphml(mergedGraph, processedDataDir+'/'+group+'/'+group+'Graph.xml')

    return
开发者ID:joshamilton,项目名称:reverseEcology,代码行数:29,代码来源:graphFunctions.py

示例8: RGG

def RGG(n, beta, mean_degree):
    G = nx.empty_graph(n)
    powerLawArray = utils.powerLawArray(n, beta, mean_degree)
    powerLawDegreeArray = np.array(powerLawArray, dtype = np.longlong)
    sumOfDegrees = powerLawDegreeArray.sum()
    delimiterArray = np.cumsum(powerLawDegreeArray)
    delimiterArray = np.insert(delimiterArray, 0, 0)
    delimiterArray = np.delete(delimiterArray, n)
    someCounter = 0
    while someCounter < sumOfDegrees/2:
        G.add_edge(np.searchsorted(delimiterArray, rnd.randrange(sumOfDegrees)),
               np.searchsorted(delimiterArray, rnd.randrange(sumOfDegrees)))
        someCounter += 1
    txtname = "generated/adj-%s-%s-%s-.txt" % (str(n), str(beta), str(mean_degree))
    nx.write_adjlist(G, txtname)
    degreeSequence=sorted(nx.degree(G).values(),reverse=True)
    dmax=max(degreeSequence)
    plt.clf()
    plt.cla()
    plt.loglog(degreeSequence,'b-',marker='o')
    plt.title("Degree rank plot")
    plt.ylabel("degree")
    plt.xlabel("rank")
    if n < 1000:
        plt.axes([0.45,0.45,0.45,0.45])
        plt.cla()
        Gcc=nx.connected_component_subgraphs(G)[0]
        pos=nx.spring_layout(Gcc)
        plt.axis('off')
        nx.draw_networkx_nodes(Gcc,pos,node_size=20)
        nx.draw_networkx_edges(Gcc,pos,alpha=0.4)
    pngname = "generated/graph-%s-%s-%s-.png" % (str(n), str(beta), str(mean_degree))
    plt.savefig(pngname)
开发者ID:berliozmeister,项目名称:6967986796707097,代码行数:33,代码来源:webgenerator.py

示例9: test_adjlist_delimiter

 def test_adjlist_delimiter(self):
     fh = io.BytesIO()
     G = nx.path_graph(3)
     nx.write_adjlist(G, fh, delimiter=':')
     fh.seek(0)
     H = nx.read_adjlist(fh, nodetype=int, delimiter=':')
     assert_nodes_equal(list(H), list(G))
     assert_edges_equal(list(H.edges()), list(G.edges()))
开发者ID:yamaguchiyuto,项目名称:networkx,代码行数:8,代码来源:test_adjlist.py

示例10: issues_network

def issues_network(out, repo, github):
    """Builds issues netowrk"""

    interactions = datautil.get_issues_interaction(repo, github)

    graph = networkutil.create_interaction_network(interactions,
            repo_name=repo)

    nx.write_adjlist(graph, out)
开发者ID:saeed-abdullah,项目名称:github-social,代码行数:9,代码来源:social.py

示例11: allFiles

def allFiles(groupName):
    fdRead = open('%s' % groupName, 'r')  #open file with edge list
    lines = fdRead.readlines()  #read all lines
    fdRead.close()  #close file

    G = nx.parse_edgelist(lines, nodetype=int)  #builte graph with edge list file
    nx.write_adjlist(G, 'adj_list.txt')  #write graph as adjacency matrix to file
    getPartitions(G)  #get partitions graph
    edgesInCommunitiesGraph('adj_list.txt', 'partitions.txt')  #add edges to graph of partitions
开发者ID:joker-ace,项目名称:vksgui,代码行数:9,代码来源:conversionTools.py

示例12: test_adjlist_integers

 def test_adjlist_integers(self):
     (fd, fname) = tempfile.mkstemp()
     G = nx.convert_node_labels_to_integers(self.G)
     nx.write_adjlist(G, fname)
     H = nx.read_adjlist(fname, nodetype=int)
     H2 = nx.read_adjlist(fname, nodetype=int)
     assert_nodes_equal(list(H), list(G))
     assert_edges_equal(list(H.edges()), list(G.edges()))
     os.close(fd)
     os.unlink(fname)
开发者ID:yamaguchiyuto,项目名称:networkx,代码行数:10,代码来源:test_adjlist.py

示例13: convert_graph_to_text

def convert_graph_to_text(graph, filename):
    """
    given a graph object, write a file containing the adjacency list.
    this is the minimum data required to reconstruct the graph.
    :param graph: the graph object to get the list from.
    :param filename: the name of the file to write to.
    :return:
    """
    networkx.write_adjlist(graph, filename)
    return
开发者ID:rask004,项目名称:youtube-channel-graphing,代码行数:10,代码来源:yt_script.py

示例14: main

def main():
    badges = user_badge_extract('Badges.xml')
    G = create_graph(badges)
    
#    draw_graph(G)
    
    # Saving the graph in Pajek format
    nx.write_pajek(G, "graph.net")
    
    # Saving the graph as AdjList
    nx.write_adjlist(G, "graph.adjlist")
开发者ID:H4iku,项目名称:stack-badges-manipulate,代码行数:11,代码来源:badges_graph_generator.py

示例15: test_adjlist_graph

 def test_adjlist_graph(self):
     G=self.G
     (fd,fname)=tempfile.mkstemp()
     nx.write_adjlist(G,fname)  
     H=nx.read_adjlist(fname)
     H2=nx.read_adjlist(fname)
     assert_not_equal(H,H2) # they should be different graphs
     assert_equal(sorted(H.nodes()),sorted(G.nodes()))
     assert_equal(sorted(H.edges()),sorted(G.edges()))
     os.close(fd)
     os.unlink(fname)
开发者ID:c0ns0le,项目名称:zenoss-4,代码行数:11,代码来源:test_adjlist.py


注:本文中的networkx.write_adjlist函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。