Skip to content

Commit

Permalink
Bunzip
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Feb 13, 2025
1 parent 71f1267 commit 4732f0a
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 843 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@
"biojs"
],
"dependencies": {
"@foxglove/wasm-bz2": "^0.1.1",
"bz2": "^1.0.1",
"bzip2": "^0.1.1",
"bzip2-wasm": "^1.0.1",
"crc": "^4.3.2",
"generic-filehandle2": "^1.0.0",
"md5": "^2.2.1",
"pako": "^1.0.4",
"quick-lru": "^4.0.1",
"seek-bzip": "^2.0.0",
"xz-decompress": "^0.2.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/cramFile/declare.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
declare module 'bz2'
declare module 'bzip2'
16 changes: 13 additions & 3 deletions src/cramFile/file.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { decompress } from 'bz2'
// import bzip2 from 'bzip2'
// import BZip2 from 'bzip2-wasm'
// import { decompress } from 'bz2'

import Bunzip from 'seek-bzip'

Check failure on line 5 in src/cramFile/file.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test on node 20.x and ubuntu-latest

There should be no empty line within import group

Check failure on line 5 in src/cramFile/file.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test on node 20.x and ubuntu-latest

`seek-bzip` import should occur after import of `quick-lru`

import crc32 from 'crc/calculators/crc32'
import QuickLRU from 'quick-lru'
import { XzReadableStream } from 'xz-decompress'
Expand Down Expand Up @@ -280,10 +285,15 @@ export default class CramFile {
inputBuffer: Uint8Array,
uncompressedSize: number,
) {
// console.log({ compressionMethod })
if (compressionMethod === 'gzip') {
return unzip(inputBuffer)
const ret = unzip(inputBuffer)
if (ret[0] === 24) {
// console.log(ret.slice(0, 500).join(','))
}
return ret
} else if (compressionMethod === 'bzip2') {
return decompress(inputBuffer)
return Bunzip.decode(inputBuffer)
} else if (compressionMethod === 'lzma') {
const decompressedResponse = new Response(
new XzReadableStream(bufferToStream(inputBuffer)),
Expand Down
11 changes: 11 additions & 0 deletions src/cramFile/slice/decodeRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import CramSlice, { SliceHeader } from './index'
import { CramFileBlock } from '../file'
import { isMappedSliceHeader } from '../sectionParsers'
let kk = 0

Check failure on line 16 in src/cramFile/slice/decodeRecord.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test on node 20.x and ubuntu-latest

'kk' is never reassigned. Use 'const' instead

Check warning on line 16 in src/cramFile/slice/decodeRecord.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test on node 20.x and ubuntu-latest

'kk' is assigned a value but never used

/**
* given a Buffer, read a string up to the first null character
Expand Down Expand Up @@ -371,6 +372,7 @@ export default function decodeRecord(

// mapping quality
mappingQuality = decodeDataSeries('MQ')!

if (CramFlagsDecoder.isPreservingQualityScores(cramFlags)) {
qualityScores = new Array(readLength)
for (let i = 0; i < qualityScores.length; i++) {
Expand Down Expand Up @@ -414,3 +416,12 @@ export default function decodeRecord(
tags,
}
}
function quals(quals: number[]) {

Check warning on line 419 in src/cramFile/slice/decodeRecord.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test on node 20.x and ubuntu-latest

'quals' is defined but never used
if (!quals || quals.length === 0) {

Check failure on line 420 in src/cramFile/slice/decodeRecord.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test on node 20.x and ubuntu-latest

Unnecessary conditional, value is always falsy
return '*'
}

return quals
.map(q => String.fromCharCode(Math.min(Math.max(q, 0), 93) + 33))
.join('')
}
17 changes: 3 additions & 14 deletions src/htscodecs/arith_gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import { decompress } from 'bz2'
import Bunzip from 'seek-bzip'

import RangeCoder from './arith_sh'
import ByteModel from './byte_model'
import IOStream from './iostream'
Expand Down Expand Up @@ -153,19 +154,7 @@ export default class RangeCoderGen {
// ----------------------------------------------------------------------
// External codec
decodeExt(stream, n_out) {
return decompress(stream.buf.slice(stream.pos))
// const bits = bzip2.array(stream.buf.slice(stream.pos))
// let size = bzip2.header(bits)
// let chunk
// const chunks = []
// do {
// chunk = bzip2.decompress(bits, size)
// if (chunk !== -1) {
// chunks.push(chunk)
// size -= chunk.length
// }
// } while (chunk !== -1)
// return concatUint8Array(chunks)
return Bunzip.decode(stream.buf.slice(stream.pos))
}

// ----------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 4732f0a

Please sign in to comment.