@@ -46,7 +46,7 @@ export class Variant {
4646 const fields = line . slice ( 0 , splitPos ) . split ( '\t' )
4747 const rest = line . slice ( splitPos + 1 )
4848 const [ CHROM , POS , ID , REF , ALT , QUAL , FILTER ] = fields
49- const filter = FILTER === '.' ? undefined : FILTER ! . split ( ';' )
49+ const filter = FILTER === '.' ? undefined : FILTER ? .split ( ';' )
5050
5151 if ( strict && ! fields [ 7 ] ) {
5252 throw new Error (
@@ -55,11 +55,11 @@ export class Variant {
5555 }
5656
5757 this . CHROM = CHROM
58- this . POS = + POS !
59- this . ID = ID === '.' ? undefined : ID ! . split ( ';' )
58+ this . POS = POS !== undefined ? + POS : 0
59+ this . ID = ID === '.' ? undefined : ID ? .split ( ';' )
6060 this . REF = REF
61- this . ALT = ALT === '.' ? undefined : ALT ! . split ( ',' )
62- this . QUAL = QUAL === '.' ? undefined : + QUAL !
61+ this . ALT = ALT === '.' ? undefined : ALT ? .split ( ',' )
62+ this . QUAL = QUAL === '.' ? undefined : QUAL !== undefined ? + QUAL : undefined
6363 this . FILTER = filter ?. length === 1 && filter [ 0 ] === 'PASS' ? 'PASS' : filter
6464 this . INFO =
6565 fields [ 7 ] === undefined || fields [ 7 ] === '.'
@@ -82,7 +82,7 @@ export class Variant {
8282 const pairsLen = infoPairs . length
8383
8484 for ( let i = 0 ; i < pairsLen ; i ++ ) {
85- const pair = infoPairs [ i ] !
85+ const pair = infoPairs [ i ] ?? ''
8686 const eqIdx = pair . indexOf ( '=' )
8787 const key = eqIdx === - 1 ? pair : pair . slice ( 0 , eqIdx )
8888 const val = eqIdx === - 1 ? undefined : pair . slice ( eqIdx + 1 )
@@ -100,7 +100,7 @@ export class Variant {
100100 if ( hasDecode ) {
101101 const items : ( string | number | undefined ) [ ] = [ ]
102102 for ( let j = 0 ; j < itemsLen ; j ++ ) {
103- const v = rawItems [ j ] !
103+ const v = rawItems [ j ] ?? ''
104104 if ( v === '.' ) {
105105 items . push ( undefined )
106106 } else {
@@ -112,7 +112,7 @@ export class Variant {
112112 } else {
113113 const items : ( string | number | undefined ) [ ] = [ ]
114114 for ( let j = 0 ; j < itemsLen ; j ++ ) {
115- const v = rawItems [ j ] !
115+ const v = rawItems [ j ] ?? ''
116116 if ( v === '.' ) {
117117 items . push ( undefined )
118118 } else {
@@ -137,18 +137,18 @@ export class Variant {
137137 const formatKeys = format . split ( ':' )
138138 const isNumberType : boolean [ ] = [ ]
139139 for ( let i = 0 ; i < formatKeys . length ; i ++ ) {
140- const r = this . formatMeta [ formatKeys [ i ] ! ] ?. Type
140+ const r = this . formatMeta [ formatKeys [ i ] ?? '' ] ?. Type
141141 isNumberType . push ( r === 'Integer' || r === 'Float' )
142142 }
143143 const numKeys = formatKeys . length
144144 const samplesLen = this . sampleNames . length
145145 for ( let i = 0 ; i < samplesLen ; i ++ ) {
146- const sample = this . sampleNames [ i ] !
146+ const sample = this . sampleNames [ i ] ?? ''
147147 const sampleData : Record <
148148 string ,
149149 ( string | number | undefined ) [ ] | undefined
150150 > = { }
151- const sampleStr = rest [ i ] !
151+ const sampleStr = rest [ i ] ?? ''
152152 const sampleStrLen = sampleStr . length
153153 let colStart = 0
154154 let colIdx = 0
@@ -157,22 +157,22 @@ export class Variant {
157157 if ( j === sampleStrLen || sampleStr [ j ] === ':' ) {
158158 const val = sampleStr . slice ( colStart , j )
159159 if ( val === '' || val === '.' ) {
160- sampleData [ formatKeys [ colIdx ] ! ] = undefined
160+ sampleData [ formatKeys [ colIdx ] ?? '' ] = undefined
161161 } else {
162162 const items = val . split ( ',' )
163163 const result : ( string | number | undefined ) [ ] = [ ]
164164 if ( isNumberType [ colIdx ] ) {
165165 for ( let k = 0 ; k < items . length ; k ++ ) {
166- const ent = items [ k ] !
166+ const ent = items [ k ] ?? ''
167167 result . push ( ent === '.' ? undefined : + ent )
168168 }
169169 } else {
170170 for ( let k = 0 ; k < items . length ; k ++ ) {
171- const ent = items [ k ] !
171+ const ent = items [ k ] ?? ''
172172 result . push ( ent === '.' ? undefined : ent )
173173 }
174174 }
175- sampleData [ formatKeys [ colIdx ] ! ] = result
175+ sampleData [ formatKeys [ colIdx ] ?? '' ] = result
176176 }
177177 colStart = j + 1
178178 colIdx += 1
0 commit comments