<p>A suggestion from the UK Biobank QC methods white paper:</p>

<ol>
<li>Create a set of SNPs common to your VCF and the 1000 genomes phase 3 call set.</li>
<li>Perform PCA of the 1000 genomes samples using eigenstrat smartpca. You might have to convert to binary plink format.</li>
<li>Project your genotypes onto this pre-computed PCA space and visualize using ggplot to see which cluster you fall in.</li>
</ol>

CC BY-SA 3.0
2017-06-06T13:03:11.313Z
2017-06-06T13:03:11.313Z
Vivek
<p>Ancestry testing is a tricky subject. I spent a good chunk of <a href="http://researcharchive.vuw.ac.nz/handle/10063/1987" rel="nofollow noreferrer">my PhD project</a> on questions similar to this, and haven't really found a good answer for how to detect unmodelled ancestry.</p>

<p>The general idea of how I tried to approach ancestry determination was to create a model set containing well-defined groups of individuals with a known, specific ancestral background. A query individual (or individuals) were then added to this group, and an ancestry-estimating program was run (specifically <a href="http://web.stanford.edu/group/pritchardlab/structure.html" rel="nofollow noreferrer">Structure</a>) to work out what proportion of the unknown individual was attributable to each of the known groups. I would expect that most genetic ancestry tests follow a similar approach to this, although perhaps with a little bit less care about the definition of the model population groups.</p>

<p>Problems arise when individuals are incorrectly assigned to a particular group, when groups are present in the model set that represent a larger proportion of individuals than most other groups, when groups are closely-related to other groups, and when an ancestral history is present in a test individual that doesn't match any of the model groups. And all that assumes that the marker set used for ancestry determination is perfect: no bias towards any particular group, and no systematic genotyping error.</p>

<p>This doesn't mean that ancestry testing won't work, but it's a good idea to take the results with a large grain of salt. There's a <a href="https://www.theguardian.com/world/2017/apr/13/a-dna-test-showed-im-100-maori-many-thought-there-were-none-of-us-left" rel="nofollow noreferrer">good example</a> of a media personality in New Zealand who was told that she had a very high probability of being 100% Māori, despite having a good knowledge of her own family history that indicated one European ancestor a few generations back on both sides of her family.</p>

CC BY-SA 3.0
2017-06-06T13:16:05.703Z
2017-06-06T13:16:05.703Z
gringer
<p>Adding another answer that, while much more involved, offers flexibility, walks through minimal steps, and provides visualizations.<br>
I created a <a href="http://tgviz.herokuapp.com/" rel="nofollow noreferrer">Dash app</a> and <a href="https://github.com/arvkevi/tgviz" rel="nofollow noreferrer">repository</a> that explores this type of analysis using published ancestry informative SNPs and 1000 Genomes Project Data. </p>

<ol>
<li>Identify published ancestry informative SNPs (AISNPs).

<ul>
<li><a href="https://www.ncbi.nlm.nih.gov/pubmed?db=pubmed&amp;cmd=Retrieve&amp;dopt=citation&amp;list_uids=24508742" rel="nofollow noreferrer">Kidd et al.</a></li>
<li><a href="https://www.ncbi.nlm.nih.gov/pubmed?cmd=Retrieve&amp;dopt=citation&amp;list_uids=18683858" rel="nofollow noreferrer">Kosoy et al.</a></li>
</ul></li>
<li>Download 1000 Genomes Project genotype <a href="http://tgviz.herokuapp.com/ftp.1000genomes.ebi.ac.uk/vol1/ftp/release/20130502/supporting/bcf_files/" rel="nofollow noreferrer">bcf data</a>.</li>
<li>Limit genotype data from (2) to AISNPs loci from (1).</li>
<li>One-hot encode the genotypes.</li>
<li>Perform dimensionality reduction (PCA, t-SNE, or UMAP)</li>
<li>Plot components. </li>
</ol>

<p>The original post seemed to want to project their genome against a reference sample. The <a href="https://github.com/arvkevi/tgviz/blob/master/notebooks/plot_walkthrough.ipynb" rel="nofollow noreferrer">plot_walkthrough.ipynb</a> in the <code>tgviz</code> repo shows how this can be achieved.<br>
Output from the notebook on my own data:</p>

<p><a href="https://i.sstatic.net/wo2JH.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/wo2JH.png" alt="enter image description here"></a></p>

CC BY-SA 4.0
2019-01-16T02:14:15.717Z
2019-01-16T02:14:15.717Z
Kevin
<p>Related: <a href="https://bioinformatics.stackexchange.com/questions/3259/ethnicity-check-either-from-bam-or-vcf-files/3300#3300">ethnicity check either from bam or vcf files</a></p>

<p>The missing piece of your puzzle is an ancestry-labeled reference dataset.  1000 Genomes phase 3 usually works well enough here, and it now has variant callsets for both GRCh37 and GRCh38.</p>

CC BY-SA 4.0
2019-01-18T17:39:58.820Z
2019-01-18T17:39:58.820Z
Christopher Chang
<p>A modified implementation of Vivek's answer.</p>

<p><a href="https://github.com/brentp/peddy" rel="noreferrer">peddy</a> is a Python package that samples an input <code>.vcf</code> at ~25000 sites and projects onto a principal component space built on 2504 thousand genome samples. The author has extensive documentation of the tool's features and a link to the preprint. </p>

<p>I downloaded the <code>.vcf</code> and <code>.vcf.tbi</code> for the NA12878 sample from Genome in a Bottle's <a href="ftp://ftp-trace.ncbi.nlm.nih.gov/giab/ftp/release/NA12878_HG001/NISTv3.3.2/GRCh37/" rel="noreferrer">ftp here</a>. Then, created a custom <code>.ped</code> file, <code>NA12878.ped</code>, with the contents:</p>

<p><code>NA12878 HG001   0       0       2       0</code></p>

<p>At the command line:</p>

<p><code>$ peddy --plot --prefix myvcf HG001_GRCh37_GIAB_highconf_CG-IllFB-IllGATKHC-Ion-10X-SOLID_CHROM1-X_v.3.3.2_highconf_PGandRTGphasetransfer.vcf.gz NA12878.ped
</code></p>

<p>The output files all have the prefix <code>myvcf.</code>, here's <code>myvcf.pca_check.png</code>
<a href="https://i.sstatic.net/FmHmB.png" rel="noreferrer"><img src="https://i.sstatic.net/FmHmB.png" alt="myvcf.pca_check.png"></a></p>

CC BY-SA 4.0
2020-02-09T00:32:27.197Z
I think it might be worth adding: `peddy` requires `coloredlogs` and `cyvcf2` the later of which will required you to have gcc&g++ and the headers (e.g. `-dev` versions in ubuntu) of `libbz2`, `liblzma` and `curl`. This knowledge would have saved a precious 15 precious moments of my life :)
George
CC BY-SA 4.0
2020-02-09T00:41:48.643Z
Also, now that it's installed I seem to get the error: `AssertionError: error loading tabix index for b'HG001_GRCh37_GIAB_highconf_CG-IllFB-IllGATKHC-Ion-10X-SOLID_CHROM1-X_v.3.3.2_highconf_PGandRTGphasetransfer.vcf.gz'` (Also based on my understanding shouldn't the `2` be `0` or left to the user to set based on his gender ?)
George
CC BY-SA 3.0
2017-12-21T12:56:43.623Z
2017-12-21T12:56:43.623Z
Kevin
<p><em>This is a question from <a href="https://www.reddit.com/user/beneficii9" rel="noreferrer">/u/beneficii9</a> on reddit. The original post can be found <a href="https://www.reddit.com/r/bioinformatics/comments/6f040g/how_do_you_do_admixture_testing_with_a_whole/" rel="noreferrer">here</a>.</em></p>
<blockquote>
<p>Through the Personal Genome Project, I have had my whole genome sequenced by Veritas, and have it in the form of a single VCF file for the whole genome and one BAS file for each chromosome. The reference genome associated with the VCF file is hg19. It has been helpful in health data; for example, I discovered I'm homozygous for the non-functional variant CYP-2D6 gene (<a href="https://www.ncbi.nlm.nih.gov/projects/SNP/snp_ref.cgi?rs=3892097" rel="noreferrer">rs3892097</a>), which can render several common medications useless, and helps explain why some medicines didn't really work for me. My doctor has found this information very helpful.</p>
<p>Unfortunately, I can't find any way of looking at admixture or ancestry. I've tried setting everything up using a combination of VCFTools, Plink1.9, and ADMIXTURE, but I can't get it to work. I think for ADMIXTURE you have to have a bunch of genomes sorted by geographical origin to compare your genome against, but I'm not sure how to do that, and what's online isn't very clear to me. So scratch that one off.</p>
<p>I've tried converting the file to 23andme format (and at this <a href="https://www.reddit.com/u/psychosomaticism" rel="noreferrer">/u/psychosomaticism</a> has been very helpful). I did that (though it seems there were problems because of the way the VCF file was set up). But the websites that take the data want you to point them to your 23andme account, and that doesn't really work if you only have the file. 23andme doesn't provide for people who had their whole genomes sequenced. They want you to give them a saliva sample like everyone else.</p>
<p>So, what can I do?</p>
</blockquote>

<vcf>
How do I carry out an ancestry/admixture test on a single VCF file?
# How do I carry out an ancestry/admixture test on a single VCF file?

(Asked by: username_0 on 2017-06-06)

*This is a question from [/u/beneficii9](https://www.reddit.com/user/beneficii9) on reddit. The original post can be found [here](https://www.reddit.com/r/bioinformatics/comments/6f040g/how_do_you_do_admixture_testing_with_a_whole/).*

> Through the Personal Genome Project, I have had my whole genome sequenced by Veritas, and have it in the form of a single VCF file for the whole genome and one BAS file for each chromosome. The reference genome associated with the VCF file is hg19. It has been helpful in health data; for example, I discovered I'm homozygous for the non-functional variant CYP-2D6 gene ([rs3892097](https://www.ncbi.nlm.nih.gov/projects/SNP/snp_ref.cgi?rs=3892097)), which can render several common medications useless, and helps explain why some medicines didn't really work for me. My doctor has found this information very helpful.
>
> Unfortunately, I can't find any way of looking at admixture or ancestry. I've tried setting everything up using a combination of VCFTools, Plink1.9, and ADMIXTURE, but I can't get it to work. I think for ADMIXTURE you have to have a bunch of genomes sorted by geographical origin to compare your genome against, but I'm not sure how to do that, and what's online isn't very clear to me. So scratch that one off.
>
> I've tried converting the file to 23andme format (and at this [/u/psychosomaticism](https://www.reddit.com/u/psychosomaticism) has been very helpful). I did that (though it seems there were problems because of the way the VCF file was set up). But the websites that take the data want you to point them to your 23andme account, and that doesn't really work if you only have the file. 23andme doesn't provide for people who had their whole genomes sequenced. They want you to give them a saliva sample like everyone else.
>
> So, what can I do?

**Tags:** vcf

---

## 5 answers

### Answer by username_2 on 2017-12-21. Score: 6 | Accepted answer

A modified implementation of Vivek's answer.

[peddy](https://github.com/brentp/peddy) is a Python package that samples an input `.vcf` at ~25000 sites and projects onto a principal component space built on 2504 thousand genome samples. The author has extensive documentation of the tool's features and a link to the preprint.

I downloaded the `.vcf` and `.vcf.tbi` for the NA12878 sample from Genome in a Bottle's [ftp here](ftp://ftp-trace.ncbi.nlm.nih.gov/giab/ftp/release/NA12878_HG001/NISTv3.3.2/GRCh37/). Then, created a custom `.ped` file, `NA12878.ped`, with the contents:

`NA12878 HG001 0 0 2 0`

At the command line:

`$ peddy --plot --prefix myvcf HG001_GRCh37_GIAB_highconf_CG-IllFB-IllGATKHC-Ion-10X-SOLID_CHROM1-X_v.3.3.2_highconf_PGandRTGphasetransfer.vcf.gz NA12878.ped`

The output files all have the prefix `myvcf.`, here's `myvcf.pca_check.png`
[![myvcf.pca_check.png](https://i.sstatic.net/FmHmB.png)](https://i.sstatic.net/FmHmB.png)

> **Comments:**
> **username_4**: I think it might be worth adding: `peddy` requires `coloredlogs` and `cyvcf2` the later of which will required you to have gcc&g++ and the headers (e.g. `-dev` versions in ubuntu) of `libbz2`, `liblzma` and `curl`. This knowledge would have saved a precious 15 precious moments of my life :)  
> **username_4**: Also, now that it's installed I seem to get the error: `AssertionError: error loading tabix index for b'HG001_GRCh37_GIAB_highconf_CG-IllFB-IllGATKHC-Ion-10X-SOLID_CHROM1-X_v.3.3.2_highconf_PGandRTGphasetransfer.vcf.gz'` (Also based on my understanding shouldn't the `2` be `0` or left to the user to set based on his gender ?)  

---

### Answer by username_1 on 2017-06-06. Score: 4

A suggestion from the UK Biobank QC methods white paper:

1. Create a set of SNPs common to your VCF and the 1000 genomes phase 3 call set.
2. Perform PCA of the 1000 genomes samples using eigenstrat smartpca. You might have to convert to binary plink format.
3. Project your genotypes onto this pre-computed PCA space and visualize using ggplot to see which cluster you fall in.


---

### Answer by username_0 on 2017-06-06. Score: 2

Ancestry testing is a tricky subject. I spent a good chunk of [my PhD project](http://researcharchive.vuw.ac.nz/handle/10063/1987) on questions similar to this, and haven't really found a good answer for how to detect unmodelled ancestry.

The general idea of how I tried to approach ancestry determination was to create a model set containing well-defined groups of individuals with a known, specific ancestral background. A query individual (or individuals) were then added to this group, and an ancestry-estimating program was run (specifically [Structure](http://web.stanford.edu/group/pritchardlab/structure.html)) to work out what proportion of the unknown individual was attributable to each of the known groups. I would expect that most genetic ancestry tests follow a similar approach to this, although perhaps with a little bit less care about the definition of the model population groups.

Problems arise when individuals are incorrectly assigned to a particular group, when groups are present in the model set that represent a larger proportion of individuals than most other groups, when groups are closely-related to other groups, and when an ancestral history is present in a test individual that doesn't match any of the model groups. And all that assumes that the marker set used for ancestry determination is perfect: no bias towards any particular group, and no systematic genotyping error.

This doesn't mean that ancestry testing won't work, but it's a good idea to take the results with a large grain of salt. There's a [good example](https://www.theguardian.com/world/2017/apr/13/a-dna-test-showed-im-100-maori-many-thought-there-were-none-of-us-left) of a media personality in New Zealand who was told that she had a very high probability of being 100% Māori, despite having a good knowledge of her own family history that indicated one European ancestor a few generations back on both sides of her family.


---

### Answer by username_2 on 2019-01-16. Score: 2

Adding another answer that, while much more involved, offers flexibility, walks through minimal steps, and provides visualizations.  
I created a [Dash app](http://tgviz.herokuapp.com/) and [repository](https://github.com/arvkevi/tgviz) that explores this type of analysis using published ancestry informative SNPs and 1000 Genomes Project Data.

1. Identify published ancestry informative SNPs (AISNPs).
   * [Kidd et al.](https://www.ncbi.nlm.nih.gov/pubmed?db=pubmed&cmd=Retrieve&dopt=citation&list_uids=24508742)
   * [Kosoy et al.](https://www.ncbi.nlm.nih.gov/pubmed?cmd=Retrieve&dopt=citation&list_uids=18683858)
2. Download 1000 Genomes Project genotype [bcf data](http://tgviz.herokuapp.com/ftp.1000genomes.ebi.ac.uk/vol1/ftp/release/20130502/supporting/bcf_files/).
3. Limit genotype data from (2) to AISNPs loci from (1).
4. One-hot encode the genotypes.
5. Perform dimensionality reduction (PCA, t-SNE, or UMAP)
6. Plot components.

The original post seemed to want to project their genome against a reference sample. The [plot\_walkthrough.ipynb](https://github.com/arvkevi/tgviz/blob/master/notebooks/plot_walkthrough.ipynb) in the `tgviz` repo shows how this can be achieved.  
Output from the notebook on my own data:

[![enter image description here](https://i.sstatic.net/wo2JH.png)](https://i.sstatic.net/wo2JH.png)


---

### Answer by username_3 on 2019-01-18. Score: 1

Related: [ethnicity check either from bam or vcf files](https://bioinformatics.stackexchange.com/questions/3259/ethnicity-check-either-from-bam-or-vcf-files/3300#3300)

The missing piece of your puzzle is an ancestry-labeled reference dataset. 1000 Genomes phase 3 usually works well enough here, and it now has variant callsets for both GRCh37 and GRCh38.


---

