Induce a subgraph from labeled nodes. All edges in the induced graph have at least one labeled node. Parameters: graph_file (str): graph file label_file (str): label file save_file (str): save file
(self, graph_file, label_file, save_file)
| 270 | fout.write("%s\t%s\n" % (node, label)) |
| 271 | |
| 272 | def induced_graph(self, graph_file, label_file, save_file): |
| 273 | """ |
| 274 | Induce a subgraph from labeled nodes. All edges in the induced graph have at least one labeled node. |
| 275 | |
| 276 | Parameters: |
| 277 | graph_file (str): graph file |
| 278 | label_file (str): label file |
| 279 | save_file (str): save file |
| 280 | """ |
| 281 | logger.info("extracting subgraph of %s induced by %s to %s" % |
| 282 | (self.relpath(graph_file), self.relpath(label_file), self.relpath(save_file))) |
| 283 | nodes = set() |
| 284 | with open(label_file, "r") as fin: |
| 285 | for line in fin: |
| 286 | nodes.update(line.split()) |
| 287 | with open(graph_file, "r") as fin, open(save_file, "w") as fout: |
| 288 | for line in fin: |
| 289 | if not line.startswith("#"): |
| 290 | u, v = line.split() |
| 291 | if u not in nodes or v not in nodes: |
| 292 | continue |
| 293 | fout.write("%s\t%s\n" % (u, v)) |
| 294 | |
| 295 | def edge_split(self, graph_file, files, portions): |
| 296 | """ |
no test coverage detected