Skip to content

Commit 298140e

Browse files
committed
rename option. support (b)gzipped input
1 parent cf3d9d0 commit 298140e

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,36 @@
22

33
[![badge](https://img.shields.io/badge/docs-latest-blue.svg)](https://brentp.github.io/libbigwig-nim/bigwig.html)
44

5+
## Command Line
6+
7+
bigwig-nim includes a command-line tool distributed as a static binary. It supports converting
8+
bed to bigwig and bigwig to bed and extracting stats (mean, coverage, etc) for regions in a bigwig.
9+
10+
There are other tools to do this, including [kentTools](https://hgwdev.gi.ucsc.edu/~kent/src/) which has a more restrictive license and does not supported (b)gzipped input and [bwtools](https://github.com/CRG-Barcelona/bwtool) which seems to provide similar functionality (but I am not able to build it).
11+
12+
13+
### view
14+
15+
To convert a bed with the value in the 4th column to bigwig, use:
16+
17+
```Shell
18+
bigwig view $bed_in --value-column 4 --chrom-sizes $fai -O bigwig -o $bigwig_out
19+
```
20+
`bigwig` will automatically determine the best data format for each block (fixed span and step or per-base) most of the
21+
CPU time is spent parsing the input bed file.
22+
23+
### stats
24+
25+
To get the mean value for a given region (in this case on chromosome 22)
26+
27+
```Shell
28+
bigwig stats --stat mean $bigwig 22:145000-155000
29+
```
30+
31+
The supported stats are `mean`, `min`, `max`, `coverage`, `sum` with a special-case for the stat of `header` which
32+
shows the chromosomes, lengths and mean coverages for each chromosome in the bigwig file.
33+
34+
535
## Reading
636

737
```Nim

bigwig.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ license = "MIT"
1818

1919
# Dependencies
2020

21-
requires "nimbigwig", "argparse"
21+
requires "nimbigwig", "argparse", "hts >= 0.2.20"
2222
srcDir = "src"
2323
installExt = @["nim"]
2424

src/bigwigpkg/cli.nim

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import strutils
22
import tables
33
import strformat
44
import ./lib
5+
import hts/files
56
import argparse
67

78
type region = tuple[chrom: string, start: int, stop: int]
@@ -54,8 +55,7 @@ iterator chunks(bed_path: string, chrom: var string, n:int=2048, value_column: i
5455
let col = value_column - 1
5556

5657
var cache = newSeqOfCap[tuple[start: int, stop:int, value:float32]](n)
57-
# TODO: support gzipped as well.
58-
for l in bed_path.lines:
58+
for l in bed_path.hts_lines:
5959
let toks = l.strip.split('\t')
6060
if toks[0] != chrom and cache.len > 0:
6161
yield cache
@@ -215,7 +215,7 @@ proc view_main*() =
215215

216216
var p = newParser("bigwig view"):
217217
option("-r", "--region", help="optional chromosome, or chrom:start-stop region to view")
218-
option("-f", "--fai", help="path to fai, only used for converting BED->BigWig")
218+
option("-c", "--chrom-sizes", help="file indicating chromosome sizes (can be .fai), only used for converting BED->BigWig")
219219
option("-i", "--value-column", help="column-number (1-based) of the value to encode in to BigWig, only used for encoding BED->BigWig", default="4")
220220
option("-O", "--output-fmt", choices= @["bed", "bigwig"], default="bed", help="output format")
221221
option("-o", "--output-file", default="/dev/stdout", help="output bed or bigwig file")
@@ -283,11 +283,11 @@ proc view_main*() =
283283
ofh.close
284284
bw.close
285285
else:
286-
if opts.fai == "":
287-
quit "[bigwig] --fai is required when input is not bigwig."
286+
if opts.chrom_sizes == "":
287+
quit "[bigwig] --chrom-sizes is required when input is not bigwig."
288288
if opts.region != "":
289289
quit "[bigwig] --region is not supported for BED input"
290-
var h = opts.fai.from_fai
290+
var h = opts.chrom_sizes.from_fai
291291
var ofh: BigWig
292292
if not ofh.open(opts.output_file, fmWrite):
293293
quit "[bigwig] couldn't open output bigwig file:" & opts.output_file

0 commit comments

Comments
 (0)