Skip to content

Commit

Permalink
Update add test
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Jan 21, 2021
1 parent a0bfd1e commit 2c2fe99
Show file tree
Hide file tree
Showing 11 changed files with 353 additions and 342 deletions.
26 changes: 26 additions & 0 deletions plugins/bed/src/BedTabixAdapter/BedTabixAdapter.test.ts
Expand Up @@ -157,3 +157,29 @@ test('adapter can fetch bed with header', async () => {
const featuresJsonArray = featuresArray.map(f => f.toJSON())
expect(featuresJsonArray).toMatchSnapshot()
})

test('adapter can use gwas header', async () => {
const adapter = new BedTabixAdapter(
MyConfigSchema.create({
bedGzLocation: {
localPath: require.resolve('./test_data/gwas.bed.gz'),
},
index: {
location: {
localPath: require.resolve('./test_data/gwas.bed.gz.tbi'),
},
},
}),
)

const features = adapter.getFeatures({
refName: '1',
start: 0,
end: 100_000,
assemblyName: 'hg19',
})

const featuresArray = await features.pipe(toArray()).toPromise()
const featuresJsonArray = featuresArray.map(f => f.toJSON())
expect(featuresJsonArray).toMatchSnapshot()
})
24 changes: 13 additions & 11 deletions plugins/bed/src/BedTabixAdapter/BedTabixAdapter.ts
Expand Up @@ -46,8 +46,7 @@ export default class BedTabixAdapter extends BaseFeatureDataAdapter {
})
this.columnNames = readConfObject(config, 'columnNames')
this.scoreColumn = readConfObject(config, 'scoreColumn')

this.parser = autoSql && new BED({ autoSql })
this.parser = new BED({ autoSql })
}

public async getRefNames(opts: BaseOptions = {}) {
Expand All @@ -69,11 +68,12 @@ export default class BedTabixAdapter extends BaseFeatureDataAdapter {
const header = await this.bed.getHeader()
const defs = header.split('\n').filter(f => !!f)
const defline = defs[defs.length - 1]
const names = defline
.slice(1)
.split('\t')
.map(field => field.trim())
return names
return defline && defline.includes('\t')
? defline
.slice(1)
.split('\t')
.map(field => field.trim())
: null
}

public getFeatures(query: Region, opts: BaseOptions = {}) {
Expand All @@ -85,11 +85,13 @@ export default class BedTabixAdapter extends BaseFeatureDataAdapter {
const l = line.split('\t')
const refName = l[meta.columnNumbers.ref - 1]
const start = +l[meta.columnNumbers.start - 1]
const end = +l[meta.columnNumbers.end - 1] + 1
const end =
+l[meta.columnNumbers.end - 1] +
(meta.columnNumbers.end === meta.columnNumbers.start ? 1 : 0)
const uniqueId = `${this.id}-${fileOffset}`
const data = this.parser
? this.parser.parseLine(line, { uniqueId })
: this.defaultParser(names, line)
const data = names
? this.defaultParser(names, line)
: this.parser.parseLine(line, { uniqueId })

const { blockCount, blockSizes, blockStarts, chromStarts } = data

Expand Down

0 comments on commit 2c2fe99

Please sign in to comment.