Hi there,

I’ve been using the dba.PCA function (Package *DiffBind* version 1.14.6) in the standard way described in the documentation. So far, I have two very related questions:

1. How can I retrieve the scores, loadings, eigenvalues from dba.PCA?

2. I’m interested in understanding how dba.PCA works. To do so I’ve unsuccessfully tried to recreate the PCA myself, the results are closed but not identical. I’m guessing that there are other steps in between or perhaps a different implementation of PCA that you’re using . Could you please take a look at my code ? Ideally I would like to recreate outside of dba.PCA each of the internal steps in the function

`samples =dba(sampleSheet = "sample_sheet_all.csv")`

samples = dba.count(samples,score = DBA_SCORE_READS)

`#Retrieve read count data`

`peaks.init.ranges<-dba.peakset(samples, bRetrieve=TRUE)`

`#Create a matrix with the read counts (there might be a more direct way of creating the inputPCA_matrix)`

inputPCA = mcols(peaks.init.ranges)

inputPCA = as.data.frame(inputPCA)

inputPCA_matrix = data.matrix(inputPCA)

`#Transpose matrix so that each row is a sample and the columns are read counts`

inputPCA_matrix=t(inputPCA_matrix)

#It uses the covariance matrix by default

pr.res=prcomp(inputPCA_matrix)

scores = as.data.frame(pr.res$x)

biplot(pr.res)

Many Thanks,

Renan Escalante-Chong

Hi Rory,

Sorry to dig up an old post but I had a follow up question; if you transpose the matrix as Renan suggested, wouldn't

`pr.res$rotation[,1:2]`

give you the loadings of the peaks, not of the samples?I've been trying to replicate Renan's code and I get the same PC contributions as in the diffbind PCA plot only when I use the non-transposed matrix.

- Brook

`DiffBind`

doesn't transpose the matrix.-R