How is a principal component analysis for population structure made from a bam or other alignment file? I'm curious how a PCA for population structure is built from an alignment/BAM or SAM file. How do programs like angsd and ngsCovar actually build a PCA? What exactly makes things come out as different and how can this be determined? If I have 3 alignments that look like this:



Locus1:

&gt;Indiv1
ACGT
&gt;Indiv2
ACGC
&gt;Indiv3
ACGA




Locus2:

&gt;Indiv1
GACT
&gt;Indiv2
GACA
&gt;Indiv3
GAGT




Locus3:

&gt;Indiv1
GGTC
&gt;Indiv2
GGCT
&gt;Indiv3
GCTA




(These example alignments leave out quality scores for simplicity, assume that each has high quality across the board.)

What algorithm or system would be used to graph them on a PCA? How many dimensions would that PCA have? Is it possible to model this by hand so that I can understand what's going on/how it is built?
In general, the process works as such:


Variants are found at a number of loci in each sample (missing loci are often imputed).
Each sample is scored at each locus, often according to the number of copies of the reference allele that it has (so, 0-2).
The resulting matrix is used for PCA.