Bio3D-PCA calculation- using the tutorial as a guide, couldnt plot a figure
Here is my script. Last line does not work.. Couldnt figure out how to plot individual principal components. Any help would be appreciated.
library(bio3d)
dcdfile <- "proteinhex.dcd"
pdbfile <- "proteinhex.pdb"
dcd <- read.dcd(dcdfile)
pdb <- read.pdb(pdbfile)
ca.inds <- atom.select(pdb, elety="CA")
xyz <- fit.xyz(fixed=pdb$xyz, mobile=dcd, fixed.inds=ca.inds$xyz, mobile.inds=ca.inds$xyz)
pc <- pca.xyz(xyz[,ca.inds$xyz])
plot(pc, pc.axes=1:2, col=annotation[, 'color'])
Comments (6)
-
-
Hi Tugba,
Can you provide what kind of error message did you get from the last line? Also, could you get a plot properly with
plot(pc)
orplot(pc, pc.axes=1:2)
? Note that the 'annotation' variable from bio3d is only to illustrate the example shipped with bio3d and should not be used for other systems. In your case, you may replace it with some color vector derived from your data. For example, you could do clustering of your trajectory first and then plot it with colors by cluster IDs:hc <- hclust(dist(pc$z[, 1:2])) grps <- cutree(hc, k=3) plot(pc, pc.axes=1:2, col=grps)
Let me know if it solves your problem
-
Account Deleted Thank you so much! It worked! I was not getting any error messages. I managed to get other plots that I wanted. But that one was kind of problematic. So many thanks for your help. Would you also suggest me a documentation? I also need to find a way to save the numerical output such as vectors of pc to a file. I am not familiar with R.
-
Hi,
To write a variable to a binary file, try
save(pc, file='pc.RData')
. Next time when you start a new R session, you can easily load the data withload('pc.RData'
. Seehelp(save)
for more details.To write a vector/matrix to a plain ascii file, you may try
write.table()
. Here is an example from an old Q&A here: https://bitbucket.org/Grantlab/bio3d/issues/236/outputting-the-matrix-of-weightsI recommend the 'Quick-R' (http://www.statmethods.net/index.html) for beginners, although others may have better suggestions.
-
Please see the "New to R" section links here: http://thegrantlab.org/bio3d/user-guide
New to R
There are now numerous on–line resources that can help you get started using R. A number of these can be found from the main R website at http://www.r-project.org. We particularly like the following:
-
Try R: a nifty interactive R tutorial in your web browser http://tryr.codeschool.com/
-
An introduction to R: The offical R manual http://cran.r-project.org/doc/manuals/R-intro.pdf
-
Learn R: Learn by doing in your web browser (requires free registration) https://www.datacamp.com/
-
Google!
-
-
- changed status to resolved
- Log in to comment