This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Examining Principal Components of Genetic Ancestry in R

Hi All,

I want to examine the population structure using genotyped data. Using the smartpca program from the eigensoft package, I calculated principal components of genetic data using 'smartpca -p mydata > pca.log' command. Finally, I have got a lot of stuff in the file name 'pca.log' including removal of outliers (5 iteration), Tracy-Widom statistics, top 10 eigvalues, 10 eigenvector..etc.

Now, i don't have any idea how to plot the population structure in R software package. Does anyone have R script to plot using the first two principal components of genetic ancestry?

Thank you for your time!

pca r

2 answers

I think this page has what you're looking for.

First of all, thank you very much for your helpful hint. I have seen it the link and tried to adopt it. However, it is not working. I understood all the outputs from 'smartpca -p Itamba.par > Itamba.out' should be in the file 'Itamba.out'. So, 'Itamba_PCA.evec' and 'Itamba_PCA.eval' were not created as separate output file and I couldn't find inside 'Itamba.out' output file. Is there a way to create these two output files from the main output file ('Itamba.out')? Becuase it has been used separately.

Thank you in advance.

Not all the output is in one file. The output file names are specified in a configuration file. In this example, the configuration file is called Itamba.par and in this file, the file 'Itamba_PCA.evec' (containing the PCs/eigenvectors) should be specified as value for the parameter named 'evecoutname' i.e. as
'evecoutname:'Itamba_PCA.evec'. Same for eigenvalues and parameter 'evaloutname'. These parameters should be required so check that you have specified the correct file name/path and/or that you don't get any error message.

Samples Eigenvector1 Eigenvector2 Eigenvector3 ... EigenvectorX

Sample1 Xcoord_____Ycoord_____Zcoord

Sample2 Xcoord_____Ycoord_____Zcoord

. . .

SampleN Xcoord_____Ycoord_____Zcoord

Plot 1 point for each sample using two of the three coordinates. Or plot all three at the same time using this package: https://cran.r-project.org/web/packages/pca3d/pca3d.pdf

Thank you. You gave me hint to plot 3D. What I need is to plot 2D?

Log in to answer this question.