This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Looping over vcf files

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

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

1 answer

 for F1 in *.vcf.gz; do for F2 in *.vcf.gz; do if [[ "$F1" < "$F2" ]]; then echo $F1 $F2; fi; done ; done

Log in to answer this question.