本文整理汇总了Python中igraph.Graph.summary方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.summary方法的具体用法?Python Graph.summary怎么用?Python Graph.summary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类igraph.Graph
的用法示例。
在下文中一共展示了Graph.summary方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plotTreeFromString
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import summary [as 别名]
def plotTreeFromString(treeString, colordict, plotFile):
"""
Plots a tree from the 'brackets tree' format
:param treeString:
:param colordict: defines the colors of the nodes by label (e.g. 1 to 5)
:param plotFile: output file (.png)
:return:
"""
g = Graph()
splitted = treeString.split("(")
level = -1
parents = dict()
parentIds = dict()
levelCount = dict()
for part in splitted:
if len(part)<1:
continue
else: #label follows
level+=1
count = levelCount.get(level,0)
levelCount[level] = count+1
#print "level %d" % level
label = part[0]
#print part.split()
if len(part.split())>1: #leaf node
label, wordPlusEnding = part.split()
#print part, "at leaf"
endings = wordPlusEnding.count(")")
word = wordPlusEnding.strip(")")
g.add_vertex(label=word, color=colordict[int(label)])
#print "added node %d" % (len(g.vs)-1)
currentNode = len(g.vs)-1
p = parents[level-1]
g.add_edge(currentNode,p)#add edge to parent
#print "added edge %d-%d" % (len(g.vs)-1, parentIds[level-1])
level-=endings
#print "word", word
else:
g.add_vertex(label=label, color=colordict[int(label)])
currentNode = g.vs[len(g.vs)-1]
#print "added node %d" % (len(g.vs)-1)
if level != 0:
p = parents[level-1]
g.add_edge(currentNode,p)#add edge to parent
#print "added edge %d-%d" % (len(g.vs)-1, parentIds[level-1])
parent = currentNode
parentId = len(g.vs)-1
parents[level] = parent
parentIds[level] = parentId
print parentIds
print g.summary()
layout = g.layout_reingold_tilford(mode="in", root=0)
plot(g, plotFile, layout=layout, bbox = (2000, 1000), margin = 100)
示例2: ReactDic
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import summary [as 别名]
#.........这里部分代码省略.........
for p in self.plst:
p.srlst = list(set(p.rlst))
for r in p.srlst:
#print r
#print r.__dict__
r.plst.append(p)
for prim in p.primlst:
for i in range(2):
for c in prim[i]:
if c not in p.sclst:
p.sclst.append(c)
c.cplst.append(p)
def create_dgraph(self):
""" initializes self.graph: the total directed graph of reactions. It ereases any preceding graph. """
self.dgraph = Graph(0,directed = True)
cnlst = []
rnlst = []
rlinks = []
for rct in self.rlst:
rnlst.append(rct.name)
for i in rct.innames:
cnlst.append(i)
rlinks.append((i,rct.name))
for o in rct.outnames:
cnlst.append(o)
rlinks.append((rct.name,o))
if rct.reversible == True:
rnlst.append(rct.name+'_r')
for o in rct.innames:
rlinks.append((rct.name+'_r',o))
for i in rct.outnames:
rlinks.append((i,rct.name+'_r'))
cnlst = list(set(cnlst))
cinpathlst = [self.gsearch(cn).inpath if self.gsearch(cn) != None else [] for cn in cnlst]
rnlst = list(set(rnlst))
rinpathlst = [self.rsearch(rn).inpath if '_r' not in rn else self.rsearch(rn[0:len(rn)-2]) for rn in rnlst]
cnlst.extend(rnlst)
cinpathlst.extend(rinpathlst)
self.dgraph.add_vertices(cnlst)
self.dgraph.add_edges(rlinks)
self.dgraph.vs['inpath'] = cinpathlst
#print rlinks[len(rlinks)-3000:len(rlinks)-1]
print self.dgraph.summary()
def create_pgraphs(self,filterlst):
""" create the graphs of all the pathways and initialize the corresponding variable """
for p in self.plst:
p.dependence(self)
print '\nprimgraph'
for p in self.plst:
p.create_primgraph(filterlst)
print '\ntotgraph\n'
for p in self.plst:
p.create_totgraph(filterlst)
def create_filterlst(self,threshold):
""" create a filtering list nlst containing all the vertex in dgraph that have a degree higher than threshold """
lst = []
nlst = []
for v in range(self.dgraph.vcount()):
if self.dgraph.degree(v) > threshold:
lst.append(v)
nlst.append(self.dgraph.vs['name'][v])
print 'NUMBER OF ELEMENTS TO FILTER: '+str(len(lst))
print nlst
return nlst
def stoichmat(self):
""" outputs the full stoichiometric matrix of the system """
smat = []
clst = []
rlst = []
rev = []
for r in self.rlst:
if r.nobalance == False:
if r.name not in rlst:
rlst.append(r.name)
rev.append(r.reversible)
else:
print 'error in STOICHMAT: reaction\t',r.name,'\talready present!'
for cname in union(r.innames[:],r.outnames[:]):
if cname not in clst:
clst.append(cname)
for r in self.rlst:
if r.nobalance == False:
#create the stoichiometric vector
rclst = r.innames[:]
rclst.extend(r.outnames[:])
sv = [r.slst[[i for i,b in enumerate(rclst) if b == cname][0]] if cname in rclst else 0 for cname in clst]
smat.append(sv)
return [smat,clst,rlst,rev]