# Understanding ancestry testing mathematically

Forgive me if this question has been asked here before, because it is something which should be very easy to find, but I can't seem to find an answer no matter where I search.

The question is simply where to learn the mathematics that goes into things like popular ancestry tests, and also more academic things like determining ancestry components of historical groups (e.g. usage of the terms Ancient North Eurasian, Eastern European Hunter-Gatherers and all that).

It is clear that if someone gets an ancestry test saying say 32% Scandinavian, then of course that doesn't mean 32% of their base pairs have a convenient "Scandinavian" label attached to them, rather there is some statistical inference going on behind these percentages, and I would like to understand that.

Suppose I have the raw data of my own fully sequenced genome, and also a database of the genomes of many individuals from various populations (of course grouping them into populations is already something that involves some assumptions that I would like to learn more about). Where would I learn how to analyze that myself to produce something like the results of an ancestry test? Is there a textbook someone could recommend that gets into the actual algorithms used?

I'll give here a simple, non-technical answer because I'm assuming you don't need to actually perform an analysis of ancestry.

So, detecting ancestry is a non-trivial task. Given your genome sequence, you would need to compare some "informative" regions of the genome with the homologous sequences of some population (say, of a database with other genomes). These informative regions are usually some parts of the genome that vary across individuals (variation is used because differences are informative: some populations vary on particular sites, distinct from other populations). At the core, this is a question on how to compare "character strings" (DNA is composed of 4 characters, namely, A, T, C, and G). But these strings exist in a complicated structure: a human genome is partitioned in 23 pairs of chromosomes, within each individual. However, the question of ancestry is not about individual sequences really, but about population-level changes in DNA composition. So, in fact, you need to consider population-level factors: size of the populations to consider, the rates of recombination (DNA exchange across chromosomic pairs), mutation rates, and even population structure (people move geographically!).

Given these (and, many other) factors, people build models of "coalescence": given a sequence of interest, how likely is that it shares some ancestor with another query sequence? So, the models try to relate these two sequences (say, the one you are interested), with a query (say, a "consensus" Scandinavian sequence), and then make a model of a 3rd sequence (the ancestor!). This process is repeated to test many hypothesis, so you end up with many probabilities. On top of this, you can estimate the ancestry for any given part of your genome, and this is what most companies do (say, 23 and me).

In summary, you are correct that a "% Scandinavian" does not mean sequence similarity per se. It implies an estimation of common ancestry. This estimation comes from models of shared ancestry. If you're unsatisfied with this simple answer, and want a more technical answer, I recommend reading this paper. An intermediate-level explanation is found here.

what is ancestry?

I think some of the confusion in ancestry proportions stems from the fact that 'ancestry' can really mean several different things in different contexts. I would really encourage people to read this short piece, as it does a good job of clarifying what the different terms mean https://journals.plos.org/plosgenetics/article?id=10.1371/journal.pgen.1008624

What something like 23andme is trying to do is to infer how much of your genome most closely matches the genome of a particular pre-specified reference population. This is relatively easy to interpret if one parent if from Nigeria and the other is from Norway, since it will roughly be 50% Norwegian and 50% Nigeria, but becomes more complex to interpret when someone is 70% Norwegian, 20% Danish and 10% Swedish, for example.

summary of the 23andme process

Since you specifically asked about 23andme, I will try and give you a relatively simple explanation of how they end with the numbers that you might have got on the report.

What 23andme are trying to achieve is essentially a 'classification' problem - they have a genome from an individual of unknown ancestry (call this the target individual), and they would like to describe it in terms of some pre-defined set of different ancestries (like 'Norwegian' or 'Nigerian'). To achieve this, they first need to assemble some kind of reference dataset of individuals of whom they know in advance to be of a certain country. For this, they will choose individuals who they know have e.g. all of their grandparents and great grandparents from Norway - so they genomes of these individuals will be reflective of general Norwegian ancestry.

They use something called Support vector machine Learning, which is just a fancy computational method, to 'learn' what segments of Norwegian ancestry look like. This is analagous to the AI algorithms which are able to tell the difference between an image of a cat and a dog. If you 'train' the AI with enough labelled examples, it can accurately classify new images. In the same way, if you train the SVM algorithm with enough examples of what Norwegian or Nigerian DNA segments look like, it can classify the probability that a new segment comes from a particular reference population.

They then take the genome of target individuals and split it up into chunks along the genome (something like 100 chunks per chromosomes). They then apply the SVM algorithm to calculate the probability that a particular chunk comes from a particular reference population. So for example, there might be a certain chunk of the genome which has a 70% chance of coming from the Norwegian reference population and a 30% chance from come from a Danish reference population. If the individual is admixed, the the next window may have a 90% chance of coming from the Nigerian reference population and a 10% chance of coming from the Cameroonian reference population.

They will then go across the genome and look for windows of 'high-confidence', where the probability of the window coming from a particular reference population may be higher than say 90%. If you add up the high confidence windows across the genome for each reference population, you will end up with your overall ancestry proportion for that population.

other ways of inferring ancestry

There are many, many other ways of inferring ancestry proportions/components. For example, Principle Component Analysis, ADMIXTURE analysis, clustering methods, all of which have different strengths and weaknesses.