8 months ago by
You can do it with base R. One way of doing it is first transposing the TPM count matrix (assuming you want to run PCA on the samples rather than the genes), centering it, then doing an SVD and subsequently plotting the first and second columns of the u matrix (assuming you are interested in the first and second principal components. Alternatively, use the prcomp() function instead of SVD and plot the first and second column of the x matrix. Both should yield the same pattern (note that the values will not be the same, but the pattern will).
tpm_centered <- t(tpm-rowMeans(tpm))
tpm_svd <- svd(tpm_centered)
tpm_prcomp <- prcomp(tpm_centered)
For more information, you might want to check out this tutorial: http://genomicsclass.github.io/book/pages/pca_svd.html