annot-tsv
CLI tool from htslib (1.22.1) that annotates regions in a target file using overlapping regions from a source file. Supports column transfer, conditional matching, special annotations (count, fraction, base pairs), and grep-like filtering. Coordinates are 1-based and inclusive by default.
Quick Start
- Command:
annot-tsv -s source.txt -t target.txt -c chr,beg,end -f info:INFO > output.txt
- Local executable:
/home/vimalinx/miniforge3/envs/bio/bin/annot-tsv
- Full reference: See
references/help.md for complete options and examples
When To Use This Tool
- Transferring annotation columns from a source file to overlapping regions in a target file
- Filtering records by overlap (print matching lines or drop overlapping regions with
-x)
- Adding overlap statistics: count of overlapping regions (
cnt), fraction overlapped (frac), or base pairs overlapped (nbp)
- Conditional annotation transfer requiring matching values in specified columns (
-m)
Common Patterns
# 1) Transfer INFO from overlapping source regions into the target table
annot-tsv \
-s source.txt \
-t target.txt \
-c chr,beg,end \
-f info:INFO \
> output.txt
# 2) Require matching type/sample columns before annotation transfer
annot-tsv \
-s src.txt.gz \
-t tgt.txt.gz \
-c chr,beg,end \
-m type,sample \
-f info
# 3) Use grep-like overlap filtering instead of column transfer
annot-tsv \
-s source.txt \
-t target.txt \
-c chr,beg,end \
-x
Recommended Workflow
- Identify the chromosome, start, and end column names/indices in both source and target files
- Determine which columns to transfer (
-f) and any required match conditions (-m)
- Run a test annotation with a subset to verify column mapping and output format
- Execute the full annotation, redirecting stdout to output file or using
-o
Guardrails
- Coordinates are 1-based and inclusive by default; use
-C to specify different conventions (e.g., BED is 0-based start)
- Either source or target can be streamed from stdin, but not both simultaneously
- The
-x (drop overlaps) option is incompatible with -f (column transfer)
- Use
--help, not -h, for usage output. Here -h is the header-row option and requires an argument.
1---2name: annot-tsv3description: Use when you need to annotate regions in a target TSV/BED file with information from overlapping regions in a source file, transfer columns between files based on genomic overlap, or filter/drop overlapping records.4---5
6# annot-tsv
7
8CLI tool from htslib (1.22.1) that annotates regions in a target file using overlapping regions from a source file. Supports column transfer, conditional matching, special annotations (count, fraction, base pairs), and grep-like filtering. Coordinates are 1-based and inclusive by default.
9
10## Quick Start
11
12- **Command**: `annot-tsv -s source.txt -t target.txt -c chr,beg,end -f info:INFO > output.txt`
13- **Local executable**: `/home/vimalinx/miniforge3/envs/bio/bin/annot-tsv`
14- **Full reference**: See `references/help.md` for complete options and examples
15
16## When To Use This Tool
17
18- Transferring annotation columns from a source file to overlapping regions in a target file
19- Filtering records by overlap (print matching lines or drop overlapping regions with `-x`)
20- Adding overlap statistics: count of overlapping regions (`cnt`), fraction overlapped (`frac`), or base pairs overlapped (`nbp`)
21- Conditional annotation transfer requiring matching values in specified columns (`-m`)
22
23## Common Patterns
24
25```bash
26# 1) Transfer INFO from overlapping source regions into the target table
27annot-tsv \
28 -s source.txt \
29 -t target.txt \
30 -c chr,beg,end \
31 -f info:INFO \
32 > output.txt
33```
34
35```bash
36# 2) Require matching type/sample columns before annotation transfer
37annot-tsv \
38 -s src.txt.gz \
39 -t tgt.txt.gz \
40 -c chr,beg,end \
41 -m type,sample \
42 -f info
43```
44
45```bash
46# 3) Use grep-like overlap filtering instead of column transfer
47annot-tsv \
48 -s source.txt \
49 -t target.txt \
50 -c chr,beg,end \
51 -x
52```
53
54## Recommended Workflow
55
561. Identify the chromosome, start, and end column names/indices in both source and target files
572. Determine which columns to transfer (`-f`) and any required match conditions (`-m`)
583. Run a test annotation with a subset to verify column mapping and output format
594. Execute the full annotation, redirecting stdout to output file or using `-o`
60
61## Guardrails
62
63- Coordinates are 1-based and inclusive by default; use `-C` to specify different conventions (e.g., BED is 0-based start)
64- Either source or target can be streamed from stdin, but not both simultaneously
65- The `-x` (drop overlaps) option is incompatible with `-f` (column transfer)
66- Use `--help`, not `-h`, for usage output. Here `-h` is the header-row option and requires an argument.