@gmod/twobit
v6.0.5
Published
Read .2bit files in node or webpack
Readme
@gmod/twobit
Read .2bit sequence files, works in Node.js or the browser.
Install
$ npm install @gmod/twobitUsage
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()API
new TwoBitFile({ path?, filehandle? })
path— filesystem path to the .2bit filefilehandle— fs.promises-like filehandle; only needs to supportread(buffer, offset, length, position)
getSequenceNames() → Promise<string[]>
Returns all sequence names in the file.
getSequenceSizes() → Promise<Record<string, number>>
Returns all sequence lengths as { seqName: length, ... }.
Note: slow if there are many sequences — prefer a chrom.sizes file if available.
getSequenceSize(seqName) → Promise<number | undefined>
Returns the length of seqName, or undefined if not found.
getSequence(seqName, regionStart?, regionEnd?) → Promise<string | undefined>
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.
Publishing
Trusted publishing via GitHub Actions.
npm version patch # or minor/majorAcademic Use
This 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.
License
MIT © Robert Buels
