1.0.2 • Published 6 years ago

tribble-index v1.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

tribble-index

Generated with nod NPM version Build Status

Read htsjdk Tribble indexes (e.g. *.vcf.idx files) using pure JavaScript. Supports only Tribble version 3 linear indexes right now.

Install

$ npm install --save tribble-index

Usage

import fs from 'fs'
import read from 'tribble-index'
// or without ES6
var fs = require('fs')
var read = require('tribble-index').default.read

fs.readFile('path/to/data.vcf.idx', (err, buffer) => {
  const index = read(buffer);

  console.log(index.header)
  const blocks = index.getBlocks("ctgA",123000,456000)

  // can now use these blocks from the index to read the file
  // regions of interest
  fs.open('path/to/data.vcf', 'r', (err, fd) => {
    if (err) throw err
    blocks.forEach(({ length, offset }) => {
      const buffer = Buffer.alloc(length)
      fs.read(fd, buffer, 0, length, offset, (err, buffer) => {
        console.log('got file data', buffer)
      })
    })
    fs.close(fd, (err) => {
      if (err) throw err
    })
  })
})

API

Table of Contents

getBlocks

Get an array of { offset, length } objects describing regions of the indexed file containing data for the given range.

Parameters

  • refName string name of the reference sequence
  • start integer start coordinate of the range of interest
  • end integer end coordinate of the range of interest

hasRefSeq

Return true if the given reference sequence is present in the index, false otherwise

Parameters

Returns boolean

read

Parse the index from the given Buffer object. The buffer must contain the entire index.

Parameters

Returns (LinearIndex | IntervalTreeIndex) an index object supporting the getBlocks method

License

MIT © Robert Buels