1
$\begingroup$

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.

$\endgroup$

1 Answer 1

3
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ Hi, are you familiar with TopMed? $\endgroup$ Jan 25, 2022 at 22:11
  • 3
    $\begingroup$ Hello, no I am not, sorry. I answered your questions according to your need. $\endgroup$
    – user324810
    Jan 25, 2022 at 22:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.