Skip to content

Commit

Permalink
No default metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Dec 8, 2024
1 parent 5950b41 commit 0fa6e43
Show file tree
Hide file tree
Showing 5 changed files with 1,455 additions and 38 deletions.
39 changes: 20 additions & 19 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,28 +302,29 @@ export default class VCFParser {
? {}
: Object.fromEntries(
fields[7].split(';').map(r => {
const ret = r.split('=')
return [ret[0], ret[1]]
const [key, val] = r.split('=')

const items = val
?.split(',')
.map(val => (val === '.' ? undefined : val))
.map(f => (f && hasDecode ? decodeURIComponentNoThrow(f) : f))
const itemType = this.getMetadata('INFO', key!, 'Type')
if (itemType === 'Integer' || itemType === 'Float') {
return [
key,
items?.map(val =>
val === undefined ? undefined : Number(val),
),
]
} else if (itemType === 'Flag') {
return [key, true]
} else {
// ?? true interpret as flag if undefined
return [key, items ?? true]
}
}),
)

for (const key of Object.keys(info)) {
const items = (info[key] as string | undefined)
?.split(',')
.map(val => (val === '.' ? undefined : val))
.map(f => (f && hasDecode ? decodeURIComponentNoThrow(f) : f))
const itemType = this.getMetadata('INFO', key, 'Type')
if (itemType === 'Integer' || itemType === 'Float') {
info[key] = items?.map(val =>
val === undefined ? undefined : Number(val),
)
} else if (itemType === 'Flag') {
info[key] = true
} else {
info[key] = items
}
}

return {
CHROM: chrom,
POS: pos,
Expand Down
Loading

0 comments on commit 0fa6e43

Please sign in to comment.