(self, convert_dir, out_dir)
| 63 | ppi_zip.extractall(out_dir) |
| 64 | |
| 65 | def convert2json(self, convert_dir, out_dir): |
| 66 | prefix = os.path.join(convert_dir, 'ppi') |
| 67 | G, feats, id_map, walks, class_map = load_data(prefix) |
| 68 | out_test = open(self.id_file, 'w') |
| 69 | with open(out_dir, 'w') as out: |
| 70 | buf = {} |
| 71 | buf["nodes"] = [] |
| 72 | buf["edges"] = [] |
| 73 | for node_id in tqdm.tqdm(G.nodes()): |
| 74 | node_buf = {} |
| 75 | idx = id_map[node_id] |
| 76 | node_buf['id'] = idx |
| 77 | node_buf['type'] = get_node_type(G.node[node_id]) |
| 78 | if node_buf['type'] == 'test': |
| 79 | out_test.write(str(idx) + '\n') |
| 80 | node_buf['weight'] = len(G[node_id]) |
| 81 | node_buf['features'] = [{}, {}] |
| 82 | node_buf['features'][0]['name'] = 'label' |
| 83 | node_buf['features'][0]['type'] = 'dense' |
| 84 | node_buf['features'][0]['value'] = class_map[node_id] |
| 85 | node_buf['features'][1]['name'] = 'feature' |
| 86 | node_buf['features'][1]['type'] = 'dense' |
| 87 | node_buf['features'][1]['value'] = list(feats[idx]) |
| 88 | buf["nodes"].append(node_buf) |
| 89 | for dst_id in G[node_id]: |
| 90 | ebuf = {"src": idx, |
| 91 | "dst": id_map[dst_id], |
| 92 | "type": get_edge_type(G[node_id][dst_id]), |
| 93 | "weight": 1, |
| 94 | "features": [] |
| 95 | } |
| 96 | buf["edges"].append(ebuf) |
| 97 | out.write(json.dumps(buf)) |
| 98 | out_test.close() |
nothing calls this directly
no test coverage detected