@@ -101,4 +101,57 @@ process BEHAVIOR_TABLE_TO_FEATURES {
101101 """
102102 Rscript ${ params.support_code_dir} behavior_summaries.R -f ${ in_summary_table} -b ${ bin_size} -o "${ in_summary_table.baseName} _features_${ bin_size} .csv"
103103 """
104+ }
105+
106+ /* *
107+ * Aggregate bout tables by behavior across all videos.
108+ *
109+ * This process uses jabs-postprocess to merge tables by behavior,
110+ * creating separate merged files for each behavior detected.
111+ *
112+ * @param bout_tables List of paths to bout tables to be merged.
113+ *
114+ * @return merged_bout_tables List of paths to merged bout tables, one per behavior.
115+ * @return merge_log Path to the log file detailing the merge process.
116+ */
117+ process AGGREGATE_BOUT_TABLES {
118+ label " jabs_table_convert"
119+ label " r_jabs_table_convert"
120+
121+ publishDir " ${ params.outdir} /merged_behavior_tables" , mode: ' copy'
122+
123+ input:
124+ path bout_tables
125+
126+ output:
127+ path(" merged_*_bouts_merged.csv" ), emit: merged_bout_tables
128+ path(" merge_log.txt" ), emit: merge_log
129+
130+ script:
131+ """
132+ # Create a temporary directory for organizing tables
133+ mkdir -p table_staging
134+
135+ # Copy all bout tables to staging directory
136+ for table in ${ bout_tables} ; do
137+ cp "\$ {table}" table_staging/
138+ done
139+
140+ # Use jabs-postprocess to merge tables by behavior
141+ # This will automatically detect behaviors and create separate merged files for each
142+ echo "Starting behavior table merging..." > merge_log.txt
143+ echo "Input tables found:" >> merge_log.txt
144+ ls table_staging/*.csv >> merge_log.txt
145+
146+ uv run python -m jabs_postprocess.cli.main merge-multiple-tables \\
147+ --table-folder table_staging \\
148+ --table-pattern "*_bouts.csv" \\
149+ --output-prefix merged \\
150+ --overwrite \\
151+ 2>&1 | tee -a merge_log.txt
152+
153+ # Log completion
154+ echo "Merge completed. Output files:" >> merge_log.txt
155+ ls merged_*_bouts_merged.csv >> merge_log.txt 2>/dev/null || echo "No merged files generated" >> merge_log.txt
156+ """
104157}
0 commit comments