Python networkx.parse_adjlist() Examples
The following are 2
code examples of networkx.parse_adjlist().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
networkx
, or try the search function
.
Example #1
Source File: graph_reader.py From nmp_qc with MIT License | 5 votes |
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
Example #2
Source File: utils.py From Recycler with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)