<p>There are tools that allows you to sort your VCF file by genomic position like <a href="http://samtools.github.io/bcftools/bcftools.html#sort" rel="nofollow noreferrer">bcftools sort</a> or <a href="https://vcftools.github.io/perl_module.html#vcf-sort" rel="nofollow noreferrer">vcf-sort</a>. But if you don't want to install these software, you could always do with bash tools for one vcf:</p>
<pre class="lang-bash prettyprint-override"><code># get the header of your VCF and write to file 'sorted.vcf'
# if your file has the extension .gz, use zgrep instead
grep &quot;^#&quot; your.vcf &gt; sorted.vcf

# get the rest of the lines not starting with '#', sort them first by chromosome, then position and add them to file 'sorted.vcf'
grep -v &quot;^#&quot; your.vcf | sort -V -k1,1 -k2,2n &gt;&gt; sorted.vcf   
</code></pre>
<p>But since you have one file for each chromosome and assuming that your files look like <code>sample_chrZ.vcf.gz</code>, where <code>Z</code> is the chromosome number, you will have to do a loop:</p>
<pre class="lang-bash prettyprint-override"><code>mkdir sorted_vcf
for chr in *.vcf.gz; do
   filename=&quot;${chr%.*}&quot;
   zgrep &quot;^#&quot; &quot;$chr&quot; &gt; sorted_vcf/&quot;$filename&quot;
   zgrep -v &quot;^#&quot; &quot;$chr&quot; | sort -V -k1,1 -k2,2n  &gt;&gt; sorted_vcf/&quot;$filename&quot;
   bgzip sorted_vcf/&quot;$filename&quot;
done
</code></pre>
<p>And if you want to know whether your VCF has been aligned against GRCh38 or GRCh37, check the header in the VCF file with a line starting with <code>##reference=</code>. A command-line like <code>grep &quot;##reference=&quot; your.vcf</code> should give you the result. However, if you don't have the reference mentioned in your VCF file, this is going to be harder to guess. This <a href="https://www.biostars.org/p/146171/" rel="nofollow noreferrer">post</a> should help you figure it out.</p>

CC BY-SA 4.0
2022-01-25T22:11:36.573Z
Hi, are you familiar with TopMed?
Shelby Labuschagne
CC BY-SA 4.0
2022-01-25T22:17:09.260Z
Hello, no I am not, sorry. I answered your questions according to your need.
user324810
CC BY-SA 4.0
2022-01-25T21:05:10.263Z
2022-01-25T21:05:10.263Z
user324810
<p>I am trying to run my VCF's through Topmed Imputation (<a href="https://imputation.biodatacatalyst.nhlbi.nih.gov/#!pages/home" rel="nofollow noreferrer">https://imputation.biodatacatalyst.nhlbi.nih.gov/#!pages/home</a>)</p>
<p>I am trying to make sure that I have the correct requirements for my file to be able to run through the software. These requirements are:</p>
<p>Create a separate vcf.gz file for each chromosome.</p>
<p>Variations must be sorted by genomic position.</p>
<p>GRCh37 or GRCh38 coordinates are required.</p>
<p>I have managed to split my VCF into each chromosome but I am unsure how to check which coordinates are being used and if my file is sorted by genomic position. Are there unix commands I can use to check, or do I just look in the file, Ive looked and not noticed anything.</p>

<vcf><imputation>
Topmed File Requirements
# Topmed File Requirements

(Asked by: username_0 on 2022-01-25)

I am trying to run my VCF's through Topmed Imputation (<https://imputation.biodatacatalyst.nhlbi.nih.gov/#!pages/home>)

I am trying to make sure that I have the correct requirements for my file to be able to run through the software. These requirements are:

Create a separate vcf.gz file for each chromosome.

Variations must be sorted by genomic position.

GRCh37 or GRCh38 coordinates are required.

I have managed to split my VCF into each chromosome but I am unsure how to check which coordinates are being used and if my file is sorted by genomic position. Are there unix commands I can use to check, or do I just look in the file, Ive looked and not noticed anything.

**Tags:** vcf, imputation

---

## 1 answers

### Answer by username_1 on 2022-01-25. Score: 3

There are tools that allows you to sort your VCF file by genomic position like bcftools sort or vcf-sort. But if you don't want to install these software, you could always do with bash tools for one vcf:
# get the header of your VCF and write to file 'sorted.vcf'
# if your file has the extension .gz, use zgrep instead
grep "^#" your.vcf > sorted.vcf

# get the rest of the lines not starting with '#', sort them first by chromosome, then position and add them to file 'sorted.vcf'
grep -v "^#" your.vcf | sort -V -k1,1 -k2,2n >> sorted.vcf   

But since you have one file for each chromosome and assuming that your files look like sample_chrZ.vcf.gz, where Z is the chromosome number, you will have to do a loop:
mkdir sorted_vcf
for chr in *.vcf.gz; do
   filename="${chr%.*}"
   zgrep "^#" "$chr" > sorted_vcf/"$filename"
   zgrep -v "^#" "$chr" | sort -V -k1,1 -k2,2n  >> sorted_vcf/"$filename"
   bgzip sorted_vcf/"$filename"
done

And if you want to know whether your VCF has been aligned against GRCh38 or GRCh37, check the header in the VCF file with a line starting with ##reference=. A command-line like grep "##reference=" your.vcf should give you the result. However, if you don't have the reference mentioned in your VCF file, this is going to be harder to guess. This post should help you figure it out.

> **Comments:**
> **username_0**: Hi, are you familiar with TopMed?  
> **username_1**: Hello, no I am not, sorry. I answered your questions according to your need.  

---

