GnomAD has publicly available VCF files that have variant data gathered from over 15k individuals. For a university project, I want to randomly select 1k of these individuals and get the variant data belgoning to them only.

I am very new to bioinformatics in general and upon checking VCF files and how they work, my current conclusion is that this task is not achievable through filtering the vcf file in any way since variants in these files have no direct connection to the genomes they were found in (no array of individual IDs in a variant entry that show which individuals had this variant).

But this task was given to me by a professor whom I believe is competent to realize the task was impossible if it is like I thought, so is there something I am missing?

How can I go about randomly selecting a 1000 individuals from this 15 000 pool, and then generating a new VCF file with the data from these selected 1000?

Are there any fields that show which individuals genome samples showed a spesific variant entry in the VCF file?

  • $\begingroup$ Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. $\endgroup$
    – Community Bot
    Commented Oct 24, 2022 at 18:02
  • 1
    $\begingroup$ When you say you want "1k of these genomes", I think you mean "you want the variants identified in 1k of these samples" and not the actual genomes. Is that correct? And what do you mean by "variants in these files have no direct connection to the genomes"? If this is a multi-sample VCF file, the zygosity field will tell you if this variant was found in a given sample. $\endgroup$
    – terdon
    Commented Oct 24, 2022 at 18:09
  • 1
    $\begingroup$ Do you want to simply randomly sample 1K individuals from the VCF and produce a second VCF with the variant data of those 1K individuals ? That's what I understand, $\endgroup$
    – JRodrigoF
    Commented Oct 25, 2022 at 7:32
  • $\begingroup$ @JRodrigoF Yes that is exactly what I want, it seems to me that I understood some spesifications of the vcf file wrong. Is this task doable, how would one go about achieving this? $\endgroup$
    – Arda Cüce
    Commented Oct 25, 2022 at 10:17

1 Answer 1


It is. A VCF ought to be sub-settable to a specific list of samples. The only thing you have to come up with for your specific case, is a list of 1K random sample IDs within the original VCF.

Geenerally speaking, knowing that you can do this and how involves getting familiar with the VCF specification as well as the main bioinfo tool used to manipulate and work with this format: BCFtools

Let's use 1000 genomes data as an example.

You can use a bit of UNIX together with BCFtools in order to get a list of 1K random IDs from individuals:

(sort -R instead of shuf might work too)

bcftools query -l ALL.chr22.phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz | shuf | head -1000 > myRandomIDs.txt

Then again BCFtools to subset the list of individuals from the original VCF and into a new VCF file:

bcftools view --samples-file myRandomIDs.txt ALL.chr22.phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz -o myNewVCF.vcf

If you dig a bit deeper into the BCFtools documentation, you will find many things you can do extra if you wanted, like re-calculating the allele frequencies based on this new cohort of individuals, if you wanted that too. Or subset for positions/variants, instead of individuals.

GnomAD data

Using GnomAD data, selecting 1K random samples is impossible since data is aggregated and instead of genotypes per individual (and individuals you can select thus) we only have the frequency of the variants across various sub-cohorts within the GnomAD project. No individual level data.

The most you can do is select one of such sub-cohorts and filter for variants with a frequency > 0 (or a range) in such cohort. You could get variants present only and only is a specific cohort too, by using either frequency information or other info such as allele counts, etc.

The example below filters for variants with a frequency above 0 in the South Asian cohort and 0 frequency in the Southern European cohort. You can have a look at the header of the VCF in order to get to know all cohorts included and the meaning of all the information contained within the INFO filed in the VCF

bcftools filter -i "AF_sas > 0 & AF_nfe_seu = 0" gnomad.exomes.r2.1.1.sites.21.vcf.bgz

But I'm afraid that's not exactly what you wanted to do in the first place.

  • $\begingroup$ The problemz is, while this works with the dataset you've given as the example, when I execute the bcftools query -l gnomad.genomes.r2.1.sites.chr21.vcf.gz it does not return any output. Does this indicate that in this VCF file does not include any sample ID information? $\endgroup$
    – Arda Cüce
    Commented Oct 25, 2022 at 16:32
  • $\begingroup$ @ArdaCüce gnomad doesn’t actually contain individual level samples, it is a vcf of aggregated samples which gives you the allele frequencies (I.e. it contains averages), so it contains no sample level information. You might want to try a different dataset which does have individual level data, depending on the question you want to ask. $\endgroup$
    – user438383
    Commented Oct 26, 2022 at 7:42
  • $\begingroup$ OK. I see, I for a moment thought your GnomAD VCF had sample-level data, but this makes sense actually. Please see if my updated answer provides a better answer, $\endgroup$
    – JRodrigoF
    Commented Oct 26, 2022 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.