bcftools view changes GT format field value when it is declared as Type=Integer

Open
#2,431 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
c

Research direction

Start by reproducing the behavior with the attached gt_integer_missing.vcf.gz and test2.vcf.gz using bcftools view. Trace how incorrectly declared Integer GT fields are decoded and written; done means missing, 0, 1, 2, and 3 values are preserved as expected instead of being changed.

Written by the indexing model from the issue text.

Description

When the GT format field is incorrectly declared as Type=Integer, bcftools view changes the GT value.

Yes, Integer as the type for the GT format field is clearly wrong, but the behavior is surprising.

Input:
gt_integer_missing.vcf.gz

##fileformat=VCFv4.2
##FILTER=<ID=PASS,Description="All filters passed">
##INFO=<ID=END,Number=1,Type=Integer,Description="End coordinate of the variant">
##FORMAT=<ID=GT,Number=1,Type=Integer,Description="Genotype">
##FORMAT=<ID=CN,Number=1,Type=Integer,Description="Copy number maximum a posteriori value">
##contig=<ID=Y>
#CHROM	POS	ID	REF	ALT	QUAL	FILTER	INFO	FORMAT	sample
Y	21154053	.	N	<DUP>	.	.	END=21154895	GT:CN	.:.

Command:

bcftools view gt_integer_missing.vcf

Actual output:

##fileformat=VCFv4.2
##FILTER=<ID=PASS,Description="All filters passed">
##INFO=<ID=END,Number=1,Type=Integer,Description="End coordinate of the variant">
##FORMAT=<ID=GT,Number=1,Type=Integer,Description="Genotype">
##FORMAT=<ID=CN,Number=1,Type=Integer,Description="Copy number maximum a posteriori value">
##contig=<ID=Y>
##bcftools_viewVersion=1.22+htslib-1.22
##bcftools_viewCommand=view gt_integer_missing.vcf; Date=Thu Jul  3 18:56:39 2025
#CHROM	POS	ID	REF	ALT	QUAL	FILTER	INFO	FORMAT	sample
Y	21154053	.	N	<DUP>	.	.	END=21154895	GT:CN	-65:.

GT value -65 in the output.

Expected output:

I would have expected it to keep the genotype as ., not changing it, even if the type is incorrect.

Version:

$ bcftools --version
bcftools 1.22
Using htslib 1.22
Copyright (C) 2025 Genome Research Ltd.
License Expat: The MIT/Expat license
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Additional information:

It also appears to change GT=0 or GT=1 to GT=. and GT=2 or GT=3 to GT=0. This seems more insidious as the more subtle change will be harder to spot. (The negative value outputted causing problems downstream was the reason why I noticed this in the first place.)

test2.vcf.gz

$ cat test2.vcf
##fileformat=VCFv4.2
##FILTER=<ID=PASS,Description="All filters passed">
##FORMAT=<ID=GT,Number=1,Type=Integer,Description="Genotype">
##contig=<ID=Y>
#CHROM	POS	ID	REF	ALT	QUAL	FILTER	INFO	FORMAT	test2
Y	21154053	missing	T	A,C,G	.	PASS	.	GT	.
Y	21154053	ref	T	A,C,G	.	PASS	.	GT	0
Y	21154053	alt1	T	A,C,G	.	PASS	.	GT	1
Y	21154053	alt2	T	A,C,G	.	PASS	.	GT	2
Y	21154053	alt3	T	A,C,G	.	PASS	.	GT	3
$ bcftools view test2.vcf
##fileformat=VCFv4.2
##FILTER=<ID=PASS,Description="All filters passed">
##FORMAT=<ID=GT,Number=1,Type=Integer,Description="Genotype">
##contig=<ID=Y>
##bcftools_viewVersion=1.22+htslib-1.22
##bcftools_viewCommand=view test2.vcf; Date=Thu Jul  3 21:00:24 2025
#CHROM	POS	ID	REF	ALT	QUAL	FILTER	INFO	FORMAT	test2
Y	21154053	missing	T	A,C,G	.	PASS	.	GT	-65
Y	21154053	ref	T	A,C,G	.	PASS	.	GT	.
Y	21154053	alt1	T	A,C,G	.	PASS	.	GT	.
Y	21154053	alt2	T	A,C,G	.	PASS	.	GT	0
Y	21154053	alt3	T	A,C,G	.	PASS	.	GT	0
Dominant language
C
Stars
891
Forks
277
Avg merge
2d 23h
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from samtools/bcftools

All issues in samtools/bcftools

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.