Skip to content

Latest commit

 

History

History
99 lines (78 loc) · 4.32 KB

schemas.md

File metadata and controls

99 lines (78 loc) · 4.32 KB

Schemas

A BED line has no column names or types, so the parser needs a schema. The sections below give four ways to set one, in the order the constructor prefers them.

A supplied autoSql

Use an autoSql for a custom BED format, or for a bigBed that has its schema in the header:

import { BigBed } from '@gmod/bbi'

const bigbed = new BigBed({ path: 'yourfile.bb' })
const { autoSql } = await bigbed.getHeader()
const p = new BED({ autoSql })
p.parseLine(line)

The parser treats the autoSql as the whole layout, so it drops columns past the last field instead of returning them as extras.

A builtin type

const p = new BED({ type: 'bigGenePred' })
p.parseLine(
  'chr1\t11868\t14409\tENST00000456328.2\t1000\t+\t11868\t11868\t255,128,0\t3\t359,109,1189,\t0,744,1352,\tDDX11L1\tnone\tnone\t-1,-1,-1,\tnone\tENST00000456328.2\tDDX11L1\tnone',
)
// { chrom: 'chr1', chromStart: 11868, chromEnd: 14409,
//   name: 'ENST00000456328.2', score: 1000, strand: 1,
//   thickStart: 11868, thickEnd: 11868, reserved: '255,128,0',
//   blockCount: 3, blockSizes: [359, 109, 1189],
//   chromStarts: [0, 744, 1352], name2: 'DDX11L1',
//   cdsStartStat: 'none', cdsEndStat: 'none', exonFrames: [-1, -1, -1],
//   type: 'none', geneName: 'ENST00000456328.2', geneName2: 'DDX11L1',
//   geneType: 'none' }

Builtin types

type source
bigInteract interact.as
bigMaf bigMaf.as
bigPsl bigPsl.as
bigNarrowPeak bigNarrowPeak.as
bigGenePred bigGenePred.as
bigLink bigLink.as
bigChain bigChain.as
mafFrames kent's source tree — no goldenPath example page
mafSummary kent's source tree — no goldenPath example page

src/as/autoSqlSchemas.ts inlines the declarations, alongside defaultBedSchema, which lists the standard BED12 columns the parser falls back on. Each declaration parses on first use, so importing the package doesn't parse the schemas you never ask for.

Column names

A BED file with a header line names its columns but not their types, so each type comes from the standard column of the same name (chromStart is numeric, blockSizes a numeric array), and anything unrecognized stays a string.

const p = new BED({
  columnNames: ['chrom', 'chromStart', 'chromEnd', 'pValue'],
})
p.parseLine('chr1\t0\t100\t1e-4')
// { chrom: 'chr1', chromStart: 0, chromEnd: 100, pValue: '1e-4', strand: 0 }

The parser matches those names against the standard BED and bigGenePred columns, with BED winning where the two disagree. Like a supplied autoSql, the list is the whole layout.

No schema

new BED() uses the standard BED schema, but treats a line that doesn't look like BED12 as partly unknown rather than forcing the standard names onto it.

The autoSql parser

src/autoSql.ts is a hand-written parser that reads both the builtin schemas and any autoSql you supply. Besides the documented grammar, it accepts quoted field names, quoted and numeric enum/set values, unclosed comment quotes, name[size] as well as type[size], and comments before the declaration, all of which appear in real UCSC and ENCODE files. It also reads a whole declaration written on one line, and a field with no comment. CONTRIBUTING.md describes how we validate it.

References: