@gmod/vcf
Version:
High performance streaming Variant Call Format (VCF) parser in pure JavaScript
31 lines • 1.02 kB
JavaScript
export function parseGenotypesOnly(format, prerest, samples) {
const rest = prerest.split('\t');
const genotypes = {};
let i = 0;
if (format.includes('GT')) {
const formatSplit = format.split(':');
if (formatSplit.length === 1) {
for (const sample of samples) {
genotypes[sample] = rest[i++];
}
}
else {
const gtIndex = formatSplit.indexOf('GT');
if (gtIndex === 0) {
for (const sample of samples) {
const val = rest[i++];
const idx = val.indexOf(':');
genotypes[sample] = idx !== -1 ? val.slice(0, idx) : val;
}
}
else {
for (const sample of samples) {
const val = rest[i++].split(':');
genotypes[sample] = val[gtIndex];
}
}
}
}
return genotypes;
}
//# sourceMappingURL=parseGenotypesOnly.js.map