I have a folder with 900 files named like this:
chr1_643632542_63643636.vcf.gz
chr1_23634521_626356.vcf.gz
chr2_363643262346_234324.vcf.gz
chr2_1345_21346.vcf.gz
....
chr22_134545_3245145.vcf.gz
I was trying to index each file with the loop:
for i in {1..22}
do
bcftools index -t -f chr${i}_*_*.vcf.gz
done
So I would end up with the following:
chr1_643632542_63643636.vcf.gz
chr1_643632542_63643636.vcf.gz.tbi
chr1_23634521_626356.vcf.gz
chr1_23634521_626356.vcf.gz.tbi
chr2_363643262346_234324.vcf.gz
chr2_363643262346_234324.vcf.gz.tbi
chr2_1345_21346.vcf.gz
chr2_1345_21346.vcf.gz.tbi
....
chr22_134545_3245145.vcf.gz
chr22_134545_3245145.vcf.gz.tbi
However, when I run the above loop I only get an indexed file for the first chromosme entry with the remainder being ignored (i.e. one chr1__.vcf.gz.tbi file only is indexed and the remainder ignored and then the first chr2 file and the first chr3 file and so on).
Help would be much appreciated.
All the best
Maybe loop over file names directly:
for i in chr*.vcf.gz
do
bcftools index -t -f $i
done