def get_input(): output_data_path, tree_input_path = get_data_paths_from_args(inputs=1) classification_config = parse_classification_config() trees: List[nx.Graph] = [] ignored_patients = get_ignored_patients() print(ignored_patients) for tree_path in Path(tree_input_path).glob("*/tree.graphml"): if tree_path.parent.name not in ignored_patients: trees.append(nx.read_graphml(tree_path)) return output_data_path, trees, classification_config
def get_input(): output_data_path, tree_input_path, render_path = get_data_paths_from_args( inputs=2) classification_config = parse_classification_config() for cc_dict in classification_config.values(): if "clustering_endnode" not in cc_dict: cc_dict["clustering_endnode"] = False trees: List[nx.Graph] = [] ignored_patients = get_ignored_patients() for tree_path in Path(tree_input_path).glob("*/tree.graphml"): if tree_path.parent.name not in ignored_patients: trees.append(nx.read_graphml(tree_path)) return output_data_path, trees, classification_config, render_path
def main(): output_path, trees, classification_config = get_input() ignored_patients = get_ignored_patients() clustering_endnodes = { name for name, config in classification_config.items() if config.get("clustering_endnode", False) } children: Dict[str, Set[str]] = { name: set(config.get("children", [])) & clustering_endnodes for name, config in classification_config.items() } print(len(clustering_endnodes), "segment-like nodes", clustering_endnodes) no_ignored = [] with_ignored = [] for index, tree_pair in enumerate(trees, 1): tree, tree_gt = tree_pair * 2 if len(tree_pair) == 1 else tree_pair # Ignore some nodes as otherwise segments may be counted twice (e.g.: LB7+8, LB7, and LB8) ignored_nodes: Set[str] = set() # print(f"\nPatient {tree.graph['patient']}") for node_id in tree_gt.nodes: node_gt = tree_gt.nodes[node_id] node = tree.nodes[node_id] sc = node["split_classification"] sc_gt = node_gt.get("split_classification_gt", "") if sc_gt == "": sc_gt = sc if sc_gt in clustering_endnodes and sc_gt not in ignored_nodes: ignored_nodes |= children.get(sc_gt, set()) correctly_classified = sc_gt == sc if str(tree.graph["patient"]) not in ignored_patients: no_ignored.append(correctly_classified) with_ignored.append(correctly_classified) def show_stats(lis: List[bool]): s = sum(lis) t = len(lis) print(f"{s}/{t} = {s/t:%}") no_ignored_count = len(trees) - len(ignored_patients) print(f"{t/no_ignored_count} segments per patient") print("Without ignored patients:") show_stats(no_ignored)
def main(): output_path, trees, classification_config, render_path = get_input() ignored_patients = get_ignored_patients() if sys.argv[4].lower() == "true": subprocess.Popen(["xdg-open", f"{output_path / f'{file_name}.pdf'}"]) sys.exit() clustering_end_nodes = [ c for c, k in classification_config.items() if "clustering_endnode" in k and k["clustering_endnode"] ] content = ["# Airway Auto-Generated Data Quality Evaluation\n"] for index, tree in enumerate(trees, 1): patient = str(tree.graph["patient"]) successors = dict(nx.bfs_successors(tree, "0")) img_path = Path(render_path) / patient / "bronchus0.png" content.append(f"![{patient}]({img_path})\n\n") formatting_if_ignored = "(ignored due to bad data)" if patient in ignored_patients else "" content.append( f"#### {index}. Patient {patient} {formatting_if_ignored}\n\n") total_cost = sum(tree.nodes[node_id]["cost"] for node_id in tree.nodes) content.append(f"Total cost: {total_cost:.2f}\n\n") content.append(f"Total nodes: {len(tree.nodes)}\n\n") is_valid = is_valid_tree(tree, classification_config, successors) content.append( f"Tree is **{'valid' if is_valid else 'invalid'}** (follows given rule-set)\n\n" ) classifications_in_tree = { tree.nodes[node_id]["split_classification"] for node_id in tree.nodes } missing_end_node = set(clustering_end_nodes) - classifications_in_tree content.append(f"Missing segments: {', '.join(missing_end_node)}\n\n") content.append("\n") generate_pdf_report(output_path, file_name, "".join(content))
def main(): output_path, trees, classification_config = get_input() ignored_patients = get_ignored_patients() encoding = { re.sub(r"^([RL])[a-z]+", r"\1", k): v for k, v in parse_array_encoding().items() } lobe_encoding = {k: v for k, v in encoding.items() if "Lobe" in k} decoding = dict(zip(encoding.values(), encoding.keys())) no_ignored = [] with_ignored = [] for index, tree in enumerate(trees, 1): for node_id in tree.nodes: node = tree.nodes[node_id] if node["split_classification"] in lobe_encoding: correctly_classified = node["lobe"] == encoding[ node["split_classification"]] if str(tree.graph["patient"]) not in ignored_patients: no_ignored.append(correctly_classified) if not correctly_classified: print(f"Patient {tree.graph['patient']}") print( f"Mistaken {decoding[node['lobe']]} (Synapse) for {node['split_classification']}\n" ) with_ignored.append(correctly_classified) def show_stats(lis: List[bool]): s = sum(lis) t = len(lis) print(f"{s}/{t} = {s / t:%}") print("Without ignored patients:") show_stats(no_ignored) print("With ignored patients:") show_stats(with_ignored)