Regions file parsing broken

Open
#1,215 7 comments 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
Domain
cli

Research direction

Reproduce the issue with bcftools view -R and -T using the one- and two-column regions_test.txt examples, then inspect the regions-file parsing path in the bcftools source. Done means the documented input format is parsed correctly and the commands return the expected records, with the behavior covered by an appropriate test.

Written by the indexing model from the issue text.

Description

enhancement

$ bcftools --version
bcftools 1.10.2
Using htslib 1.10.2
Copyright (C) 2019 Genome Research Ltd.

$ cat regions_test.txt
NC_000001.11 1

$ cat -A regions_test.txt
NC_000001.11^I1$

$ bcftools view -H -R regions_test.txt freq.vcf.gz

No output produced at all but if I use -r option instead it works as expected:

$ bcftools view -H -r NC_000001.11 latest_release/freq.vcf.gz | head -2
NC_000001.11 10498 rs1338146081 G A,T . . . AN:AC 2072:0,0 6:0,0 2:0,0 76:0,0 0:0,00:0,0 2:0,0 4:0,0 26:0,0 82:0,0 4:0,0 2188:0,0
NC_000001.11 10509 rs1262211809 G A . . . AN:AC 2072:0 6:0 2:0 76:0 0:0 0:0 2:0 4:0 26:0 82:0 4:0 2188:0

Same issue if I use -T option, tab-separated file is not parsed properly. If I omit '1' start coordinate from the file then I get the following error:

$ bcftools view -H -R regions_test.txt latest_release/freq.vcf.gz
[E::bcf_sr_regions_init] Could not parse the file regions_test.txt, using the columns 1,2[,-1]
Failed to read the regions: regions_test.txt

The only way to make it work is to use arbitrary large dummy end coordinate in the file:

$ cat regions_test.txt
NC_000001.11 1 999000000000

$ bcftools view -H -R regions_test.txt latest_release/freq.vcf.gz | head -2
NC_000001.11 10498 rs1338146081 G A,T . . . AN:AC 2072:0,0 6:0,0 2:0,0 76:0,0 0:0,00:0,0 2:0,0 4:0,0 26:0,0 82:0,0 4:0,0 2188:0,0
NC_000001.11 10509 rs1262211809 G A . . . AN:AC 2072:0 6:0 2:0 76:0 0:0 0:0 2:0 4:0 26:0 82:0 4:0 2188:0

Unfortunately, description of regions file format in the documentation is overly concise and not very helpful. It is possible I am doing something wrong but I have ran out of ideas to try.

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.