Skip to content

Commit 6b0d36f

Browse files
authored
Merge pull request #48 from KumarLabJax/task/improve-merged-bout-table-naming
Improve the naming functionality of Merge Behavior Tables code
2 parents 7e076d7 + 8d8db93 commit 6b0d36f

File tree

6 files changed

+19
-15
lines changed

6 files changed

+19
-15
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "jabs-postprocess"
3-
version = "0.4.1"
3+
version = "0.4.2"
44
description = "A python library for JABS postprocessing utilities."
55
readme = "README.md"
66
license = "LicenseRef-PLATFORM-LICENSE-AGREEMENT-FOR-NON-COMMERCIAL-USE"

src/jabs_postprocess/cli/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,9 @@ def merge_multiple_tables(
539539
typer.Option(help="File pattern to match behavior tables"),
540540
] = "*.csv",
541541
output_prefix: Annotated[
542-
str,
542+
Optional[str],
543543
typer.Option(help="File prefix for merged output tables"),
544-
] = "merged_behavior",
544+
] = None,
545545
overwrite: Annotated[bool, typer.Option(help="Overwrites output files")] = False,
546546
):
547547
"""Merge multiple sets of behavior tables, automatically grouping by behavior.

src/jabs_postprocess/generate_behavior_tables.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ def process_multiple_behaviors(
121121

122122
def merge_behavior_tables(
123123
input_tables: List[Path],
124-
output_prefix: str = "merged_behavior",
124+
output_prefix: str | None = None,
125125
overwrite: bool = False,
126126
) -> Tuple[str, str]:
127127
"""Merge multiple behavior tables for the same behavior.
128128
129129
Args:
130130
input_tables: List of paths to behavior table files to merge
131-
output_prefix: Prefix for output filenames
131+
output_prefix: Optional prefix for output filenames
132132
overwrite: Whether to overwrite existing files
133133
134134
Returns:
@@ -174,13 +174,17 @@ def merge_behavior_tables(
174174

175175
tables.append(table)
176176

177+
output_file = behavior_name.replace(" ", "_").lower()
178+
if output_prefix:
179+
output_file = f"{output_prefix}_{output_file}"
180+
177181
# Merge the tables using the existing combine_data method
178182
if table_type == "bout":
179183
merged_table = BoutTable.combine_data(tables)
180-
output_file = f"{output_prefix}_{behavior_name}_bouts_merged.csv"
184+
output_file = f"{output_file}_bouts_merged.csv"
181185
else:
182186
merged_table = BinTable.combine_data(tables)
183-
output_file = f"{output_prefix}_{behavior_name}_summaries_merged.csv"
187+
output_file = f"{output_file}_summaries_merged.csv"
184188

185189
# Write the merged table
186190
merged_table.to_file(output_file, overwrite)
@@ -193,14 +197,14 @@ def merge_behavior_tables(
193197

194198
def merge_multiple_behavior_tables(
195199
table_groups: Dict[str, List[Path]],
196-
output_prefix: str = "merged_behavior",
200+
output_prefix: str | None = None,
197201
overwrite: bool = False,
198202
) -> Dict[str, Tuple[str, str]]:
199203
"""Merge multiple sets of behavior tables grouped by behavior.
200204
201205
Args:
202206
table_groups: Dictionary mapping behavior names to lists of table file paths
203-
output_prefix: Prefix for output filenames
207+
output_prefix: Optional prefix for output filenames
204208
overwrite: Whether to overwrite existing files
205209
206210
Returns:
@@ -238,15 +242,13 @@ def merge_multiple_behavior_tables(
238242
bout_output = None
239243
if bout_tables:
240244
bout_output, _ = merge_behavior_tables(
241-
bout_tables, f"{output_prefix}_{behavior_name}_bouts", overwrite
245+
bout_tables, output_prefix, overwrite
242246
)
243247

244248
# Merge bin tables if any exist
245249
bin_output = None
246250
if bin_tables:
247-
bin_output, _ = merge_behavior_tables(
248-
bin_tables, f"{output_prefix}_{behavior_name}_summaries", overwrite
249-
)
251+
bin_output, _ = merge_behavior_tables(bin_tables, output_prefix, overwrite)
250252

251253
results[behavior_name] = (bout_output, bin_output)
252254

tests/cli/test_merge_multiple_tables.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ def mock_csv_reader(file_path, nrows=None):
7474
"merge-multiple-tables",
7575
"--table-folder",
7676
str(table_folder),
77+
"--output-prefix",
78+
"merged_behavior",
7779
]
7880

7981
if overwrite:

tests/test_generate_behavior_tables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ def read_csv_side_effect(path, **kwargs):
749749

750750
# Mock merge_behavior_tables to return expected outputs
751751
def merge_side_effect(tables, prefix, overwrite):
752-
behavior = prefix.split("_")[1]
752+
behavior = prefix.split("_")[0]
753753
return f"merged_{behavior}_output.csv", f"merged_{behavior}_output.csv"
754754

755755
mock_merge.side_effect = merge_side_effect

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)