Sample Header Ad - 728x90

bash script quoting frustration

6 votes
3 answers
954 views
This problem is driving me crazy. From the command prompt I can enter this command and it works as expected (records where the INFO/RegionType tag contains the value Core are emitted in the output file):
bcftools filter -i "INFO/RegionType='Core'" -Oz -o temp.core.vcf.gz temp2.vcf.gz
But when I try to put the command in a bash script things go awry. This seems to be due to the single and double quotes? I tried various permutations of escaping quotes with no success. Finally I tried the approach described here: to store the filter string in a variable and reference the variable. From my script:
filter_string=INFO/RegionType="'Core'"
bcftools filter -i \""$filter_string"\" -Oz -o temp.core.vcf.gz temp2.vcf.gz
This completes without an error but the command is not interpreting the filter correctly as evidenced by the fact that no records are included in the output file, whereas the command given directly from the command prompt yields 3124 records in the output file. What might be going on here? ---- A minimal example of the input file that works with bcftools and reproduces the issue (note that all whitespace in the lines starting with chr1 needs to be single tabs, not spaces):
-none
##fileformat=VCFv4.2
##FILTER=
##INFO=
##INFO=
##FORMAT=
##contig=
#CHROM	POS	ID	REF	ALT	QUAL	FILTER	INFO	FORMAT	sample1
chr1	103385791	.	C	G	1182.77	PASS	AC=1;	GT	0/1
chr1	103471456	.	CCAT	C	2848.73	PASS	AC=2;RegionType=Core	GT	1/1
Asked by mcrepeau (69 rep)
Aug 21, 2024, 08:17 PM
Last activity: Aug 23, 2024, 05:17 AM