|
| 1 | +import { parseGenotypesOnly } from './parseGenotypesOnly.ts' |
1 | 2 | import { parseMetaString } from './parseMetaString.ts' |
2 | 3 | import vcfReserved from './vcfReserved.ts' |
3 | 4 |
|
@@ -120,38 +121,6 @@ export default class VCFParser { |
120 | 121 | return genotypes |
121 | 122 | } |
122 | 123 |
|
123 | | - private parseGenotypesOnly(format: string, prerest: string) { |
124 | | - const rest = prerest.split('\t') |
125 | | - const genotypes = {} as Record<string, string> |
126 | | - let i = 0 |
127 | | - const formatSplit = format.split(':') |
128 | | - if (formatSplit.length === 1) { |
129 | | - for (const sample of this.samples) { |
130 | | - genotypes[sample] = rest[i++]! |
131 | | - } |
132 | | - } else { |
133 | | - const gtIndex = formatSplit.indexOf('GT') |
134 | | - if (gtIndex === 0) { |
135 | | - for (const sample of this.samples) { |
136 | | - const val = rest[i++]! |
137 | | - const idx = val.indexOf(':') |
138 | | - if (idx !== -1) { |
139 | | - genotypes[sample] = val.slice(0, idx) |
140 | | - } else { |
141 | | - console.warn('unknown') |
142 | | - } |
143 | | - } |
144 | | - } else { |
145 | | - for (const sample of this.samples) { |
146 | | - const val = rest[i++]!.split(':') |
147 | | - genotypes[sample] = val[gtIndex]! |
148 | | - } |
149 | | - } |
150 | | - } |
151 | | - |
152 | | - return genotypes |
153 | | - } |
154 | | - |
155 | 124 | /** |
156 | 125 | * Parse a VCF metadata line (i.e. a line that starts with "##") and add its |
157 | 126 | * properties to the object. |
@@ -338,7 +307,7 @@ export default class VCFParser { |
338 | 307 | QUAL: qual, |
339 | 308 | FORMAT: format, |
340 | 309 | SAMPLES: () => this.parseSamples(fields[8] ?? '', rest), |
341 | | - GENOTYPES: () => this.parseGenotypesOnly(fields[8] ?? '', rest), |
| 310 | + GENOTYPES: () => parseGenotypesOnly(fields[8] ?? '', rest, this.samples), |
342 | 311 | } |
343 | 312 | } |
344 | 313 | } |
|
0 commit comments