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