本文整理汇总了Python中networkx.parse_adjlist方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.parse_adjlist方法的具体用法?Python networkx.parse_adjlist怎么用?Python networkx.parse_adjlist使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx
的用法示例。
在下文中一共展示了networkx.parse_adjlist方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_graph_enzymes
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import parse_adjlist [as 别名]
def create_graph_enzymes(file):
f = open(file, 'r')
lines = f.read().splitlines()
f.close()
# get the indices of the vertext, adj list and class
idx_vertex = lines.index("#v - vertex labels")
idx_adj_list = lines.index("#a - adjacency list")
idx_clss = lines.index("#c - Class")
# node label
vl = [int(ivl) for ivl in lines[idx_vertex+1:idx_adj_list]]
adj_list = lines[idx_adj_list+1:idx_clss]
sources = list(range(1,len(adj_list)+1))
for i in range(len(adj_list)):
if not adj_list[i]:
adj_list[i] = str(sources[i])
else:
adj_list[i] = str(sources[i])+","+adj_list[i]
g = nx.parse_adjlist(adj_list, nodetype=int, delimiter=",")
for i in range(1, g.number_of_nodes()+1):
g.node[i]['labels'] = np.array(vl[i-1])
c = int(lines[idx_clss+1])
return g, c
示例2: get_fastg_digraph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import parse_adjlist [as 别名]
def get_fastg_digraph(fastg_name):
""" scans through fastg headers as an adjacency list
builds and returns a nx directed graph using adjacencies
note: no connections are created between each node and its
rc node - we need to take care to maintain these
"""
lines = []
fp = open(fastg_name, 'r')
for name,seq,qual in readfq(fp):
name = re.sub('[:,]'," ", name[:-1])
lines.append(name)
G = nx.DiGraph()
return nx.parse_adjlist(lines, create_using=G)