{"id":13741151,"url":"https://github.com/brentp/hts-zig","last_synced_at":"2025-10-29T19:31:43.568Z","repository":{"id":46314493,"uuid":"420980731","full_name":"brentp/hts-zig","owner":"brentp","description":"ziglang + htslib","archived":false,"fork":false,"pushed_at":"2021-10-31T15:46:32.000Z","size":184,"stargazers_count":20,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-02T04:41:11.583Z","etag":null,"topics":["bioinformatics","genomics","hacktoberfest","htslib","zig","ziglang"],"latest_commit_sha":null,"homepage":"","language":"Zig","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":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-25T10:38:07.000Z","updated_at":"2024-12-06T02:22:40.000Z","dependencies_parsed_at":"2022-08-29T23:40:38.879Z","dependency_job_id":null,"html_url":"https://github.com/brentp/hts-zig","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brentp%2Fhts-zig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brentp%2Fhts-zig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brentp%2Fhts-zig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brentp%2Fhts-zig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brentp","download_url":"https://codeload.github.com/brentp/hts-zig/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238882480,"owners_count":19546527,"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":["bioinformatics","genomics","hacktoberfest","htslib","zig","ziglang"],"created_at":"2024-08-03T04:00:56.074Z","updated_at":"2025-10-29T19:31:43.273Z","avatar_url":"https://github.com/brentp.png","language":"Zig","funding_links":[],"categories":["Libraries"],"sub_categories":[],"readme":"[![Build](https://github.com/brentp/hts-zig/actions/workflows/build.yml/badge.svg)](https://github.com/brentp/hts-zig/actions/workflows/build.yml)\n\n# WIP [zig](https://ziglang.org) wrapper for [htslib](htslib.org) parsing of VCFs for genetic variants\n\nI wrote this learning zig so it probably has many non-ziggy usages.\nMost of the htslib VCF/Variant stuff is supported.\n\n# Usage\n\n\u003e :warning: `hts-zig` tries to allocate as little as possible, use\n\u003e `.dup()` on a variant if when it's necessary to keep it in memory.\n\n```zig\nconst vcf = @import(\"src/vcf.zig\")\nconst VCF = vcf.VCF\n\nconst allocator = std.testing.allocator;\n\nvar vcf = VCF.open(\"tests/test.snpeff.bcf\").?; // can return null\n// file and cleanup htslib memory at end of scope\ndefer vcf.deinit(); \nvar variant = vcf.next().?; // .? syntax gets an optional result.\ntry stdout.print(\"\\nvariant:{any}\\n\", .{variant}); // Variant(chr1:30859-30860 (G/C))\n\n// # get the AD field\n// # needs to allocate, this interface will likely change.\n// # extract the FORMAT/sample AD field (allelic depth)\n// # to get INFO, use get(vcf.Field.info, ...);\nvar fld = \"AD\";\nvar ads = std.ArrayList(i32).init(allocator)\ndefer ads.deinit();\ntry variant.get(vcf.Field.format, ads, fld);\n// 4 samples * 2\ntry stdout.print(\"\\nAD:{any}\\n\", .{ads.items}); // { 7, 0, 2, 0, 6, 0, 4, 0 }\n\n// # genotypes:\nvar gts_mem = std.ArrayList(i32).init(allocator); // can re-use this for each variant\ndefer gts_mem.deinit();\nvar gts = try variant.genotypes(\u0026gts_mem);\ntry stdout.print(\"\\ngts:{any}\\n\", .{gts});\n// # gts:[0/0/, 0/0/, 0/1/, 0/0/] (note trailing / is accurate as it's how it's stored in htslib)\n\n// # region queries\nvar iter = try ivcf.query(chrom, 69269, 69270);\nwhile (iter.next()) |v| {\n    try std.testing.expect(v.start() == 69269);\n}\n```\n\n# testing and dev\n\nThis will require `zig` and `htslib` installed.\n```\nzig build test\n```\nZig requires very little additional work to wrap a C library, but it is\ncurrently not able to access struct fields when the struct contains bitfields.\nFor this reason, we need to write functions to access fields in many htslib\nstructs. Those functions are [here](https://github.com/brentp/hts-zig/blob/main/src/htslib_struct_access.c)\n\n# TODO\n\n- [X] Add nice genotypes access methods/structs\n- [X] Add `vcf.query()` (currently only iteration from start of file is supported, not querying by genomic location.\n- [X] updating header.\n- [X] setting INFO fields.\n- [X] writing. currently everything is read-only.\n- [X] fewer allocations (pass ArrayList to functions).\n- [X] support querying vcf as well as bcf\n- [X] set_samples().\n- [ ] fix ergonomics and think about error and null return types.\n\n# Why?\n\nit's quite useful to learn a new language by writing something that\nI'll use every day. zig looks interesting and sane\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrentp%2Fhts-zig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrentp%2Fhts-zig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrentp%2Fhts-zig/lists"}