{"id":17220824,"url":"https://github.com/kojix2/bio-twobit","last_synced_at":"2025-09-04T05:16:44.048Z","repository":{"id":45555140,"uuid":"436454379","full_name":"kojix2/bio-twobit","owner":"kojix2","description":"A ruby library for accessing 2bit files","archived":false,"fork":false,"pushed_at":"2025-08-01T14:25:50.000Z","size":531,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-09T19:59:59.316Z","etag":null,"topics":["bioinformatics","genome","genomics","ruby","twobit"],"latest_commit_sha":null,"homepage":"https://kojix2.github.io/bio-twobit/","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kojix2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","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,"zenodo":null},"funding":{"ko_fi":"kojix2"}},"created_at":"2021-12-09T02:14:11.000Z","updated_at":"2025-08-01T14:48:21.000Z","dependencies_parsed_at":"2024-10-15T03:53:28.401Z","dependency_job_id":"94ffe6de-45ce-4d2d-af4b-99c8ca974eff","html_url":"https://github.com/kojix2/bio-twobit","commit_stats":null,"previous_names":["kojix2/bio-twobit","ruby-on-bioc/bio-twobit"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/kojix2/bio-twobit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Fbio-twobit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Fbio-twobit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Fbio-twobit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Fbio-twobit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kojix2","download_url":"https://codeload.github.com/kojix2/bio-twobit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Fbio-twobit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273555459,"owners_count":25126316,"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","status":"online","status_checked_at":"2025-09-04T02:00:08.968Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","genome","genomics","ruby","twobit"],"created_at":"2024-10-15T03:53:20.205Z","updated_at":"2025-09-04T05:16:44.039Z","avatar_url":"https://github.com/kojix2.png","language":"Ruby","funding_links":["https://ko-fi.com/kojix2"],"categories":[],"sub_categories":[],"readme":"# bio-twobit\n\n[![Gem Version](https://badge.fury.io/rb/bio-twobit.svg)](https://badge.fury.io/rb/bio-twobit)\n[![test](https://github.com/kojix2/bio-twobit/actions/workflows/ci.yml/badge.svg)](https://github.com/kojix2/bio-twobit/actions/workflows/ci.yml)\n[![docs](https://img.shields.io/badge/docs-stable-blue.svg)](https://rubydoc.info/gems/bio-twobit)\n[![Lines of Code](https://img.shields.io/endpoint?url=https%3A%2F%2Ftokei.kojix2.net%2Fbadge%2Fgithub%2Fkojix2%2Fbio-twobit%2Flines)](https://tokei.kojix2.net/github/kojix2/bio-twobit)\n[![DOI](https://zenodo.org/badge/436454379.svg)](https://zenodo.org/badge/latestdoi/436454379)\n\nBio::TwoBit is a Ruby interface to 2bit files.\n\nRuby bindings to [lib2bit](https://github.com/dpryan79/lib2bit) / [py2bit](https://github.com/deeptools/py2bit).\n\n\n2bit files are used to store and index DNA sequences, usually of entire reference genomes. [The 2bit format](https://genome.ucsc.edu/goldenPath/help/twoBit.html) is a compact binary representation of DNA sequences that is used by the UCSC Genome Browser.\n\n## Installation\n\n```sh\ngem install bio-twobit\n```\n\nLinux and macOS are supported.\nWindows is currently not supported.\n\n### Usage\n\n```ruby\nrequire 'bio/twobit'\n\n# hg38 = Bio::TwoBit.open(\"hg38.2bit\")\nhg38 = Bio::TwoBit::Hg38.new\n\nhg38.path\n# \"hg38.2bit\"\n\nhg38.info\n# {\"file_size\"=\u003e818064875,\n# \"nChroms\"=\u003e640,\n# \"sequence_length\"=\u003e3272116950,\n# \"hard_masked_length\"=\u003e161368694,\n# \"soft_masked_length\"=\u003e0}\n\nhg38.chroms.take(5)\n# [[\"chr1\", 248956422],\n# [\"chr2\", 242193529],\n# [\"chr3\", 198295559],\n# [\"chr4\", 190214555],\n# [\"chr5\", 181538259]]\n```\n\nFetch a sequence\n\n```ruby\nhg38.sequence(\"chr1\", 50000, 50050)\n# \"AAACAGGTTAATCGCCACGACATAGTAGTATTTAGAGTTACTAGTAAGCC\" # length 50\n```\n\n* The first number is the **(0-based)** position on the chromosome/contig where the sequence should begin.\n* The second number is the **(1-based)** position on the chromosome where the sequence should end.\n\n```ruby\nhg38.bases(\"chr1\", 10000, 10100)\n# {\"A\"=\u003e0.34, \"C\"=\u003e0.49, \"T\"=\u003e0.17, \"G\"=\u003e0.0}\n\nhg38.bases(\"chr1\", 10000, 10100, fraction: false)\n# {\"A\"=\u003e34, \"C\"=\u003e49, \"T\"=\u003e17, \"G\"=\u003e0}\n\nhg38.bases(\"chr1\") \n# {\"A\"=\u003e0.26940569141052323,\n# \"C\"=\u003e0.19302592242428676,\n# \"T\"=\u003e0.2701041550155312,\n# \"G\"=\u003e0.19325280952182064}\n\nhg38.hard_masked_blocks(\"chr1\", 0, 1000000)\n# [[0, 10000], [207666, 257666], [297968, 347968], [535988, 585988]]\n```\n\nThe 2-bit file must be closed explicitly. Alternatively, you can use a block. Even if it is not closed, it will probably be closed by GC and there will be no problem. But this is not guaranteed.\n\n```ruby\n# Explicitly close the file.\ntb = Bio::TwoBit.open(\"test/fixtures/foo.2bit\")\ntb.close\n\n# You can also use blocks.\nBio::TwoBit.open(\"test/fixtures/foo.2bit\") do |t|\n  p t.info\nend\n```\n\n```ruby\ntb.closed? # true / false\n```\n\nIf you would like to include information about soft-masked bases, you need to specify `masked: true`\n\n```ruby\ntb = Bio::TwoBit.open(\"test/fixtures/foo.2bit\")\ntb.sequence(\"chr1\", 60, 72)\n# =\u003e \"GTAGCTAGCTGA\"\n\ntb = Bio::TwoBit.open(\"test/fixtures/foo.2bit\", masked: true)\ntb.sequence(\"chr1\", 60, 72)\n# =\u003e \"GTagctagctGA\"\ntb.soft_masked_blocks(\"chr1\")\n# =\u003e [[62, 70]]\n```\n\n```ruby\ntb.masked? # true / false\n```\n\n## hg19, hg38, hs1...\n\nSome reference genomes are provided as classes in advance. These classes automatically download 2bit files from the UCSC site into a cache directory upon first use.\n\n```ruby\nhg19 = Bio::TwoBit::Hg19.new\nhg38 = Bio::TwoBit::Hg38.new\nhs1  = Bio::TwoBit::Hs1.new\n```\n\nAdding a new reference genome is easy. Add the id of the genome you want to use [here](https://github.com/kojix2/bio-twobit/blob/main/lib/bio/twobit/references/template.erb). \n\n```\ngit clone https://github.com/kojix2/bio-twobit\nvi lib/bio/twobit/references/template.erb # Add your id to ids list.\nruby lib/bio/twobit/references/template.erb\nrake install\n```\n\nIf you want to use 2-bit files from locations other than UCSC, create your own classes [here](https://github.com/kojix2/bio-twobit/tree/main/lib/bio/twobit/references).\n\nPull requests are welcome.\n\n## Development\n\nBug reports and pull requests are welcome on GitHub at https://github.com/kojix2/bio-twobit.\n\n    Do you need commit rights to my repository?\n    Do you want to get admin rights and take over the project?\n    If so, please feel free to contact us @kojix2.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\nCode from [Red Datasets](https://github.com/red-data-tools/red-datasets) is used for automatic file download and caching. (The MIT license)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkojix2%2Fbio-twobit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkojix2%2Fbio-twobit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkojix2%2Fbio-twobit/lists"}