Question: Remove columns from the VCF file using vcftools
0
gravatar for mayara_salvian
2.5 years ago by
mayara_salvian0 wrote:

I have a vcf file and I would like to remove four columns (CHROM,POS,ID,REF). I used the following command to extract these columns of my vcf file, but it's not working.

vcf-subset -c CHROM,POS,ID,REF my.vcf > out.vcf

What else should I add to that command?

vcftools • 2.7k views
ADD COMMENTlink modified 2.5 years ago by genomax92k • written 2.5 years ago by mayara_salvian0
1

if you want to remove headers and first 4 columns:

 $ awk -v OFS="\t" '!/##/ {$1=$2=$3=$4="";print}' test.vcf|sed 's/^\s\+//g'

If you want to retain headers, but remove first 4 columns:

$ awk -v OFS="\t" '!/##/ {$1=$2=$3=$4=""}1' test.vcf |sed 's/^\s\+//g'

with sed:

$ sed -e '/##/! s/^\([^\t]*\t\)\{4\}//g' test.vcf | grep -v "##"
ADD REPLYlink modified 2.5 years ago • written 2.5 years ago by cpad011214k
2
gravatar for Pierre Lindenbaum
2.5 years ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum131k wrote:
cut  --complement -f 1-4 my.vcf | grep -v "^##"> out.vcf
ADD COMMENTlink modified 2.5 years ago • written 2.5 years ago by Pierre Lindenbaum131k
1

shouldn't it be (as OP wants to remove the columns, not retain)?

cut --complement -f1-4  my.vcf | grep -v "^##"> out.vcf
ADD REPLYlink modified 2.5 years ago • written 2.5 years ago by cpad011214k

yes, you're right ! I didn't notice. Thanks.

ADD REPLYlink written 2.5 years ago by Pierre Lindenbaum131k
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: 1550 users visited in the last hour