This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to extract specific SNPs from a vcf file and create new a one consisting of the extracted loci.

Hi everyone.

I currently have a vcf file containing SNP information for a total of 3831 loci. From this vcf file, I would like to generate a vcf file consisting only of loci whose POS column (second column) is the position shown below.

scaffold_8754:711 scaffold_56662:2153 scaffold_56764:16891 scaffold_70342:19238 scaffold_70335:4963 scaffold_65968:2460 scaffold_3433:598 scaffold_40074:5854 scaffold_70209:66631 scaffold_71244:898110 scaffold_71250:456730 scaffold_66351:1452 scaffold_70132:55627 ...

Although omitted above, there are actually 1000 loci that I want to extract.

Could I do this using grep command? Or any other ideas or advice would be appreciated.

Thank you.

vcf grep shellscript snp

1 answer

So you want to extract 1000 loci from 3831 loci?

You can keep 1000 loci in a file "loci_1000", one locus a line, then

cat loci_1000 |
xargs -i grep {} loci_3831.vcf > loci_1000.vcf

Hope this will help.

So you want to extract 1000 loci from 3831 loci?

Yes.

Thank you for your comment! I will try this script.

Log in to answer this question.