bcftools query add header
2
0
Entering edit mode
2.7 years ago
User000 ▴ 710

Hello,

I have a vcf file and I extract only some columns like FILTER, and GT and DP values.

bcftools query -f '%FILTER[\t%GT\t%DP]\n' {input} > {output}

This gives me an output without a header, is it possible to add a tab delimited header like FILTER GT DP?

    FILTER GT DP
    PASS 1/1 89
    PASS 0/1 78
bcftools • 4.0k views
ADD COMMENT
1
Entering edit mode
2.7 years ago
(bcftools query -l in.vcf | awk 'BEGIN{printf("FILTER");} {printf("\t%s_GT\t%s_DP",$1,$1);} END{printf("\n");}'  &&  bcftools query -f '%FILTER[\t%GT\t%DP]\n' in.vcf ) > out.tsv
ADD COMMENT
0
Entering edit mode

thanks a lot, this gives me an error:

IndexError: list index out of range
  File "/usr/local/lib/python3.6/site-packages/snakemake/executors/__init__.py", line 140, in run_jobs
  File "/usr/local/lib/python3.6/site-packages/snakemake/executors/__init__.py", line 441, in run
  File "/usr/local/lib/python3.6/site-packages/snakemake/executors/__init__.py", line 230, in _run
  File "/usr/local/lib/python3.6/site-packages/snakemake/executors/__init__.py", line 156, in _run
  File "/usr/local/lib/python3.6/site-packages/snakemake/executors/__init__.py", line 162, in printjob
ADD REPLY
1
Entering edit mode

I'ts unrelated to your original problem. Looks like a snakemake error. See if awk statements need to be escaped.

ADD REPLY
0
Entering edit mode
NameError: The name 'printf("FILTER");' is unknown in this context. Please make sure that you defined that variable. Also note that braces not used for variable access have to be escaped by repeating them, i.e. {{print $1}}
  File "/usr/local/lib/python3.6/site-packages/snakemake/executors/__init__.py", line 140, in run_jobs
  File "/usr/local/lib/python3.6/site-packages/snakemake/executors/__init__.py", line 441, in run
  File "/usr/local/lib/python3.6/site-packages/snakemake/executors/__init__.py", line 230, in _run
  File "/usr/local/lib/python3.6/site-packages/snakemake/executors/__init__.py", line 156, in _run
  File "/usr/local/lib/python3.6/site-packages/snakemake/executors/__init__.py", line 162, in printjob
ADD REPLY
3
Entering edit mode

at this point I stop helping you.

ADD REPLY
0
Entering edit mode

it says syntax error at END{printf... but I dont know how to solve this since I do not understand what exaactly the code does without any explanations.

ADD REPLY
1
Entering edit mode
2.7 years ago
User000 ▴ 710

I found an easier way:

bcftools query -H -f '%FILTER[\t%GT\t%DP]\n' {output} -o {output}
ADD COMMENT
1
Entering edit mode

Should be

bcftools query -H -f '%FILTER[\t%GT\t%DP]\n' {input} -o {outputname}

This includes header but, for me, also numbers before the names:

#[1]FILTER [2]GT [3]DP

ADD REPLY

Login before adding your answer.

Traffic: 2654 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6