Skip to content

Commit df82c90

Browse files
committed
Add htsget demo to README and CHANGELOG
1 parent 42992fb commit df82c90

File tree

2 files changed

+55
-36
lines changed

2 files changed

+55
-36
lines changed

CHANGELOG.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
<a name="1.0.40"></a>
2-
## [1.0.40](https://github.com/GMOD/bam-js/compare/v1.0.39...v1.0.40) (2020-07-30)
1+
- Add htsget example
2+
- Support opts object to getHeader allowing things like auth headers to be passed right off the bat
33

4+
<a name="1.0.40"></a>
45

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

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

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

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

README.md

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
[![Build Status](https://img.shields.io/travis/GMOD/bam-js/master.svg?style=flat-square)](https://travis-ci.org/GMOD/bam-js)
44
[![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)
55

6-
76
## Install
87

98
$ npm install --save @gmod/bam
109

1110
## Usage
1211

1312
```js
14-
const {BamFile} = require('@gmod/bam'); // or import {BamFile} from '@gmod/bam'
13+
const { BamFile } = require('@gmod/bam') // or import {BamFile} from '@gmod/bam'
1514

1615
const t = new BamFile({
17-
bamPath: 'test.bam',
18-
});
16+
bamPath: 'test.bam',
17+
})
1918

2019
var header = await t.getHeader()
2120

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

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

28-
## Documentation
27+
## Usage with htsget
2928

29+
Since 1.0.41 we support htsget!
3030

31-
### BAM constructor
31+
Here is a small code snippet for this
32+
33+
```js
34+
const { HtsgetFile } = require('@gmod/bam')
35+
36+
const ti = new HtsgetFile({
37+
baseUrl: 'http://htsnexus.rnd.dnanex.us/v1/reads',
38+
trackId: 'BroadHiSeqX_b37/NA12878',
39+
})
40+
await ti.getHeader()
41+
const records = await ti.getRecordsForRange(1, 2000000, 2000001)
42+
```
3243

44+
## Documentation
45+
46+
### BAM constructor
3347

3448
The BAM class constructor accepts arguments
3549

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

4357
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
4458

45-
4659
### async getRecordsForRange(refName, start, end, opts)
4760

48-
* refName - a string for the chrom to fetch from
49-
* start - a 0 based half open start coordinate
50-
* end - a 0 based half open end coordinate
51-
* opts.signal - an AbortSignal to indicate stop processing
52-
* opts.viewAsPairs - re-dispatches requests to find mate pairs. default: false
53-
* opts.pairAcrossChr - control the viewAsPairs option behavior to pair across chromosomes. default: false
54-
* opts.maxInsertSize - control the viewAsPairs option behavior to limit distance within a chromosome to fetch. default: 200kb
61+
- refName - a string for the chrom to fetch from
62+
- start - a 0 based half open start coordinate
63+
- end - a 0 based half open end coordinate
64+
- opts.signal - an AbortSignal to indicate stop processing
65+
- opts.viewAsPairs - re-dispatches requests to find mate pairs. default: false
66+
- opts.pairAcrossChr - control the viewAsPairs option behavior to pair across chromosomes. default: false
67+
- opts.maxInsertSize - control the viewAsPairs option behavior to limit distance within a chromosome to fetch. default: 200kb
5568

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

57-
### async *streamRecordsForRange(refName, start, end, opts)
58-
59-
This is a async generator function that takes the same signature as getRecordsForRange but results can be processed using
71+
This is a async generator function that takes the same signature as getRecordsForRange but results can be processed using
6072

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

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

78+
### async getHeader(opts: {....anything to pass to generic-filehandle opts})
79+
80+
This obtains the header from HtsgetFile or BamFile. Retrieves BAM file and BAI/CSI header if applicable, or API request for refnames from htsget
81+
6682
### async indexCov(refName, start, end)
6783

68-
* refName - a string for the chrom to fetch from
69-
* start - a 0 based half open start coordinate (optional)
70-
* end - a 0 based half open end coordinate (optional)
84+
- refName - a string for the chrom to fetch from
85+
- start - a 0 based half open start coordinate (optional)
86+
- end - a 0 based half open end coordinate (optional)
7187

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

74-
7590
### async lineCount(refName)
7691

77-
* refName - a string for the chrom to fetch from
92+
- refName - a string for the chrom to fetch from
7893

7994
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
8095

8196
### async hasRefSeq(refName)
8297

83-
* refName - a string for the chrom to check
98+
- refName - a string for the chrom to check
8499

85100
Returns whether we have this refName in the sample
86101

@@ -121,14 +136,17 @@ Example
121136
BAM tags such as MD can be obtained via
122137

123138
feature.get('MD')
124-
139+
125140
A full list of tags that can be obtained can be obtained via
126141

127142
feature._tags()
128-
129-
143+
130144
The feature format may change in future versions to be more raw data records, but this will be a major version bump
131145

132146
## License
133147

134148
MIT © [Colin Diesh](https://github.com/cmdcolin)
149+
150+
```
151+
152+
```

0 commit comments

Comments
 (0)