{"id":16618539,"url":"https://github.com/brentp/bigwig-nim","last_synced_at":"2025-09-10T21:32:33.302Z","repository":{"id":66472159,"uuid":"199888356","full_name":"brentp/bigwig-nim","owner":"brentp","description":"command-line querying+conversion of bigwigs and a nim wrapper for dpryan's libbigwig","archived":false,"fork":false,"pushed_at":"2020-05-02T00:11:49.000Z","size":189,"stargazers_count":16,"open_issues_count":4,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T04:10:02.937Z","etag":null,"topics":["bigbed","bigwig","genomics","high-throughput-sequencing","nim","nim-lang"],"latest_commit_sha":null,"homepage":"","language":"Nim","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brentp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-31T16:03:04.000Z","updated_at":"2024-04-29T20:50:13.000Z","dependencies_parsed_at":"2023-02-22T12:30:50.126Z","dependency_job_id":null,"html_url":"https://github.com/brentp/bigwig-nim","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brentp%2Fbigwig-nim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brentp%2Fbigwig-nim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brentp%2Fbigwig-nim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brentp%2Fbigwig-nim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brentp","download_url":"https://codeload.github.com/brentp/bigwig-nim/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248819404,"owners_count":21166477,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bigbed","bigwig","genomics","high-throughput-sequencing","nim","nim-lang"],"created_at":"2024-10-12T02:20:36.447Z","updated_at":"2025-04-14T04:10:10.512Z","avatar_url":"https://github.com/brentp.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bigwig for nim\n\n[![Build Status](https://travis-ci.com/brentp/bigwig-nim.svg?branch=master)](https://travis-ci.com/brentp/bigwig-nim)\n[![badge](https://img.shields.io/badge/docs-latest-blue.svg)](https://brentp.github.io/bigwig-nim/lib.html)\n\n## Command Line\n\nbigwig-nim includes a command-line tool distributed as a static binary [here](https://github.com/brentp/bigwig-nim/releases/latest).\nIt supports converting bed to bigwig and bigwig to bed and extracting stats (mean, coverage, etc) for regions in a bigwig.\n\nThere 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).\n\n\n### view \n\nTo convert a bed with the value in the 4th column to bigwig, use:\n\n```Shell\nbigwig view $bed_in --value-column 4 --chrom-sizes $fai -O bigwig -o $bigwig_out\n```\n`bigwig` will automatically determine the best data format for each block (fixed span and step or per-base) most of the\nCPU time is spent parsing the input bed file.\n\n### stats\n\nTo get the mean value for a given region (in this case on chromosome 22)\n\n```Shell\nbigwig stats --stat mean $bigwig 22:145000-155000\n# or a bed file or regions\nbigwig stats --stat mean $bigwig $bed\n```\n\nOutput is tab-delimited `chrom`, `start`, `stop`, `stat` for each row in the bed (or just once for the region).\n\nThe supported stats are `mean`, `min`, `max`, `coverage`, `sum` with a special-case for the stat of `header` which\nshows the chromosomes, lengths and mean coverages for each chromosome in the bigwig file.\n\n\n## Reading\n\n```Nim\nvar bw: BigWig\nbw.open(path, fmRead)\n\n# avoid allocating when possible\nvar values: seq[float32]\nbw.values(values, \"chr1\", 0, 2222)\n\nfor iv in bw.intervals(\"chr2\", 999, 88888): # iterator.\n  # tuple[start: int, stop: int, value: float32]\n\n# for bigbed\nfor iv in bw.entries(\"chr2\", 999, 88888): # iterator.\n  # tuple[start: int, stop: int, value: cstring]\n  # value contains \"SQL\" for bigbed entry.\n\n# single value\nvar m: seq[float32] = bw.stats(\"chr2\", 999, 9999, stat=Stat.mean)\n\n# multiple bins:\nvar L: seq[float32] = bw.stats(\"chr2\", 999, 9999, stat=Stat.min, nBins=10)\n\necho bw.header # @[(name: \"1\", length: 195471971, tid: 0'u32), (name: \"10\", length: 130694993, tid: 1'u32)]\n\nbw.close\n```\n\n## Writing\n\n```Nim\nvar wtr:BigWig\ndoAssert wtr.open(\"tests/writer.bw\", fmWrite)\nwtr.setHeader(@[(name:\"chr1\", length: 2000, tid: 0'u32)])\nwtr.writeHeader\n\n# add intervals with tuples\nwtr.add(\"chr1\", @[(start: 22, stop: 33, value: 0.01'f32), (start: 44, stop: 55, value: 155'f32)])\n\n# or with, for example a span of 15 bases:\nwtr.add(\"chr1\", 15, @[(start: 20, value: 0.01'f32), (start: 30, value: 155'f32)])\n\n# or an array of values with a given span and step:\nvar values = @[0.1'f32, 0.2, 0.3, 0.4]\nwtr.add(\"chr1\", 100, values, span=100, step=200) # 100-200 is 0.1, 300-400 is 0.2 ...\nwtr.close()\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrentp%2Fbigwig-nim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrentp%2Fbigwig-nim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrentp%2Fbigwig-nim/lists"}