Tutorial: Merging multiple vcf files into Single vcf file
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!
• 15,372 views
•
link
0 answers
No answers yet.
Log in to answer this question.
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.
I agree. Maybe I should have been specific about my post. However, the code you showed me, did not work. umm, after running code, you showed me, it gave me a lot of errors. It could not identify vcf.list and other problems.
Failed to open vcf.list: unknown file type
This was the main error I got.
Maybe you could help me more on the code you showed me.
Are you using Mac OS?
No, my workstation is Ubuntu.
It is fine to use your method for your own work. People just need to be aware that it may merge files that they do not want to be merged. My approach is more specific and 'controlled'.
Maybe it is. But it did not work. Even though I made a list of the vcf files using the ls command, executing the command you helped me with, gave me the error the vcf.list unknown file type.
How to solve this?
The
vcf.listfile is in the same directory as that in which you are running the command, right?Yes. It is in the same directory.
Try
bcftools mergewith--file-list... an easier implementation of the way that I did it (courtesy finswimmer)Hello jaybee ,
I would suggest you open a new question for that, so we can keep the focus in this thread on aspects around your tutorial.
Once you open a new question I would like to remove this part of the discussion here, to keep this threat clean.
Thanks!
fin swimmer
Sure, I will add this discussion as a new question on the forum,