shorter:
awk 'BEGIN{FS="\t"; OFS="\t"} /^#/ {print; next;} {$1=($2<3000000?"chr1":"chr2");print $0}}' foo.vcf > foo.modified.vcf
• 0 views
•
link
Hi
I have a VCF file which hasn't distinguished between the chromosomes - rather #Chrom is the name of my reference strain. The genomes in my MSA only have 2 chromosomes, so I was wondering if there is a way to rename #Chrom before position 3,000,000 chr1 and after this position chr2?
Thanks!!
It's not pretty, but something along these lines should work:
awk 'BEGIN{FS="\t"; OFS="\t"}{if(substr($0,1,1) == "#") {print $0} else {if($2<3000000){$1="chr1"}else{$1="chr2"}print $0}}' foo.vcf > foo.modified.vcf
Update: To chop 3 million off of the chr2 positions:
awk 'BEGIN{FS="\t"; OFS="\t"}{if(substr($0,1,1) == "#") {print $0} else {if($2<3000000){$1="chr1"}else{$1="chr2"; $2 -= 3000000}print $0}}' foo.vcf > foo.modified.vcf
Log in to answer this question.
Thank you, this works great!
However, because my vcf wasn't created based on chromosomes, all the positions for chr2 are 3,000,000 positions too high. Is there a way I can take 3,000,000 off every position for chromosome 2?
See my update.