This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Extract several columns from a VCF file

Hello,

I have a vcf file with 100 genotypes. I want to extract information on 10 specific genotypes and I have a list of their ID's. Any ideas which tool could be used?

vcf

bcftools is the go to for me in such cases.

a bit more details would be much appreciated, as I studied it, but without any success.

You need to study and experiment with it more, then. It's a pretty straightforward tool.

I've edited my answer above

2 answers

Yes, now I found a solution:

bcftools view -S in.txt in.vcf > out.vcf

If you were polite and just wrote your latest comment, we would have avoided upsetting each other. Don't take for granted that understanding some concepts are easy for everybody like they are for you. Sometimes we just need one keyword to move on. Thanks

I'm glad you found a solution. "You need to read (the documentation) more" and "Read the manual" are not upsetting statements, they are plain facts. The disconnect was between the words you were using to think about the problems and the words the community uses to describe those concepts.

When we encounter an obstacle, we can either choose to learn or complain how difficult it is for us. On a personal note, I struggle with this a lot myself too. We cannot expect people to coddle us, especially in a professional setting.

Do you mean you have the SNP IDs?

bcftools view -i ID==@text file_of_SNP_IDs yourvcf > output.vcf

Further to your question I think you want:

bcftools view -s sample1,sample2 file.vcf > filtered.vcf
bcftools view -S sample_file.txt file.vcf > filtered.vcf

vcf format

#header1
#header2
#etc
#CHROM  POS ID REF ALT QUAL FILTER INFO FORMAT ID1 ID2 ID3 ID4 ID5...ID100

I need to get some of this ID's

Figure out how to use bcftools to subset a VCF file to have only a few samples. Read the manual, it is the single most useful tool you'll need to work with VCF files.

I wouldn't be asking questions here if I wasn't stuck. So sorry I am not as brilliant as you are! Also, if you are not willing to help, just do not comment, as I am a grown up person and I know how to study! thanks

if you are not willing to help, just do not comment

Please don't take things so personally. If you were to read the comment properly, you'd see I gave you the exact keywords to search for in the manual. subset and samples are the keywords you need to get to where you want. Use those and you won't be stuck.

Log in to answer this question.