Skip to content

Repository files navigation

bed-js

Coverage Status Build Status

Parses BED lines into feature objects, using the file's autoSql schema when it has one. Includes a standalone autoSql parser and the UCSC bigBed schemas.

Install

npm install @gmod/bed

Usage

Feed the parser one line at a time:

import BED from '@gmod/bed'

const parser = new BED()
const features = text
  .split('\n')
  .filter(line => line.trim() && !/^(#|track|browser)/.test(line))
  .map(line => parser.parseLine(line))

parser.parseLine('chr1\t0\t100\tgene1\t50\t+')
// { chrom: 'chr1', chromStart: 0, chromEnd: 100, name: 'gene1',
//   score: 50, strand: 1 }

parseLine has no notion of header or comment lines — filter them out first, or they come back as features with NaN coordinates.

The lines can come from anywhere. A .bed.gz can be queried with @gmod/tabix, and a bigBed can be read with @gmod/bbi. If either file is remote, have that package read through a filehandle from @gmod/range-cache-filehandle, which caches the byte ranges it fetches.

A file whose first line names its columns can hand that line straight back as columnNames, instead of dropping it with the other # lines:

const [header, ...rest] = text.split('\n')
const parser = new BED({ columnNames: header.replace(/^#/, '').split('\t') })
rest.map(line => parser.parseLine(line))

Schemas

Four ways to tell the constructor how to name and type the columns:

new BED() // standard BED columns
new BED({ autoSql }) // an autoSql string, e.g. from a bigBed header
new BED({ type: 'bigGenePred' }) // a builtin UCSC schema
new BED({ columnNames }) // names from a '#chrom start end ...' header

Documentation

  • API — constructor, parseLine, exported types
  • Schemas — the builtin list, autoSql, column-name headers
  • Parsing behavior — strand, missing data, BED12+n, and what the parser guesses when there is no schema
  • Contributing — development and releases

Academic 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 © Colin Diesh

About

A parser for the BED format including autoSql support

Resources

Contributing

Stars

5 stars

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages