Entering edit mode
3.3 years ago
jaybee
▴
140
To merge multiple vcf files into a single vcf file from different samples,
we can try the code below:
/PATH/to/bcftools merge Home/data/*vcf.gz -Oz -o Merged.vcf.gz
[considering that your files A.vcf.gz , B.vcf.gz and so on are in the Home directory, under the folder data]
[If your bcftools is installed in the usr/bin directory then simply use:
/usr/bin/bcftools merge Home/data/*vcf.gz -Oz -o Merged.vcf.gz
For selective merging:
one may create a list of selected vcf files using the command:
ls *.vcf.gz > vcfout.list
Then merge the selected files using the vcfout.list (file):
bcftools merge -m none --file-list vcfout.list -Oz -o ProjectMerge.vcf.gz
Courtesy: Pierre Lindenbaum, finswimmer, Kevin Blighe
This should work fine!
Just to add that this will merge any file in Home/data/ that has vcf.gz at the end of the filename. Using the method that I showed you elsewhere, jaybee, one can have a list (stored as single column in a file) of the specific files that they want to merge. Each has pros and cons.