This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Extract VCF samples by ID - Help

Hi,

I have a vcf.gz file which contains about 1000 samples, but I want to extract about 400 of them based on sample ID. I have a separate csv file containing the sample IDs - my idea is to create a for loop that goes through the sample ID column of the vcd and matches it with the IDs from the csv file.

How can I do this so that I create a new VCF file containing only the sample ID matches? Thank you for your help - I am a beginner in bioinformatics so this may be a very basic task.

vcf python bcftools bash

1 answer

Thank you very much. I am trying to bcftools method, but am a bit confused on how it works. What does it mean by "one sample per line" when doing":

bcftools view -S sample.txt

What does it mean by "one sample per line" when doing"

each line in sample.txt contains one sample name.

Thank you! Just an additional question - this is what I came up with, but it seems to run into errors. Do you know if I'm lacking something in my script?

set -x

{SCRIPT=${SCRATCH}/HLA

source ${SCRIPT}/myenv/bin/activate

module load NiaEnv/2019b && \ module load gcc/8.3.0 && \ module load bcftools\

TOTAL=/project/j/jle/Shared/joint-call/February2022/total.vcf.gz sampleID=/scratch/j/jle/jasminl/HLA/participant_ID.txt OUTPUTS=/scratch/j/jle/jasminl/HLA/Output

for ${TOTAL}; do bcftools view -Oz -S ${sampleID} > ${OUTPUTS} sample.vcf.gz done }

Oh! I see, Ill make a separate post for it. Thank you for your help!

Log in to answer this question.