Skip to content

Commit 4dc4b21

Browse files
Update vesicle pool visualization
1 parent fc7ca4d commit 4dc4b21

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

synapse_net/tools/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,14 @@ def pool_visualization_cli():
110110
"--vesicle_path", "-v", required=True, help="The filepath to the tif file containing the vesicle segmentation."
111111
)
112112
parser.add_argument(
113-
"--table_path", "-t", required=True, help="The filepath to the table with the vesicle pool assignments."
113+
"--table_paths", "-t", required=True, nargs="+",
114+
help="The filepath to the table with the vesicle pool assignments."
114115
)
115116
parser.add_argument(
116117
"-s", "--segmentation_paths", nargs="+", help="Filepaths for additional segmentations."
117118
)
118119
args = parser.parse_args()
119-
_visualize_vesicle_pools(args.input_path, args.vesicle_path, args.table_path, args.segmentation_paths)
120+
_visualize_vesicle_pools(args.input_path, args.vesicle_path, args.table_paths, args.segmentation_paths)
120121

121122

122123
# TODO: handle kwargs

synapse_net/tools/pool_visualization.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,29 @@ def _create_pools(vesicles, table):
1717
return pools, colormap
1818

1919

20-
def _visualize_vesicle_pools(input_path, vesicle_path, table_path, segmentation_paths):
20+
def _parse_tables(table_paths):
21+
def load_table(path):
22+
if path.endswith(".csv"):
23+
return pd.read_csv(path)
24+
elif path.endswith(".xlsx"):
25+
return pd.read_excel(path)
26+
else:
27+
raise RuntimeError("Unknown file ending.")
28+
29+
if len(table_paths) == 1:
30+
table = load_table(table_paths[0])
31+
else:
32+
table = []
33+
for table_path in table_paths:
34+
this_table = load_table(table_path)
35+
pool_name = Path(table_path).stem
36+
this_table["pool"] = [pool_name] * len(this_table)
37+
table.append(this_table)
38+
table = pd.concat(table)
39+
return table
40+
41+
42+
def _visualize_vesicle_pools(input_path, vesicle_path, table_paths, segmentation_paths):
2143
# Load the tomogram data, including scale information.
2244
data, voxel_size = read_mrc(input_path)
2345
axes = "zyx" if data.ndim == 3 else "yx"
@@ -27,9 +49,9 @@ def _visualize_vesicle_pools(input_path, vesicle_path, table_path, segmentation_
2749
# Load the vesicle layer.
2850
vesicles = imageio.imread(vesicle_path)
2951

30-
# Load the table with the pool assignments.
52+
# Load the tables with the pool assignments.
3153
# Create and add the pool layer.
32-
table = pd.read_excel(table_path)
54+
table = _parse_tables(table_paths)
3355
pools, colormap = _create_pools(vesicles, table)
3456

3557
viewer = napari.Viewer()

0 commit comments

Comments
 (0)