Skip to content

Commit

Permalink
Add htsget demo to README and CHANGELOG
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Aug 19, 2020
1 parent 42992fb commit df82c90
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 36 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<a name="1.0.40"></a>
## [1.0.40](https://github.com/GMOD/bam-js/compare/v1.0.39...v1.0.40) (2020-07-30)
- Add htsget example
- Support opts object to getHeader allowing things like auth headers to be passed right off the bat

<a name="1.0.40"></a>

## [1.0.40](https://github.com/GMOD/bam-js/compare/v1.0.39...v1.0.40) (2020-07-30)

<a name="1.0.39"></a>
## [1.0.39](https://github.com/GMOD/bam-js/compare/v1.0.38...v1.0.39) (2020-07-30)


## [1.0.39](https://github.com/GMOD/bam-js/compare/v1.0.38...v1.0.39) (2020-07-30)

- Don't use origin master in the follow-tags postpublish command for cleaner version publishing

Expand Down
82 changes: 50 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
[![Build Status](https://img.shields.io/travis/GMOD/bam-js/master.svg?style=flat-square)](https://travis-ci.org/GMOD/bam-js)
[![Coverage Status](https://img.shields.io/codecov/c/github/GMOD/bam-js/master.svg?style=flat-square)](https://codecov.io/gh/GMOD/bam-js/branch/master)


## Install

$ npm install --save @gmod/bam

## Usage

```js
const {BamFile} = require('@gmod/bam'); // or import {BamFile} from '@gmod/bam'
const { BamFile } = require('@gmod/bam') // or import {BamFile} from '@gmod/bam'

const t = new BamFile({
bamPath: 'test.bam',
});
bamPath: 'test.bam',
})

var header = await t.getHeader()

Expand All @@ -25,62 +24,78 @@ var records = await t.getRecordsForRange('ctgA', 0, 49999)

Input are 0-based half-open coordinates (note: not the same as samtools view coordinate inputs!)

## Documentation
## Usage with htsget

Since 1.0.41 we support htsget!

### BAM constructor
Here is a small code snippet for this

```js
const { HtsgetFile } = require('@gmod/bam')

const ti = new HtsgetFile({
baseUrl: 'http://htsnexus.rnd.dnanex.us/v1/reads',
trackId: 'BroadHiSeqX_b37/NA12878',
})
await ti.getHeader()
const records = await ti.getRecordsForRange(1, 2000000, 2000001)
```

## Documentation

### BAM constructor

The BAM class constructor accepts arguments

* bamPath/baiUrl/bamFilehandle - a string file path to a local file or a class object with a read method
* csiPath/csiUrl/csiFilehandle - a CSI index for the BAM file, required for long chromosomes greater than 2^29 in length
* baiPath/baiUrl/baiFilehandle - a BAI index for the BAM file
* fetchSizeLimit - total size of the number of chunks being fetched at once. default: ~50MB
* chunkSizeLimit - size limit on any individual chunk. default: ~10MB
* cacheSize - limit on number of chunks to cache. default: 50
- bamPath/baiUrl/bamFilehandle - a string file path to a local file or a class object with a read method
- csiPath/csiUrl/csiFilehandle - a CSI index for the BAM file, required for long chromosomes greater than 2^29 in length
- baiPath/baiUrl/baiFilehandle - a BAI index for the BAM file
- fetchSizeLimit - total size of the number of chunks being fetched at once. default: ~50MB
- chunkSizeLimit - size limit on any individual chunk. default: ~10MB
- cacheSize - limit on number of chunks to cache. default: 50

Note: filehandles implement the Filehandle interface from https://www.npmjs.com/package/generic-filehandle. This module offers the path and url arguments as convenience methods for supplying the LocalFile and RemoteFile


### async getRecordsForRange(refName, start, end, opts)

* refName - a string for the chrom to fetch from
* start - a 0 based half open start coordinate
* end - a 0 based half open end coordinate
* opts.signal - an AbortSignal to indicate stop processing
* opts.viewAsPairs - re-dispatches requests to find mate pairs. default: false
* opts.pairAcrossChr - control the viewAsPairs option behavior to pair across chromosomes. default: false
* opts.maxInsertSize - control the viewAsPairs option behavior to limit distance within a chromosome to fetch. default: 200kb
- refName - a string for the chrom to fetch from
- start - a 0 based half open start coordinate
- end - a 0 based half open end coordinate
- opts.signal - an AbortSignal to indicate stop processing
- opts.viewAsPairs - re-dispatches requests to find mate pairs. default: false
- opts.pairAcrossChr - control the viewAsPairs option behavior to pair across chromosomes. default: false
- opts.maxInsertSize - control the viewAsPairs option behavior to limit distance within a chromosome to fetch. default: 200kb

### async \*streamRecordsForRange(refName, start, end, opts)

### async *streamRecordsForRange(refName, start, end, opts)

This is a async generator function that takes the same signature as getRecordsForRange but results can be processed using
This is a async generator function that takes the same signature as getRecordsForRange but results can be processed using

for await(const chunk of file.streamRecordsForRange(refName, start, end, opts)) {
}

The getRecordsForRange simply wraps this process by concatenating chunks into an array

### async getHeader(opts: {....anything to pass to generic-filehandle opts})

This obtains the header from HtsgetFile or BamFile. Retrieves BAM file and BAI/CSI header if applicable, or API request for refnames from htsget

### async indexCov(refName, start, end)

* refName - a string for the chrom to fetch from
* start - a 0 based half open start coordinate (optional)
* end - a 0 based half open end coordinate (optional)
- refName - a string for the chrom to fetch from
- start - a 0 based half open start coordinate (optional)
- end - a 0 based half open end coordinate (optional)

Returns features of the form {start, end, score} containing estimated feature density across 16kb windows in the genome


### async lineCount(refName)

* refName - a string for the chrom to fetch from
- refName - a string for the chrom to fetch from

Returns number of features on refName, uses special pseudo-bin from the BAI/CSI index (e.g. bin 37450 from bai, returning n_mapped from SAM spec pdf) or -1 if refName not exist in sample

### async hasRefSeq(refName)

* refName - a string for the chrom to check
- refName - a string for the chrom to check

Returns whether we have this refName in the sample

Expand Down Expand Up @@ -121,14 +136,17 @@ Example
BAM tags such as MD can be obtained via

feature.get('MD')

A full list of tags that can be obtained can be obtained via

feature._tags()



The feature format may change in future versions to be more raw data records, but this will be a major version bump

## License

MIT © [Colin Diesh](https://github.com/cmdcolin)

```
```

0 comments on commit df82c90

Please sign in to comment.