# Sample QC and PCA

This is a description of the quality control procedures applied before running the GWAS.

## PCA

The PCA for population structure has been run in the following way:

### Variant filtering and LD pruning

The sisu version 4.2 imputation panel is pruned iteratively, until a target number of SNPs is reached:

9,641,808 starting variants: only variants with a minimum info score of 0.9 in all batches are kept.

The script starts with \[500.0, 50.0, 0.9] params in plink (window,step,r2). It then decreases 0.05 in r2 iteratively pruning the imputation panel until the threshold of 200,000 snps is reached. Once the SNP count falls under 200,000 the closest pruning is returned.

If the higher r2 is closer, 200,000 snps are randomly selected, else the last pruned snps are returned.

Plink flags used: --snps-only --chr 1-22 --max-alleles 2 --maf 0.01 .

For this run 180,042 snps are returned.

### PCA outlier detection

Then, FinnGen data was merged with the 1k genome project (1kgp) data, using the variants mentioned above. A round of PCA was performed and a bayesian algorithm was used to spot outliers. This process got rid of 15,898 FinnGen samples. The figure below shows the scatter plots for the first 3 PCs. Outliers, in green, are separated from the FinnGen red cluster.

<figure><img src="https://3248549602-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwxE6DR0oal1nFglVz4Hy%2Fuploads%2FuZcqbCoRURAcVzLwosh7%2Ffinngen_R12_analysis_document_GWAS.pdf-image-000.png?alt=media&#x26;token=78c3e0aa-e2e1-4692-bc67-317ee23aad72" alt=""><figcaption></figcaption></figure>

While the method automatically detected as being outliers the 1kg samples with non European and southern European ancestries, it did not manage to exclude some samples with Western European origins. Since the signal from these samples would have been too small to allow a second round to be performed without detecting substructures of the Finnish population, another approach was used. The FinnGen samples that survived the first round were used to compute another PCA. The EUR and FIN 1kg samples were then projected onto the space generated by the first 3 PCs. Then, the centroid of each cluster was calculated and used to calculate the squared mahalanobis distance of each FinnGen sample to each of the centroids. Being the squared distance a sum of squared variables (with unitary variance, due to the mahalanobis distance), we could see it as a sum of 3 independent squared variables. This allowed us to map the squared distance into a probability (chi squared with 3 degrees of freedom). Therefore, for each cluster, a probability of being part of it was computed. Then, a threshold of 0.95 was used to exclude FinnGen samples whose relative chance of being part of the Finnish cluster was below the level. This method produced another 879 outliers. The figure below shows the first three principal components.

<figure><img src="https://3248549602-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwxE6DR0oal1nFglVz4Hy%2Fuploads%2FculWZK6vp5UVzUBQ8cIn%2Ffinngen_R12_analysis_document_GWAS.pdf-image-001.png?alt=media&#x26;token=362add92-8679-4a7f-86cb-298bb519d625" alt=""><figcaption></figcaption></figure>

FIN 1kg samples are in purple, while EUR 1kgp samples are in Blue. Samples in green are FinnGen samples who are flagged as being non Finnish, while red ones are considered Finnish.

### Kinship

Then all pairs of FinnGen samples up to second degree were returned. The figure below shows the distribution of kinship values.

<figure><img src="https://3248549602-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwxE6DR0oal1nFglVz4Hy%2Fuploads%2FyOzSp3hCWBuAPQy6K0Dy%2Ffinngen_R12_analysis_document_GWAS.pdf-image-002.png?alt=media&#x26;token=8bda0976-e513-4d45-aca8-d6806908dace" alt=""><figcaption></figcaption></figure>

Then, the previously defined “non Finnish” samples were excluded and 2 algorithms were used to return a unique subset of unrelated samples:

* one called *greedy* would continuously remove the highest degree node from the network of relations, until no more links are left in the network.
* one called *native*, based on a native implementation of python’s *networkx* package, performed on each subgraph of the network.

The largest independent set of either algorithm would be used to keep those sample, while flagging the others as “outliers” for the final PCA.&#x20;

Then, the subset of outliers who also belong to the set of duplicates/twins was identified.

### Final PCA

To compute the final step the Finngen samples were ultimately separated in three groups:

* 296,829 **inliers**: unrelated samples with Finnish ancestry.
* 203,908 **outliers**: non duplicate samples with Finnish ancestries, but who are also related to the inliers.&#x20;
* 19,473 **rejected** samples: either of non Finnish ancestry or are twins/duplicates with relations to other samples.&#x20;

Finally, the PCA for the inliers was calculated, and then outliers were projected on the same PC space, allowing to calculate covariates for a total of **500,737** samples.

<figure><img src="https://3248549602-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwxE6DR0oal1nFglVz4Hy%2Fuploads%2F6MCHilBcvVlKtA6lIi09%2Ffinngen_R12_analysis_document_GWAS.pdf-image-003.png?alt=media&#x26;token=2db2346e-dc97-480f-aa55-281188a90220" alt=""><figcaption></figcaption></figure>

## Sample filtering based on phenotype data

Of the 500,737 non-duplicate population inlier samples from PCA, we excluded 355 samples from analysis because of missing minimum phenotype data, and 34 samples because of failing sex check with F thresholds of 0.4 and 0.7. **A total of 500,348 samples were used for core analysis.** There are 282,064 females and 218,284 males among these samples.

## Further info

### Bayesian outlier detection

Documentation from the original developers of the algorithm can be found here: [http://www.well.ox.ac.uk/\~spencer/Aberrant/aberrant-manu](http://www.well.ox.ac.uk/~spencer/Aberrant/aberrant-manual.pdf).
