2020
2121class GraphBuilder :
2222 """
23- A class that builds and processes graphs constructed from SWC files.
23+ A class that builds graphs constructed from SWC files.
2424
2525 """
2626
@@ -31,6 +31,28 @@ def __init__(
3131 selected_ids = None ,
3232 use_anisotropy = True ,
3333 ):
34+ """
35+ Instantiates a GraphBuilder object.
36+
37+ Parameters
38+ ----------
39+ anisotropy : Tuple[int], optional
40+ Image to physical coordinates scaling factors to account for the
41+ anisotropy of the microscope. The default is [1.0, 1.0, 1.0].
42+ label_mask : ImageReader, optional
43+ Predicted segmentation mask.
44+ selected_ids : Set[int], optional
45+ Only SWC files with an swc_id contained in this set are read. The
46+ default is None.
47+ use_anisotropy : bool, optional
48+ Indication of whether to apply anisotropy to coordinates in SWC
49+ files. The default is True.
50+
51+ Returns
52+ -------
53+ None
54+
55+ """
3456 # Instance attributes
3557 self .anisotropy = anisotropy
3658 self .label_mask = label_mask
@@ -42,12 +64,45 @@ def __init__(
4264 )
4365
4466 def run (self , swc_pointer ):
67+ """
68+ Builds graphs by reading SWC files to extract content which is then
69+ loaded into a custom SkeletonGraph object. Optionally, the nodes are
70+ labeled if a "label_mask" is provided.
71+
72+ Parameters
73+ ----------
74+ swc_pointer : Any
75+ Object that points to SWC files to be read.
76+
77+ Returns
78+ -------
79+ dict
80+ A dictionary where the keys are unique identifiers (i.e. filenames
81+ of SWC files) and values are the correspondign SkeletonGraph.
82+
83+ """
4584 graphs = self ._build_graphs_from_swcs (swc_pointer )
4685 graphs = self ._label_graphs_with_segmentation (graphs )
4786 return graphs
4887
4988 # --- Build Graphs ---
5089 def _build_graphs_from_swcs (self , swc_pointer ):
90+ """
91+ Builds graphs by reading SWC files to extract content which is then
92+ loaded into a custom SkeletonGraph object.
93+
94+ Parameters
95+ ----------
96+ swc_pointer : Any
97+ Object that points to SWC files to be read.
98+
99+ Returns
100+ -------
101+ dict
102+ A dictionary where the keys are unique identifiers (i.e. filenames
103+ of SWC files) and values are the correspondign SkeletonGraph.
104+
105+ """
51106 # Initializations
52107 swc_dicts = self .swc_reader .read (swc_pointer )
53108 pbar = tqdm (total = len (swc_dicts ), desc = "Build Graphs" )
@@ -81,11 +136,12 @@ def to_graph(self, swc_dict):
81136 Parameters
82137 ----------
83138 swc_dict : dict
84- ...
139+ Dictionary whose keys and values are the attribute names and
140+ values from an SWC file.
85141
86142 Returns
87143 -------
88- networkx.Graph
144+ SkeletonGraph
89145 Graph built from an SWC file.
90146
91147 """
@@ -119,15 +175,18 @@ def _label_graph(self, key):
119175class LabelHandler :
120176 def __init__ (self , connections_path = None , valid_labels = None ):
121177 """
122- Initializes the label handler and builds the label mappings
123- if a connections path is provided.
178+ Initializes the label handler and builds the label mappings if a
179+ connections path is provided.
124180
125181 Parameters
126182 ----------
127183 connections_path : str, optional
128184 Path to a file containing pairs of segment ids that were merged.
185+ The default is None.
129186 valid_labels : Set[int], optional
130- Set of valid segment ids to be considered during processing.
187+ Segment IDs that can be assigned to nodes. This argument accounts
188+ for segments that were been removed due to some type of filtering.
189+ The default is None.
131190
132191 Returns
133192 -------
@@ -194,8 +253,8 @@ def build_labels_graph(self, connections_path):
194253 # Main
195254 for line in util .read_txt (connections_path ):
196255 ids = line .split ("," )
197- id_1 = get_segment_id (ids [0 ])
198- id_2 = get_segment_id (ids [1 ])
256+ id_1 = util . get_segment_id (ids [0 ])
257+ id_2 = util . get_segment_id (ids [1 ])
199258 labels_graph .add_edge (id_1 , id_2 )
200259 return labels_graph
201260
@@ -231,7 +290,3 @@ def count_splits(graph):
231290
232291 """
233292 return max (nx .number_connected_components (graph ) - 1 , 0 )
234-
235-
236- def get_segment_id (swc_id ):
237- return int (swc_id .split ("." )[0 ])
0 commit comments