dna-data-compessor is a tiny library, it can quick convert (and compress) DNA sequences data (string data type in javascript) to binary data and vice versa. It can provide maximum level of DNA data compression (we suppose that allocation of nucleotides is random).
This can be useful for data transfering or fast data analysis of DNA sequences.
So, every nucleotide is encoded by 2 bytes (UTF-16), in some cases - 1 byte (ASCII, UTF-8).
But, actualy, we need just two bits to encode one nucleotide. For example:
A - 00
C - 01
G - 10
T - 11
By this way, we can compress DNA sequences data in 4-8 times.
In order to use dna-data-compressor on a webpage, download dna-compressor.js from the web folder of this repository and include it in a script, like so (assuming it is in the same directory as your page):
<script src="dna-compressor.js"></script>
And use it, like so:
<script>
const compressor = new Compressor();
<script>
You can use dna-data-compressor in your node project. Download dna-data-compressor.umd.js from the dist folder of this repository. Then include it in your script:
const compressor = require('../path/dna-data-compressor.umd');
// Some DNA sequence
const sequence = 'ATTGGTACGACTGCAGCTGCATATTATAATGATCGATCGATCGTAC'
// Compress string to binary data (ArrayBuffer)
const buffer = compressor.sequenceToBinaryData(sequence);
// Decompess binary data to string
const decompressed = compressor.binaryDataToSequence(buffer);
npm test
: Run simple test (test folder)
The tool was created by Serhii Silov. Contact e-mail: [email protected]