https://github.com/mhyfritz/k-mers
Enumerate k-mers of a given string.
https://github.com/mhyfritz/k-mers
dna genomics javascript k-mer nodejs string
Last synced: 7 months ago
JSON representation
Enumerate k-mers of a given string.
- Host: GitHub
- URL: https://github.com/mhyfritz/k-mers
- Owner: mhyfritz
- Created: 2017-10-16T18:52:04.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-11-11T06:30:53.000Z (almost 7 years ago)
- Last Synced: 2024-10-22T16:35:16.049Z (12 months ago)
- Topics: dna, genomics, javascript, k-mer, nodejs, string
- Language: JavaScript
- Homepage:
- Size: 66.4 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# k-mers
Enumerate [k-mers](https://en.wikipedia.org/wiki/K-mer)
of a given string.## Installation
```bash
npm install k-mers
```## Usage
```js
var kmers = require('k-mers')var s = 'foobar'
var k = 3// get list of 3-mers in one shot:
kmers(k, s).all() // [ 'foo', 'oob', 'oba', 'bar' ]// iterate over 3-mers:
iterKmers = kmers(k, s)
while (true) {
var kmer = iterKmers.next()
if (kmer.value === undefined) {
break
}
console.log(kmer)
}
// { value: 'foo', index: 0 }
// { value: 'oob', index: 1 }
// { value: 'oba', index: 2 }
// { value: 'bar', index: 3 }// (re)set iterator to given index
iterKmers.seek(2)
iterKmers.next() // { value: 'oba', index: 2 }
```