group-by
Quick Start
- Command:
groupBy -i <file> -g <cols> -c <cols> -o <ops>
- Local executable:
/home/vimalinx/miniforge3/envs/bio/bin/groupBy
- Full reference: See
references/help.md
When To Use This Tool
- Summarize tabular outputs by shared key columns, similar to SQL
GROUP BY.
- Collapse many overlap rows into per-feature counts, sums, means, or distinct value lists.
- Aggregate one or more columns with operations like
sum, count, mean, collapse, distinct, concat, first, and last.
- Post-process interval joins and annotation tables into compact summaries.
Common Patterns
# 1) Sum a numeric column per genomic feature
groupBy \
-i overlaps.tsv \
-g 1,2,3,4 \
-c 9 \
-o sum
# 2) Apply multiple operations to the same column
groupBy \
-i overlaps.tsv \
-g 1,2,3,4 \
-c 9,9 \
-o sum,max
# 3) Collapse IDs and compute the mean score per group from stdin
cat overlaps.tsv | groupBy \
-g 1,2,3,4 \
-c 8,9 \
-o collapse,mean
Recommended Workflow
- Decide which columns define the grouping key and make sure the input is already sorted/grouped by those columns.
- Choose the summarized column list with
-c and the corresponding aggregation operations with -o.
- Run the aggregation on a file or via stdin, using
-header / -inheader / -outheader when headers are present.
- Tune
-prec, -delim, or -full only when the downstream consumer needs those specific output conventions.
Guardrails
-c is required; without it, bedtools does not know which column(s) to aggregate.
- The input must already be sorted/grouped by the
-g columns, or identical groups will be split across multiple output rows.
- Column numbers are 1-based.
- If you supply multiple columns and multiple operations, the counts must either match or one side must have length 1 so bedtools can broadcast it.
-full keeps non-group columns from the first row in each group, which can be misleading if later rows in the same group differ.
1---2name: group-by3description: Use when you need to summarize tabular data by grouping rows on common column values and applying aggregation operations (sum, count, mean, etc.), similar to SQL GROUP BY.4---5
6# group-by
7
8## Quick Start
9- **Command**: `groupBy -i <file> -g <cols> -c <cols> -o <ops>`
10- **Local executable**: `/home/vimalinx/miniforge3/envs/bio/bin/groupBy`
11- **Full reference**: See `references/help.md`
12
13## When To Use This Tool
14
15- Summarize tabular outputs by shared key columns, similar to SQL `GROUP BY`.
16- Collapse many overlap rows into per-feature counts, sums, means, or distinct value lists.
17- Aggregate one or more columns with operations like `sum`, `count`, `mean`, `collapse`, `distinct`, `concat`, `first`, and `last`.
18- Post-process interval joins and annotation tables into compact summaries.
19
20## Common Patterns
21
22```bash
23# 1) Sum a numeric column per genomic feature
24groupBy \
25 -i overlaps.tsv \
26 -g 1,2,3,4 \
27 -c 9 \
28 -o sum
29```
30
31```bash
32# 2) Apply multiple operations to the same column
33groupBy \
34 -i overlaps.tsv \
35 -g 1,2,3,4 \
36 -c 9,9 \
37 -o sum,max
38```
39
40```bash
41# 3) Collapse IDs and compute the mean score per group from stdin
42cat overlaps.tsv | groupBy \
43 -g 1,2,3,4 \
44 -c 8,9 \
45 -o collapse,mean
46```
47
48## Recommended Workflow
49
501. Decide which columns define the grouping key and make sure the input is already sorted/grouped by those columns.
512. Choose the summarized column list with `-c` and the corresponding aggregation operations with `-o`.
523. Run the aggregation on a file or via stdin, using `-header` / `-inheader` / `-outheader` when headers are present.
534. Tune `-prec`, `-delim`, or `-full` only when the downstream consumer needs those specific output conventions.
54
55## Guardrails
56
57- `-c` is required; without it, bedtools does not know which column(s) to aggregate.
58- The input must already be sorted/grouped by the `-g` columns, or identical groups will be split across multiple output rows.
59- Column numbers are 1-based.
60- If you supply multiple columns and multiple operations, the counts must either match or one side must have length 1 so bedtools can broadcast it.
61- `-full` keeps non-group columns from the first row in each group, which can be misleading if later rows in the same group differ.