<p>You could run loop over the files in your shell, running a separate command for each file. For example, in <a href="https://www.gnu.org/software/bash/manual/html_node/Looping-Constructs.html" rel="nofollow noreferrer">Bash</a> (or another Bourne shell):</p>
<pre><code>for file in *.vcf.gz; do ./gatk IndexFeatureFile -I <span class="math-container">${file} -O $</span>{file}.tbi; done
</code></pre>

CC BY-SA 4.0
2021-03-22T19:22:06.513Z
Is this approach also valid for merging vcf files? Because, normally I am using bcftools for merging. For example for 3 vcf files I use this: bcftools merge HG00096.chrom22.bam.10061.vcf.gz HG00097.chrom22.bam.10062.vcf.gz HG00101.chrom22.bam.10065.vcf.gz  -o merged.vcf
Ugur Toprak
CC BY-SA 4.0
2021-03-22T20:59:29.570Z
In the case of bcftools merge, I guess looping shouldn't be necessary since you can merge them with one command: `bcftools merge -O z -o merged.vcf.gz HG*.vcf.gz`
Jukka Matilainen
CC BY-SA 4.0
2021-03-22T17:48:08.870Z
2021-03-22T17:48:08.870Z
Jukka Matilainen
<p>I am trying to use GATK IndexFeatureFile to create &quot;.vcf.gz.tbi&quot; file. But I have 480 files.</p>
<p>For the pilot study I used:</p>
<pre><code>!./gatk IndexFeatureFile -I HG00096.chrom22.bam.10061.vcf.gz -O HG00096.chrom22.bam.10061.vcf.gz.tbi
</code></pre>
<p>Doing this procedure for 480 files is not seem very practical. Is there any way to use all file as an input and it takes all files and gives &quot;.tbi&quot; files as an output?</p>
<p>I thought</p>
<pre><code>!./gatk IndexFeatureFile -I *.vcf.gz -O *.vcf.gz.tbi
</code></pre>
<p>or maybe not using output argument (just input). I did not worked for me.</p>

<vcf><gatk>
GATK 4.2 using IndexFeatureFile with multiple files
# GATK 4.2 using IndexFeatureFile with multiple files

(Asked by: username_0 on 2021-03-22)

I am trying to use GATK IndexFeatureFile to create ".vcf.gz.tbi" file. But I have 480 files.
For the pilot study I used:
!./gatk IndexFeatureFile -I HG00096.chrom22.bam.10061.vcf.gz -O HG00096.chrom22.bam.10061.vcf.gz.tbi

Doing this procedure for 480 files is not seem very practical. Is there any way to use all file as an input and it takes all files and gives ".tbi" files as an output?
I thought
!./gatk IndexFeatureFile -I *.vcf.gz -O *.vcf.gz.tbi

or maybe not using output argument (just input). I did not worked for me.

**Tags:** vcf, gatk

---

## 1 answers

### Answer by username_1 on 2021-03-22. Score: 2 | Accepted answer

You could run loop over the files in your shell, running a separate command for each file. For example, in Bash (or another Bourne shell):
for file in *.vcf.gz; do ./gatk IndexFeatureFile -I ${file} -O ${file}.tbi; done

> **Comments:**
> **username_0**: Is this approach also valid for merging vcf files? Because, normally I am using bcftools for merging. For example for 3 vcf files I use this: bcftools merge HG00096.chrom22.bam.10061.vcf.gz HG00097.chrom22.bam.10062.vcf.gz HG00101.chrom22.bam.10065.vcf.gz  -o merged.vcf  
> **username_1**: In the case of bcftools merge, I guess looping shouldn't be necessary since you can merge them with one command: `bcftools merge -O z -o merged.vcf.gz HG*.vcf.gz`  

---

