Question: bash loop to count variants using vcftools
0
gravatar for bioguy24
4.8 years ago by
bioguy24190
Chicago
bioguy24190 wrote:

I can run the below vcftools command to count individual variant types in vcf.gz files

zcat /home/cmccabe/Desktop/vcf/file1.vcf.gz | vcf-annotate --fill-type | grep -oP "TYPE=\w+" | sort | uniq -c > /home/cmccabe/Desktop/vcf/file1_variant_counts.bed

However when I try a bash loop the command does not run at all and I can not seem to figure out why, I think it looks right?  Thank you :).

for f in /home/cmccabe/Desktop/vcf/*.vcf.gz ; do
     bname=`basename $f`
     pref=${bname%%.vcf.gz
     zcat /home/cmccabe/Desktop/vcf/$f | vcf-annotate --fill-type | grep -oP "TYPE=\w+" | sort | uniq -c > /home/cmccabe/Desktop/vcf/${pref}_variant_counts.bed
done

 

I think I see it now, I m issed a closing brace in the pref=.... Thank you :).

bash vcftools • 1.7k views
ADD COMMENTlink modified 4.8 years ago by geek_y11k • written 4.8 years ago by bioguy24190
1

Exactly. The closing brace was the problem. Nice use of %% BTW :)

ADD REPLYlink modified 9 months ago • written 4.8 years ago by RamRS30k

In your loop, f=/home/cmccabe/Desktop/vcf/*.vcf.gz; in your zcat command you open

"/home/cmccabe/Desktop/vcf/home/cmccabe/Desktop/vcf/*.vcf.gz"
ADD REPLYlink modified 9 months ago by RamRS30k • written 4.8 years ago by michael.ante3.6k

It must be zcat $f

ADD REPLYlink written 4.8 years ago by venu6.7k
2
gravatar for venu
4.8 years ago by
venu6.7k
Germany
venu6.7k wrote:
for f in /home/cmccabe/Desktop/vcf/*.vcf.gz
> do
> zcat $f | vcf-annotate --fill-type | grep -oP "TYPE=\w+" | sort | uniq -c > "$f"_variant_counts.bed
> done

Then change all the file names with rename command.

Ex:

rename "s/.vcf.gz_variant_counts.bed/.bed/" *.bed
ADD COMMENTlink modified 9 months ago by RamRS30k • written 4.8 years ago by venu6.7k

Thank you all :).

ADD REPLYlink written 4.7 years ago by bioguy24190
2
gravatar for geek_y
4.8 years ago by
geek_y11k
Barcelona
geek_y11k wrote:

Try to use GNU Parallel for these kind of tasks:

parallel --jobs <int> "zcat {} |  vcf-annotate --fill-type | grep -oP \"TYPE=\\w+\" | sort | uniq -c > {.}_variant_counts.bed" ::: /home/cmccabe/Desktop/vcf/*.vcf.gz
ADD COMMENTlink modified 9 months ago by RamRS30k • written 4.8 years ago by geek_y11k
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: 1161 users visited in the last hour