Read .2bit sequence files, works in Node.js or the browser.
$ npm install @gmod/twobit
import { TwoBitFile } from '@gmod/twobit'
const t = new TwoBitFile({ path: 'path/to/file.2bit' })
// coordinates are 0-based half-open
const region = await t.getSequence('chr1', 0, 10)
const fullSeq = await t.getSequence('chr1')
const sizes = await t.getSequenceSizes() // { seqName: length, ... }
const size = await t.getSequenceSize('chr1')
const names = await t.getSequenceNames()path— filesystem path to the .2bit filefilehandle— fs.promises-like filehandle; only needs to supportread(buffer, offset, length, position)
Returns all sequence names in the file.
Returns all sequence lengths as { seqName: length, ... }.
Note: slow if there are many sequences — prefer a chrom.sizes file if available.
Returns the length of seqName, or undefined if not found.
Returns sequence bases as a string, or undefined if seqName is not found. Coordinates are 0-based half-open. regionStart defaults to 0, regionEnd defaults to end of sequence.
Trusted publishing via GitHub Actions.
npm version patch # or minor/majorThis package was written with funding from the NHGRI as part of the JBrowse project. If you use it in an academic project that you publish, please cite the most recent JBrowse paper, which will be linked from jbrowse.org.
MIT © Robert Buels