Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Dec 14, 2024
1 parent 9864902 commit fcc7549
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 206 deletions.
9 changes: 8 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ import tseslint from 'typescript-eslint'

export default tseslint.config(
{
ignores: ['esm/**/*', 'dist/**/*', '*.js', '*.mjs', 'example/*'],
ignores: [
'esm/**/*',
'dist/**/*',
'*.js',
'*.mjs',
'example/*',
'src/htscodecs',
],
},
{
languageOptions: {
Expand Down
5 changes: 3 additions & 2 deletions src/cramFile/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import QuickLRU from 'quick-lru'
import { XzReadableStream } from 'xz-decompress'

import { CramMalformedError, CramUnimplementedError } from '../errors'
import htscodecs from '../htscodecs'
import * as htscodecs from '../htscodecs'
import { open } from '../io'
import ransuncompress from '../rans'
import { parseHeaderText } from '../sam'
import { unzip } from '../unzip'
import { concatUint8Array } from '../util'
import CramContainer from './container'
import CramRecord from './record'
import {
Expand All @@ -17,7 +18,7 @@ import {
cramFileDefinition,
getSectionParsers,
} from './sectionParsers'
import { concatUint8Array, parseItem, tinyMemoize } from './util'
import { parseItem, tinyMemoize } from './util'

import type { GenericFilehandle } from 'generic-filehandle2'

Expand Down
17 changes: 0 additions & 17 deletions src/cramFile/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,3 @@ export function tinyMemoize(_class: any, methodName: any) {
export function sequenceMD5(seq: string) {
return md5(seq.toUpperCase().replaceAll(/[^\u0021-\u007e]/g, ''))
}

export function sum(array: Uint8Array[]) {
let sum = 0
for (const entry of array) {
sum += entry.length
}
return sum
}
export function concatUint8Array(args: Uint8Array[]) {
const mergedArray = new Uint8Array(sum(args))
let offset = 0
for (const entry of args) {
mergedArray.set(entry, offset)
offset += entry.length
}
return mergedArray
}
26 changes: 7 additions & 19 deletions src/htscodecs/arith_gen.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable no-var */
// @ts-nocheck

/*
* Copyright (c) 2019,2020 Genome Research Ltd.
* Author(s): James Bonfield
Expand Down Expand Up @@ -36,23 +39,7 @@ import bzip2 from 'bzip2'
import RangeCoder from './arith_sh'
import ByteModel from './byte_model'
import IOStream from './iostream'

function sum(array) {
let sum = 0
for (const entry of array) {
sum += entry.length
}
return sum
}
function concatUint8Array(args) {
const mergedArray = new Uint8Array(sum(args))
let offset = 0
for (const entry of args) {
mergedArray.set(entry, offset)
offset += entry.length
}
return mergedArray
}
import { concatUint8Array } from '../util'

const ARITH_ORDER = 1
const ARITH_EXT = 4
Expand All @@ -63,12 +50,13 @@ const ARITH_RLE = 64
const ARITH_PACK = 128

export default class RangeCoderGen {
decode(src) {
stream: IOStream
decode(src: Uint8Array) {
this.stream = new IOStream(src)
return this.decodeStream(this.stream)
}

decodeStream(stream, n_out = 0) {
decodeStream(stream: IOStream, n_out = 0) {
const flags = this.stream.ReadByte()
if (!(flags & ARITH_NOSIZE)) {
n_out = this.stream.ReadUint7()
Expand Down
2 changes: 2 additions & 0 deletions src/htscodecs/arith_sh.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-nocheck

/*
* Copyright (c) 2019 Genome Research Ltd.
* Author(s): James Bonfield
Expand Down
3 changes: 3 additions & 0 deletions src/htscodecs/byte_model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable no-var */
// @ts-nocheck

/*
* Copyright (c) 2019 Genome Research Ltd.
* Author(s): James Bonfield
Expand Down
9 changes: 5 additions & 4 deletions src/htscodecs/fqzcomp.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable no-var */
// @ts-nocheck

/*
* Copyright (c) 2019 Genome Research Ltd.
* Author(s): James Bonfield
Expand Down Expand Up @@ -293,7 +296,7 @@ function decode_fqz_new_record(src, rc, gparams, model, state, rev) {
state.rec++
}

function decode_fqz(src, q_lens) {
function decode_fqz(src: IOStream, q_lens: number) {
// Decode parameter block
const n_out = src.ReadUint7()
const gparams = decode_fqz_params(src)
Expand Down Expand Up @@ -384,10 +387,8 @@ function reverse_qualities(qual, qual_len, rev, len) {
}
}

export function decode(src, q_lens) {
export function decode(src: Uint8Array, q_lens) {
const stream = new IOStream(src)

// var n_out = stream.ReadUint32(); stream.ReadUint32(); // move to main

return decode_fqz(stream, q_lens)
}
20 changes: 7 additions & 13 deletions src/htscodecs/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-nocheck
//
/*
* Copyright (c) 2020 Genome Research Ltd.
* Author(s): James Bonfield
Expand Down Expand Up @@ -43,35 +45,27 @@ import * as r4x8 from './rans'
import * as r4x16 from './rans4x16'
import * as tok3 from './tok3'

function r4x8_uncompress(inputBuffer, outputBuffer) {
export function r4x8_uncompress(inputBuffer: Uint8Array) {
return r4x8.decode(inputBuffer)
}

function r4x16_uncompress(inputBuffer) {
export function r4x16_uncompress(inputBuffer: Uint8Array) {
return r4x16.decode(inputBuffer)
}

function arith_uncompress(inputBuffer) {
export function arith_uncompress(inputBuffer: Uint8Array) {
// fix by @cmdcolin for CRAM 3.1
// xref https://github.com/jkbonfield/htscodecs/pull/1/files
return new arith().decode(inputBuffer)
}

function fqzcomp_uncompress(inputBuffer) {
export function fqzcomp_uncompress(inputBuffer: Uint8Array) {
const q_lens = []
return fqzcomp.decode(inputBuffer, q_lens)
}

function tok3_uncompress(inputBuffer) {
export function tok3_uncompress(inputBuffer: Uint8Array) {
// Returns in string form instead of buffer
const out = tok3.decode(inputBuffer, 0, '\0')
return Uint8Array.from(Array.from(out).map(letter => letter.charCodeAt(0)))
}

module.exports = {
arith_uncompress: arith_uncompress,
fqzcomp_uncompress: fqzcomp_uncompress,
r4x16_uncompress: r4x16_uncompress,
r4x8_uncompress: r4x8_uncompress,
tok3_uncompress: tok3_uncompress,
}
Loading

0 comments on commit fcc7549

Please sign in to comment.