From 12637931373aa4cd5a77619256bd3cbb87f0ad98 Mon Sep 17 00:00:00 2001 From: anna-grim Date: Fri, 12 Jan 2024 04:42:25 +0000 Subject: [PATCH] bug : parse swc --- src/deep_neurographs/graph_utils.py | 1 + src/deep_neurographs/intake.py | 15 +++++++++++++-- src/deep_neurographs/swc_utils.py | 12 ++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/deep_neurographs/graph_utils.py b/src/deep_neurographs/graph_utils.py index d82c084..3ad9e21 100644 --- a/src/deep_neurographs/graph_utils.py +++ b/src/deep_neurographs/graph_utils.py @@ -65,6 +65,7 @@ def get_irreducibles(swc_dict, swc_id=None, prune=True, depth=16, smooth=True): # Extract irreducibles leafs, junctions = get_irreducible_nodes(dense_graph) + assert len(leafs) > 0, "Error: swc with no leaf nodes!" source = sample(leafs, 1)[0] root = None edges = dict() diff --git a/src/deep_neurographs/intake.py b/src/deep_neurographs/intake.py index 989c33e..8f9e5b8 100644 --- a/src/deep_neurographs/intake.py +++ b/src/deep_neurographs/intake.py @@ -28,10 +28,10 @@ N_PROPOSALS_PER_LEAF = 3 OPTIMIZE_PROPOSALS = False OPTIMIZATION_DEPTH = 15 -PRUNE = True +PRUNE = False PRUNE_DEPTH = 16 SEARCH_RADIUS = 0 -MIN_SIZE = 30 +MIN_SIZE = 35 SMOOTH = True @@ -281,6 +281,8 @@ def build_neurograph( ): # Extract irreducibles irreducibles = dict() + """ + -- asynchronous -- with ProcessPoolExecutor() as executor: # Assign Processes processes = [None] * len(swc_dicts) @@ -296,6 +298,15 @@ def build_neurograph( for process in as_completed(processes): process_id, result = process.result() irreducibles[process_id] = result + """ + for key in swc_dicts.keys(): + _, irreducibles[key] = gutils.get_irreducibles( + swc_dicts[key], + swc_id=key, + prune=prune, + depth=prune_depth, + smooth=smooth + ) # Build neurograph t0 = time() diff --git a/src/deep_neurographs/swc_utils.py b/src/deep_neurographs/swc_utils.py index a234808..ea58f94 100644 --- a/src/deep_neurographs/swc_utils.py +++ b/src/deep_neurographs/swc_utils.py @@ -21,15 +21,15 @@ def process_local_paths(paths, min_size, bbox=None): swc_dicts = dict() for path in paths: - swc_id = utils.get_swc_id(path) - swc_dicts[swc_id] = parse_local_swc(path, bbox=bbox) + swc_dicts.update(parse_local_swc(path, bbox=bbox, min_size=min_size)) return swc_dicts -def parse_local_swc(path, bbox=None, min_size=0): +def parse_local_swc(path, bbox=None, min_size=25): + swc_id = utils.get_swc_id(path) swc_contents = read_from_local(path) - parse_bool = len(swc_contents) > min_size - return parse(swc_contents, bbox=bbox) if parse_bool else [] + swc_dict = parse(swc_contents, bbox=bbox) + return {swc_id: swc_dict} if len(swc_dict["id"]) > min_size else dict() def parse_gcs_zip(zip_file, path, min_size=0): @@ -61,7 +61,7 @@ def parse(swc_contents, bbox=None): if line.startswith("# OFFSET"): parts = line.split() offset = read_xyz(parts[2:5]) - if not line.startswith("#") and len(line) > 0: + if not line.startswith("#"): parts = line.split() xyz = read_xyz(parts[2:5], offset=offset) if bbox: