@@ -5,25 +5,28 @@ export function parseGenotypesOnly(
5
5
) {
6
6
const rest = prerest . split ( '\t' )
7
7
const genotypes = { } as Record < string , string >
8
- let i = 0
8
+ let len = samples . length
9
9
if ( format . includes ( 'GT' ) ) {
10
- const formatSplit = format . split ( ':' )
11
- if ( formatSplit . length === 1 ) {
12
- for ( const sample of samples ) {
13
- genotypes [ sample ] = rest [ i ++ ] !
10
+ if ( format === 'GT' ) {
11
+ let len = samples . length
12
+ for ( let i = 0 ; i < len ; i ++ ) {
13
+ genotypes [ samples [ i ] ! ] = rest [ i ] !
14
14
}
15
15
} else {
16
- const gtIndex = formatSplit . indexOf ( 'GT' )
17
- if ( gtIndex === 0 ) {
18
- for ( const sample of samples ) {
19
- const val = rest [ i ++ ] !
20
- const idx = val . indexOf ( ':' )
21
- genotypes [ sample ] = idx !== - 1 ? val . slice ( 0 , idx ) : val
16
+ if ( format . startsWith ( 'GT' ) ) {
17
+ for ( let i = 0 ; i < len ; i ++ ) {
18
+ const idx = rest [ i ] ! . indexOf ( ':' )
19
+ genotypes [ samples [ i ] ! ] =
20
+ idx !== - 1 ? rest [ i ] ! . slice ( 0 , idx ) : rest [ i ] !
22
21
}
23
22
} else {
24
- for ( const sample of samples ) {
25
- const val = rest [ i ++ ] ! . split ( ':' )
26
- genotypes [ sample ] = val [ gtIndex ] !
23
+ // according to vcf spec, GT should be first, so shouldn't even get
24
+ // here, but just added to beware
25
+ const formatSplit = format . split ( ':' )
26
+ const gtIndex = formatSplit . indexOf ( 'GT' )
27
+ for ( let i = 0 ; i < len ; i ++ ) {
28
+ const val = rest [ i ] ! . split ( ':' )
29
+ genotypes [ samples [ i ] ! ] = val [ gtIndex ] !
27
30
}
28
31
}
29
32
}
0 commit comments