本文整理匯總了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)