Skip to content

Commit

Permalink
bug : parse swc
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-grim committed Jan 12, 2024
1 parent 27319f7 commit 1263793
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/deep_neurographs/graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 13 additions & 2 deletions src/deep_neurographs/intake.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -281,6 +281,8 @@ def build_neurograph(
):
# Extract irreducibles
irreducibles = dict()
"""
-- asynchronous --
with ProcessPoolExecutor() as executor:
# Assign Processes
processes = [None] * len(swc_dicts)
Expand All @@ -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()
Expand Down
12 changes: 6 additions & 6 deletions src/deep_neurographs/swc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 1263793

Please sign in to comment.