Looping over vcf files
1
0
Entering edit mode
6.1 years ago
paolo002 ▴ 160

Hi I have a list of various vcf files for different human populations in a directory. pop1.vcf pop2.vcf pop3.vcf pop4.vcf Usually, if I want to do some operation on those files I loop over in bash shell. Example:

for file in /home/users/vcf/*.vcf;
do plink --vcf ${file} --recode -out ${file}.flt.vcf;
done

However, now let's say if I have other 4 files for different populations :

pop5.vcf pop6.vcf pop7.vcf pop8.vcf

I would like to do some operation such as merge for instance for each pair of file in single combination and not over all the possible combination, and third file for each pair will be generated as output:

pop1.vcf with pop5.vcf pop2.vcf with pop6.vcf and so on.

Other times I have this second set of files in different extension. Such as :

pop1.vcf with pop5.bed pop2.vcf with pop6.bed and so on.

How to write a loop with iterates over pair of files doing some kind of operation?

Any help, highly appreciated, thanks

Linux Bash • 2.2k views
ADD COMMENT
0
Entering edit mode

Is there a constant relationship between the file pairs? I.e. is the offset between numbers always the same (i.e 1 with 3, 2 with 4, 3 with 6 etc?).

If the pairings are arbitrary, there's no way to do it without first mapping the numbers to one another

ADD REPLY
1
Entering edit mode
6.1 years ago
 for F1 in *.vcf.gz; do for F2 in *.vcf.gz; do if [[ "$F1" < "$F2" ]]; then echo $F1 $F2; fi; done ; done
ADD COMMENT

Login before adding your answer.

Traffic: 1947 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6