Question: How to sort VCF "chr1, chr2..."
0
gravatar for student-t
15 months ago by
student-t430
Australia
student-t430 wrote:

I have a VCF file ordered by "chr1, chr10, chr11 ...". I would like to sort it to "chr1, chr2, chr3 ..."

I tried Picard's SortVcf but it gives me back the orders "chr1, chr10, chr11 ...". It's not something I want.

Q: What's the easiest way to sort my VCF file by "chr1, chr2, chr3 ..."?

vcf • 652 views
ADD COMMENTlink modified 15 months ago by Petr Ponomarenko2.5k • written 15 months ago by student-t430
2

Picard's SortVcf but it gives me the old orders.

Hi student-t,

Just a moment, I'm getting my crystal ball to find out more about those errors! In all seriousness: please be as informative as possible. We are notoriously bad in reading your mind or your unknown error messages!

Cheers,
Wouter

ADD REPLYlink written 15 months ago by WouterDeCoster28k

I've edited my question to address your concerns.

ADD REPLYlink written 15 months ago by student-t430
6
gravatar for Petr Ponomarenko
15 months ago by
United States / Los Angeles / ALAPY.com
Petr Ponomarenko2.5k wrote:

One way is to use vcf-sort from vcftools http://vcftools.sourceforge.net/

vcf-sort your.vcf > sorted.vcf

The second way is to use grep and sort:

grep "^#" your.vcf > sorted.vcf && grep -v "^#" your.vcf | \
  sort -V -k1,1 -k2,2n >> sorted.vcf

The first grep select header, the second grep select data, sort sorts by the first column and since it is alphanumerical it sorts it -V in version sort order. Some systems do not have -V in sort, then use

grep "^#" your.vcf > sorted.vcf && grep -v "^#" your.vcf | \
  awk '{tmp=$1;sub(/chr/,"",tmp);print tmp,$0}' | \
  sort -k1,1n -k3,3n | \
  awk '{tmp=$0;sub(/([^ ]+ +){1}/,"",tmp);print tmp}' >> sorted.vcf

By the way do you have chrX and chrY and where you want to have it?

ADD COMMENTlink modified 15 months ago • written 15 months ago by Petr Ponomarenko2.5k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 918 users visited in the last hour