Skip to content

Commit

Permalink
Misc test code
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Dec 20, 2023
1 parent e486162 commit a7004eb
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 132 deletions.
139 changes: 68 additions & 71 deletions test/csi.test.ts
Original file line number Diff line number Diff line change
@@ -1,81 +1,78 @@
//@ts-nocheck
import { LocalFile } from 'generic-filehandle'
import VirtualOffset from '../src/virtualOffset'
import CSI from '../src/csi'

describe('csi index', () => {
it('loads test.gff3.gz.csi', async () => {
const ti = new CSI({
filehandle: new LocalFile(require.resolve('./data/test.gff3.gz.csi')),
})
const indexData = await ti.parse()
expect(indexData.columnNumbers.start).toEqual(4)
expect(indexData.columnNumbers.ref).toEqual(1)
expect(indexData.columnNumbers.end).toEqual(5)
// console.log( ti );
let blocks = await ti.blocksForRange('1', 1, 4000)
expect(blocks.length).toEqual(0)
blocks = await ti.blocksForRange('1', 0, 2000046092)
expect(blocks.length).toEqual(1)
expect(blocks[0].minv.blockPosition).toEqual(0)
expect(blocks[0].minv.dataPosition).toEqual(130)
// console.log( blocks );
test('loads test.gff3.gz.csi', async () => {
const ti = new CSI({
filehandle: new LocalFile(require.resolve('./data/test.gff3.gz.csi')),
})
const indexData = await ti.parse()
expect(indexData.columnNumbers.start).toEqual(4)
expect(indexData.columnNumbers.ref).toEqual(1)
expect(indexData.columnNumbers.end).toEqual(5)
// console.log( ti );
let blocks = await ti.blocksForRange('1', 1, 4000)
expect(blocks.length).toEqual(0)
blocks = await ti.blocksForRange('1', 0, 2000046092)
expect(blocks.length).toEqual(1)
expect(blocks[0].minv.blockPosition).toEqual(0)
expect(blocks[0].minv.dataPosition).toEqual(130)
// console.log( blocks );

const metadata = await ti.getMetadata()
expect(metadata).toEqual({
columnNumbers: { end: 5, ref: 1, start: 4 },
csi: true,
csiVersion: 1,
depth: 6,
refCount: 2,
coordinateType: '1-based-closed',
format: 'generic',
firstDataLine: new VirtualOffset(0, 130),
metaChar: '#',
refIdToName: ['1', 'ctgB'],
refNameToId: { 1: 0, ctgB: 1 },
skipLines: 0,
maxBlockSize: 1 << 16,
maxBinNumber: 299593,
maxRefLength: 4294967296,
})
const metadata = await ti.getMetadata()
expect(metadata).toEqual({
columnNumbers: { end: 5, ref: 1, start: 4 },
csi: true,
csiVersion: 1,
depth: 6,
refCount: 2,
coordinateType: '1-based-closed',
format: 'generic',
firstDataLine: new VirtualOffset(0, 130),
metaChar: '#',
refIdToName: ['1', 'ctgB'],
refNameToId: { 1: 0, ctgB: 1 },
skipLines: 0,
maxBlockSize: 1 << 16,
maxBinNumber: 299593,
maxRefLength: 4294967296,
})
})
test('loads test.vcf.gz.csi', async () => {
const ti = new CSI({
filehandle: new LocalFile(require.resolve('./data/test.vcf.gz.csi')),
})
it('loads test.vcf.gz.csi', async () => {
const ti = new CSI({
filehandle: new LocalFile(require.resolve('./data/test.vcf.gz.csi')),
})
const indexData = await ti.parse()
expect(indexData.columnNumbers.start).toEqual(2)
expect(indexData.columnNumbers.ref).toEqual(1)
expect(indexData.columnNumbers.end).toEqual(0)
// console.log( ti );
let blocks = await ti.blocksForRange('1', 1, 4000)
expect(blocks.length).toEqual(0)
blocks = await ti.blocksForRange('1', 0, 2000046092)
expect(blocks.length).toEqual(1)
expect(blocks[0].minv.blockPosition).toEqual(0)
expect(blocks[0].minv.dataPosition).toEqual(2560)
// console.log( blocks );
const indexData = await ti.parse()
expect(indexData.columnNumbers.start).toEqual(2)
expect(indexData.columnNumbers.ref).toEqual(1)
expect(indexData.columnNumbers.end).toEqual(0)
// console.log( ti );
let blocks = await ti.blocksForRange('1', 1, 4000)
expect(blocks.length).toEqual(0)
blocks = await ti.blocksForRange('1', 0, 2000046092)
expect(blocks.length).toEqual(1)
expect(blocks[0].minv.blockPosition).toEqual(0)
expect(blocks[0].minv.dataPosition).toEqual(2560)
// console.log( blocks );

expect(await ti.lineCount('1')).toEqual(37)
expect(await ti.lineCount('1')).toEqual(37)

const metadata = await ti.getMetadata()
expect(metadata).toEqual({
csi: true,
csiVersion: 1,
depth: 6,
refCount: 1,
columnNumbers: { end: 0, ref: 1, start: 2 },
coordinateType: '1-based-closed',
format: 'VCF',
metaChar: '#',
firstDataLine: new VirtualOffset(0, 2560),
refIdToName: ['1'],
refNameToId: { 1: 0 },
maxBlockSize: 1 << 16,
skipLines: 0,
maxBinNumber: 299593,
maxRefLength: 4294967296,
})
const metadata = await ti.getMetadata()
expect(metadata).toEqual({
csi: true,
csiVersion: 1,
depth: 6,
refCount: 1,
columnNumbers: { end: 0, ref: 1, start: 2 },
coordinateType: '1-based-closed',
format: 'VCF',
metaChar: '#',
firstDataLine: new VirtualOffset(0, 2560),
refIdToName: ['1'],
refNameToId: { 1: 0 },
maxBlockSize: 1 << 16,
skipLines: 0,
maxBinNumber: 299593,
maxRefLength: 4294967296,
})
})
89 changes: 41 additions & 48 deletions test/tbi.test.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,48 @@
//@ts-nocheck
import { LocalFile } from 'generic-filehandle'
import VirtualOffset from '../src/virtualOffset'
import TabixIndex from '../src/tbi'
import TBI from '../src/tbi'

describe('tbi index', () => {
it('loads', async () => {
const ti = new TabixIndex({
filehandle: new LocalFile(
require.resolve('./data/volvox.test.vcf.gz.tbi'),
),
})
const indexData = await ti.parse()
expect(indexData.columnNumbers.start).toEqual(2)
expect(indexData.columnNumbers.ref).toEqual(1)
expect(indexData.columnNumbers.end).toEqual(0)
// console.log( ti );
const blocks = await ti.blocksForRange('contigA', 1, 4000)
expect(blocks.length).toEqual(1)
expect(blocks[0].minv.blockPosition).toEqual(0)
expect(blocks[0].minv.dataPosition).toEqual(10431)
// console.log( blocks );

const metadata = await ti.getMetadata()
expect(metadata).toEqual({
columnNumbers: { end: 0, ref: 1, start: 2 },
coordinateType: '1-based-closed',
format: 'VCF',
metaChar: '#',
maxBinNumber: 37449,
firstDataLine: new VirtualOffset(0, 10431),
refIdToName: ['contigA'],
refNameToId: { contigA: 0 },
maxBlockSize: 1 << 16,
skipLines: 0,
maxRefLength: 536870912,
})
console.warn = jest.fn()
expect(await ti.blocksForRange('contigA', 7334998796, 8104229566)).toEqual(
[],
)
expect(console.warn).toHaveBeenCalledWith(
'querying outside of possible tabix range',
)
test('loads', async () => {
const ti = new TBI({
filehandle: new LocalFile(require.resolve('./data/volvox.test.vcf.gz.tbi')),
})
it('failing tabix', async () => {
const ti = new TabixIndex({
filehandle: new LocalFile(
require.resolve('./data/failing_tabix.vcf.gz.tbi'),
),
})
const indexData = await ti.parse()
expect(indexData.columnNumbers.start).toEqual(2)
expect(indexData.columnNumbers.ref).toEqual(1)
expect(indexData.columnNumbers.end).toEqual(0)
// console.log( ti );
const blocks = await ti.blocksForRange('contigA', 1, 4000)
expect(blocks.length).toEqual(1)
expect(blocks[0].minv.blockPosition).toEqual(0)
expect(blocks[0].minv.dataPosition).toEqual(10431)
// console.log( blocks );

await expect(ti.parse()).rejects.toThrow(/too many bins/)
const metadata = await ti.getMetadata()
expect(metadata).toEqual({
columnNumbers: { end: 0, ref: 1, start: 2 },
coordinateType: '1-based-closed',
format: 'VCF',
metaChar: '#',
maxBinNumber: 37449,
firstDataLine: new VirtualOffset(0, 10431),
refIdToName: ['contigA'],
refNameToId: { contigA: 0 },
maxBlockSize: 1 << 16,
skipLines: 0,
maxRefLength: 536870912,
})
console.warn = jest.fn()
expect(await ti.blocksForRange('contigA', 7334998796, 8104229566)).toEqual([])
expect(console.warn).toHaveBeenCalledWith(
'querying outside of possible tabix range',
)
})
test('failing tabix', async () => {
const ti = new TBI({
filehandle: new LocalFile(
require.resolve('./data/failing_tabix.vcf.gz.tbi'),
),
})

await expect(ti.parse()).rejects.toThrow(/too many bins/)
})
13 changes: 0 additions & 13 deletions test/utils.ts

This file was deleted.

0 comments on commit a7004eb

Please sign in to comment.