diff --git a/src/deep_neurographs/utils/swc_util.py b/src/deep_neurographs/utils/swc_util.py index 9bd55b4..1e64450 100644 --- a/src/deep_neurographs/utils/swc_util.py +++ b/src/deep_neurographs/utils/swc_util.py @@ -239,7 +239,7 @@ def load_from_cloud_zipped_file(self, zip_file, path): """ content = util.read_zip(zip_file, path).splitlines() - if len(content) > self.min_size: + if len(content) > self.min_size - 10: result = self.parse(content) result["swc_id"] = util.get_swc_id(path) return result diff --git a/src/deep_neurographs/utils/util.py b/src/deep_neurographs/utils/util.py index 1413c60..dba2176 100644 --- a/src/deep_neurographs/utils/util.py +++ b/src/deep_neurographs/utils/util.py @@ -10,6 +10,7 @@ import json import math +import networkx as nx import os import shutil from io import BytesIO @@ -21,6 +22,7 @@ import psutil from google.cloud import storage +from deep_neurographs.utils import graph_util as gutil, swc_util # --- os utils --- def mkdir(path, delete=False): @@ -477,10 +479,7 @@ def sample_once(my_container): sample """ - if type(my_container) is list: - return sample(my_container, 1)[0] - else: - return sample(list(my_container), 1)[0] + return sample(my_container, 1)[0] # --- dictionary utils --- @@ -540,6 +539,28 @@ def find_best(my_dict, maximize=True): # --- miscellaneous --- +def count_fragments(fragments_pointer, min_size=0): + """ + Counts the number of fragments in a given predicted segmentation. + + Parameters + ---------- + swc_pointer : dict, list, str + Object that points to swcs to be read, see class documentation for + details. + min_size : float, optional + + """ + # Extract fragments + graph_loader = gutil.GraphLoader(min_size=min_size, progress_bar=True) + graph = graph_loader.run(fragments_pointer) + + # Report results + print("# Connected Components:", nx.number_connected_components(graph)) + print("# Nodes:", graph.number_of_nodes()) + print("# Edges:", graph.number_of_edges()) + + def time_writer(t, unit="seconds"): """ Converts a runtime "t" to a larger unit of time if applicable.