Skip to content

Commit

Permalink
Fix Hi-C rendering for some high resolution files (#4319)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Mar 28, 2024
1 parent 68e4a36 commit 9789c42
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions plugins/hic/src/HicAdapter/HicAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,23 @@ interface HicOptions extends BaseOptions {
bpPerPx?: number
}

// wraps generic-filehandle so the read function only takes a position and length
// in some ways, generic-filehandle wishes it was just this but it has
// wraps generic-filehandle so the read function only takes a position and
// length in some ways, generic-filehandle wishes it was just this but it has
// to adapt to the node.js fs promises API
class GenericFilehandleWrapper {
constructor(private filehandle: GenericFilehandle) {}

async read(position: number, length: number) {
const { buffer: b, bytesRead } = await this.filehandle.read(
Buffer.allocUnsafe(length),
const { buffer } = await this.filehandle.read(
Buffer.alloc(length),
0,
length,
position,
)
// xref https://stackoverflow.com/a/31394257/2129219
return b.buffer.slice(b.byteOffset, b.byteOffset + bytesRead)
return buffer.buffer.slice(
buffer.byteOffset,
buffer.byteOffset + buffer.byteLength,
)
}
}
export function openFilehandleWrapper(
Expand Down
2 changes: 1 addition & 1 deletion plugins/hic/src/HicRenderer/HicRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export default class HicRenderer extends ServerSideRendererType {

const w = res / (bpPerPx * Math.sqrt(2))
const baseColor = colord(readConfObject(config, 'baseColor'))
const offset = region.start
if (features.length) {
const offset = features[0].bin1
let maxScore = 0
let minBin = 0
let maxBin = 0
Expand Down

0 comments on commit 9789c42

Please sign in to comment.