• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python pygraph.digraph函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: testAddEmptyGraph

 def testAddEmptyGraph(self):
     gr1 = pygraph.digraph()
     gr1.generate(25, 100)
     gr1c = copy.copy(gr1)
     gr2 = pygraph.digraph()
     gr1.add_graph(gr2)
     self.assertTrue(gr1.nodes() == gr1c.nodes())
     self.assertTrue(gr1.edges() == gr1c.edges())
开发者ID:svn2github,项目名称:python-graph2,代码行数:8,代码来源:unittests-digraph.py


示例2: testAddGraph

 def testAddGraph(self):
     gr1 = pygraph.digraph()
     gr1.generate(25, 100)
     gr2 = pygraph.digraph()
     gr2.generate(40, 200)
     gr1.add_graph(gr2)
     for each in gr2.nodes():
         self.assertTrue(each in gr1)
     for each in gr2.edges():
         self.assertTrue(each in gr1.edges())
开发者ID:svn2github,项目名称:python-graph2,代码行数:10,代码来源:unittests-digraph.py


示例3: graphize

  def graphize(self):
    try:
      self.graph = pygraph.digraph()
    except (NameError, AttributeError):
      self.graph = digraph()   

    modules = [self.topModule] + self.moduleList
    # first, we must add all the nodes. Only then can we add all the edges
    self.graph.add_nodes(modules)

    # here we have a strictly directed graph, so we need only insert directed edges
    for module in modules:
      def checkParent(child):
        if module.name == child.parent:
          return True
        else:
          return False

      children = filter(checkParent, modules)
      for child in children:
        # due to compatibility issues, we need these try catch to pick the 
        # right function prototype.
        try:
          self.graph.add_edge(module,child) 
        except TypeError:
          self.graph.add_edge((module,child)) 
开发者ID:sunila,项目名称:airblue_7dec12,代码行数:26,代码来源:ModuleList.py


示例4: graphizeSynth

  def graphizeSynth(self):
    try:
      self.graphSynth = pygraph.digraph()
    except (NameError, AttributeError):
      self.graphSynth = digraph()
    modulesUnfiltered = [self.topModule] + self.moduleList
    # first, we must add all the nodes. Only then can we add all the edges
    # filter by synthesis boundaries
    modules = filter(checkSynth, modulesUnfiltered)
    self.graphSynth.add_nodes(modules)

    # here we have a strictly directed graph, so we need only insert directed edges
    for module in modules:
      def checkParent(child):
        if module.name == child.synthParent:
          return True
        else:
          return False

      children = filter(checkParent, modules)
      for child in children:
        #print "Adding p: " + module.name + " c: " + child.name
        try:
          self.graphSynth.add_edge(module,child) 
        except TypeError:
          self.graphSynth.add_edge((module,child)) 
开发者ID:sunila,项目名称:airblue_7dec12,代码行数:26,代码来源:ModuleList.py


示例5: sort_out_covering_exons

def sort_out_covering_exons (cursor, exons):

    # havana is manually curated and gets priority
    is_ensembl = {}
    is_havana  = {}
    for exon in exons:
        logic_name = get_logic_name(cursor, exon.analysis_id)
        is_ensembl[exon] = ('ensembl' in logic_name)
        is_havana [exon] = ('havana'  in logic_name)

    dg = digraph()
    dg.add_nodes(exons)
    for exon1, exon2 in combinations(dg.nodes(),2):
        master, covered = find_master(cursor, exon1,exon2,is_ensembl,is_havana)
        if master is not None and covered is not None:
            dg.add_edge(master,covered)
    assert not find_cycle(dg)
    clusters = dict(((k,v) for k,v in accessibility(dg).iteritems()
                     if not dg.incidents(k)))
    for k in clusters:
        clusters[k].remove(k)

    for master_exon, covered_list in clusters.iteritems():
        master_exon.covering_exon       = -1 # nobody's covering this guy
        master_exon.covering_exon_known = -1 # formal
        for covered_exon in covered_list:
            covered_exon.covering_exon       = master_exon.exon_id
            covered_exon.covering_exon_known = master_exon.is_known
开发者ID:ivanamihalek,项目名称:exolocator,代码行数:28,代码来源:06_exon_coordinates.py


示例6: testSanityDigraph

 def testSanityDigraph(self):
     G = pygraph.digraph()
     G.generate(100, 500)
     st, lo = G.breadth_first_search()
     for each in G:
         if (st[each] != None):
             assert lo.index(each) > lo.index(st[each])
开发者ID:svn2github,项目名称:python-graph2,代码行数:7,代码来源:unittests-searching.py


示例7: testDigraph

 def testDigraph(self):
     
     def has_parent(node, list):
         for each in list:
             if gr.has_edge(each, node):
                 return True
         return (ts == [])
         
     gr = pygraph.digraph()
     gr.add_nodes([0,1,2,3,4,5,6,7,8])
     gr.add_edge(0,1)
     gr.add_edge(0,2)
     gr.add_edge(1,3)
     gr.add_edge(1,4)
     gr.add_edge(2,5)
     gr.add_edge(2,6)
     gr.add_edge(3,7)
     gr.add_edge(8,0)
     gr.add_edge(7,5)
     gr.add_edge(3,0)
     gr.add_edge(4,3)
     gr.add_edge(2,7)
     gr.add_edge(6,0)
     ts = topological_sorting(gr)
     while (ts):
         x = ts.pop()
         assert has_parent(x, ts)
开发者ID:svn2github,项目名称:python-graph2,代码行数:27,代码来源:unittests-sorting.py


示例8: testReadDigraphDot

 def testReadDigraphDot(self):
     dot = ['digraph graphname {', '1;', '2;', '3;', '4;', '5;', '1 -> 2;', '4 -> 5;', '1 -> 5;', '2 -> 3;', '2 -> 4;', '3 -> 5;', '}', '']
     dot = "\n".join(dot)
     gr = pygraph.digraph()
     gr.read(dot, 'dot')
     self._check_nodes(gr, dot)
     self._check_arrows(gr, dot)
开发者ID:svn2github,项目名称:python-graph2,代码行数:7,代码来源:unittests-readwrite.py


示例9: testGraphComplete

 def testGraphComplete(self):
     gr = pygraph.digraph()
     gr.add_nodes(xrange(10))
     gr.complete()
     for i in xrange(10):
         for j in range(10):
             self.assertTrue((i, j) in gr.edges() or i == j)
开发者ID:svn2github,项目名称:python-graph2,代码行数:7,代码来源:unittests-digraph.py


示例10: testNoCycleDigraph2

 def testNoCycleDigraph2(self):
     G = pygraph.digraph()
     G.add_nodes([1,2,3])
     G.add_edge(1,2)
     G.add_edge(1,3)
     G.add_edge(2,3)
     assert G.find_cycle() == []
开发者ID:svn2github,项目名称:python-graph2,代码行数:7,代码来源:unittests-cycles.py


示例11: testGraphInverse

 def testGraphInverse(self):
     gr = pygraph.digraph()
     gr.generate(50, 300)
     inv = gr.inverse()
     for each in gr.edges():
         self.assertTrue(each not in inv.edges())
     for each in inv.edges():
         self.assertTrue(each not in gr.edges())
开发者ID:svn2github,项目名称:python-graph2,代码行数:8,代码来源:unittests-digraph.py


示例12: testRandomGraph

 def testRandomGraph(self):
     gr = pygraph.digraph()
     gr.generate(100, 500)
     self.assertEqual(gr.nodes(), range(100))
     self.assertEqual(len(gr.edges()), 500)
     for each, other in gr.edges():
         self.assertTrue(each in gr)
         self.assertTrue(other in gr)
开发者ID:svn2github,项目名称:python-graph2,代码行数:8,代码来源:unittests-digraph.py


示例13: testNodeRemoval

 def testNodeRemoval(self):
     gr = pygraph.digraph()
     gr.generate(10, 90)
     gr.del_node(0)
     self.assertTrue(0 not in gr)
     for each, other in gr.edges():
         self.assertTrue(each in gr)
         self.assertTrue(other in gr)
开发者ID:svn2github,项目名称:python-graph2,代码行数:8,代码来源:unittests-digraph.py


示例14: testNoCycleDigraph

 def testNoCycleDigraph(self):
     G = pygraph.digraph()
     G.add_nodes([1, 2, 3, 4, 5])
     G.add_edge(1, 2)
     G.add_edge(2, 3)
     G.add_edge(2, 4)
     G.add_edge(4, 5)
     G.add_edge(3, 5)
     assert G.find_cycle() == []
开发者ID:svn2github,项目名称:python-graph2,代码行数:9,代码来源:unittests-cycles.py


示例15: testMisleadingDigraph

 def testMisleadingDigraph(self):
     G = pygraph.digraph()
     G.add_nodes([1, 2, 3, 4, 5])
     G.add_edge(1, 2)
     G.add_edge(2, 3)
     G.add_edge(2, 4)
     G.add_edge(4, 5)
     G.add_edge(3, 5)
     G.add_edge(3, 1)
     assert G.find_cycle() == [1, 2, 3]
开发者ID:svn2github,项目名称:python-graph2,代码行数:10,代码来源:unittests-cycles.py


示例16: testSmallCycleDigraph

 def testSmallCycleDigraph(self):
     G = pygraph.digraph()
     G.add_nodes([1, 2, 3, 4, 5])
     G.add_edge(1, 2)
     G.add_edge(2, 3)
     G.add_edge(2, 4)
     G.add_edge(4, 5)
     G.add_edge(2, 1)
     # Cycle: 1-2
     assert G.find_cycle() == [1,2]
开发者ID:svn2github,项目名称:python-graph2,代码行数:10,代码来源:unittests-cycles.py


示例17: testDigraph

 def testDigraph(self):
     G = pygraph.digraph()
     G.add_nodes([1, 2, 3, 4, 5])
     G.add_edge(1, 2)
     G.add_edge(2, 3)
     G.add_edge(2, 4)
     G.add_edge(4, 5)
     G.add_edge(5, 1)
     # Cycle: 1-2-4-5
     assert find_cycle(G) == [1,2,4,5]
开发者ID:svn2github,项目名称:python-graph2,代码行数:10,代码来源:unittests-cycles.py


示例18: testWriteDigraphDot

 def testWriteDigraphDot(self):
     gr = pygraph.digraph()
     gr.add_nodes([1, 2, 3, 4, 5])
     gr.add_edge(1, 2)
     gr.add_edge(2, 3)
     gr.add_edge(2, 4)
     gr.add_edge(4, 5)
     gr.add_edge(1, 5)
     gr.add_edge(3, 5)
     dotstr = dot.write(gr)
     self._check_nodes(gr, dotstr)
     self._check_arrows(gr, dotstr)
开发者ID:svn2github,项目名称:python-graph2,代码行数:12,代码来源:unittests-readwrite.py


示例19: testDigraphDFS

 def testDigraphDFS(self):
     G = pygraph.digraph()
     G.add_nodes([1, 2, 3, 4, 5, 6])
     G.add_edge(1, 2)
     G.add_edge(1, 3)
     G.add_edge(2, 4)
     G.add_edge(4, 3)
     G.add_edge(5, 1)
     G.add_edge(3, 5)
     G.add_edge(5, 6)
     st, pre, post = depth_first_search(G, 1, filter=filters.find(5))
     assert st == {1: None, 2: 1, 3: 4, 4: 2, 5: 3}
开发者ID:svn2github,项目名称:python-graph2,代码行数:12,代码来源:unittests-filters.py


示例20: __init__

    def __init__(self, connections):

        self.unmatchedChannels = False                    
        
        self.modules = {}
 
        for connection in connections:
            # give channels unit weight
            connection.activity = 1
            if (not connection.module_name in self.modules):
                # for now, type and name are the same
                if(DUMP_GRAPH_DEBUG):
                    print "Adding module, Found channel " + connection.name + " with module " + connection.module_name
                self.modules[connection.module_name] = LIModule(connection.module_name,\
                                                                connection.module_name)
       
            if (isinstance(connection, LIChannel)):
                self.modules[connection.module_name].addChannel(connection)
            else:
                self.modules[connection.module_name].addChain(connection)
 

        # let's match up all those connections
        self.matchGraphChannels()       

        # now that we have a dictionary, we can create a graph
        try:
            self.graph = pygraph.digraph() 
        except (NameError, AttributeError): 
            self.graph = digraph() 
      
        self.graph.add_nodes(self.modules.values())
        self.weights = {} # unfortunately pygraph does not support multiedges
    
        # add edges - for now all edges have unit weight
        for module in self.modules.values():
            for channel in module.channels:
                # depending on what we are doing with the graph,
                # unmatched channels may not be an error.  We will
                # instead mark the object in case the caller cares
                if (not (channel.matched or channel.optional)):
                    self.unmatchedChannels = True                    
                    continue
                # It is possible that optional channels do not have a match
                if (not channel.matched):
                    continue
                #Only add an edge if the channel is a source.
                if (channel.isSource()):
                    if (not self.graph.has_edge((module, channel.partnerModule))):
                        self.graph.add_edge((module, channel.partnerModule))
                        self.weights[(module, channel.partnerModule)] = channel.activity
                    else:
                        self.weights[(module, channel.partnerModule)] += channel.activity
开发者ID:HackLinux,项目名称:HAsim-RV32I,代码行数:53,代码来源:liGraph.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python cycles.find_cycle函数代码示例发布时间:2022-05-25
下一篇:
Python seqdb.SequenceFileDB类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap