From 4d03434f738fdc514bf79de8d1c485789f0a324c Mon Sep 17 00:00:00 2001 From: Matt Mallory Date: Thu, 29 May 2025 10:09:12 -0700 Subject: [PATCH 1/2] fix: directly measure length in proj mat --- morph_utils/ccf.py | 54 +++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/morph_utils/ccf.py b/morph_utils/ccf.py index 79ea5dd..0c60d9e 100644 --- a/morph_utils/ccf.py +++ b/morph_utils/ccf.py @@ -294,9 +294,7 @@ def projection_matrix_for_swc(input_swc_file, mask_method = "tip_and_branch", resolution=10, node_type_list=[2], resample_spacing=None): """ - Given a swc file, quantify the projection matrix. That is the amount of axon in each structure. This function assumes - there is equivalent internode spacing (i.e. the input swc file should be resampled prior to running this code). - + Given a swc file, quantify the projection matrix. Args: input_swc_file (str): path to swc file @@ -334,6 +332,13 @@ def projection_matrix_for_swc(input_swc_file, mask_method = "tip_and_branch", if count_method not in ['node','tip','branch']: msg = f"count_method must be 'node','tip', or 'branch'. You passed in: {count_method}" raise ValueError(msg) + + if mask_method == 'None': + mask_method = None + + if mask_method not in [None,'tip_and_branch', 'branch', 'tip', 'tip_or_branch']: + raise ValueError(f"Invalid mask_method provided {mask_method}") + sg_df = load_structure_graph() name_map = NAME_MAP @@ -353,8 +358,6 @@ def projection_matrix_for_swc(input_swc_file, mask_method = "tip_and_branch", if resample_spacing is not None: morph = resample_morphology(morph, resample_spacing) - spacing = get_node_spacing(morph)[0] - morph_df = pd.DataFrame(morph.nodes()) # filter by axon/dend types @@ -386,21 +389,21 @@ def node_ider(morph,i): # determine ipsi/contra projections morph_df["ccf_structure_sided"] = morph_df.apply(lambda row: "ipsi_{}".format(row.ccf_structure) if row.z Date: Thu, 29 May 2025 10:13:48 -0700 Subject: [PATCH 2/2] doc updated --- morph_utils/ccf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/morph_utils/ccf.py b/morph_utils/ccf.py index 0c60d9e..dacf68a 100644 --- a/morph_utils/ccf.py +++ b/morph_utils/ccf.py @@ -302,7 +302,7 @@ def projection_matrix_for_swc(input_swc_file, mask_method = "tip_and_branch", 'tip_and_branch' will return a projection matrix masking only structures with tip and branch nodes. If 'tip' will only look at structures with tip nodes. And last, if 'branch' will only look at structures with branch nodes. - count_method (str): ['node','tip','branch']. When 'node', will measure axon length by multiplying by internode spacing. + count_method (str): ['node','tip','branch']. When 'node', will measure axon length directly. Otherwise will return the count of tip or branch nodes in each structure annotation (array, optional): 3 dimensional ccf annotation array. Defaults to None. annotation_path (str, optional): path to nrrd file to use (optional). Defaults to None.