Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Nov 8, 2024
2 parents 3074136 + 5e6c181 commit 4a88867
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 10 deletions.
16 changes: 7 additions & 9 deletions src/cramFile/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,8 @@ export default class CramFile {
return parseHeaderText('')
}
const content = firstBlock.content
// find the end of the trailing zeros in the header text
const headerLength = content.readInt32LE(0)
const textStart = 4
// let textEnd = content.length - 1
// while (textEnd >= textStart && !content[textEnd]) textEnd -= 1
// trim off the trailing zeros
const text = content.toString('utf8', textStart, textStart + headerLength)
this.header = text
return parseHeaderText(text)
Expand Down Expand Up @@ -189,7 +185,8 @@ export default class CramFile {
position = block._endPosition
}
} else {
// otherwise, just traverse to the next container using the container's length
// otherwise, just traverse to the next container using the container's
// length
position += currentHeader._size + currentHeader.length
}
}
Expand Down Expand Up @@ -230,9 +227,9 @@ export default class CramFile {
if (!currentHeader) {
break
}
// if this is the first container, read all the blocks in the
// container, because we cannot trust the container
// header's given length due to a bug somewhere in htslib
// if this is the first container, read all the blocks in the container,
// because we cannot trust the container header's given length due to a
// bug somewhere in htslib
if (containerCount === 0) {
position = currentHeader._endPosition
for (let j = 0; j < currentHeader.numBlocks; j++) {
Expand All @@ -243,7 +240,8 @@ export default class CramFile {
position = block._endPosition
}
} else {
// otherwise, just traverse to the next container using the container's length
// otherwise, just traverse to the next container using the container's
// length
position += currentHeader._size + currentHeader.length
}
containerCount += 1
Expand Down
Binary file added test/data/hts-specs/3.1/passed/level-1.cram
Binary file not shown.
Binary file added test/data/hts-specs/3.1/passed/level-2.cram
Binary file not shown.
Binary file added test/data/hts-specs/3.1/passed/level-3.cram
Binary file not shown.
Binary file added test/data/hts-specs/3.1/passed/level-4.cram
Binary file not shown.
25 changes: 25 additions & 0 deletions test/dump3.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// @ts-nocheck
import { test } from 'vitest'
import { t3 as testFileList } from './lib/testFileList'
import { testDataFile } from './lib/util'
import { dumpWholeFile } from './lib/dumpFile'
import { CramFile } from '../src/index'
import { FetchableSmallFasta } from './lib/fasta'

testFileList.forEach(filename => {
test(`can dump the whole ${filename} without error`, async () => {
let seqFetch
if (filename.includes('#')) {
const referenceFileName = filename.replace(/#.+$/, '.fa')
const fasta = new FetchableSmallFasta(testDataFile(referenceFileName))
seqFetch = fasta.fetch.bind(fasta)
}

const filehandle = testDataFile(filename)
const file = new CramFile({
filehandle,
seqFetch,
})
await dumpWholeFile(file) // just try to decode it, no snapshot test for now as it is large
}, 10000)
})
13 changes: 12 additions & 1 deletion test/lib/testFileList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,15 @@ ML_test.cram
.split(/\s+/)
.filter(f => !!f)

export { t1, t2 }
const t3 = `
hts-specs/0902_comp_bz2.cram
hts-specs/0903_comp_lzma.cram
hts-specs/3.1/passed/level-3.cram
hts-specs/3.1/passed/level-4.cram
hts-specs/3.1/passed/level-1.cram
hts-specs/3.1/passed/level-2.cram
`
.split(/\s+/)
.filter(f => !!f)

export { t1, t2, t3 }

0 comments on commit 4a88867

Please sign in to comment.