I am trying to replicate the Principal Component Analysis (PCA) method for a set of proteins using Bio3D in R to examine the relationship between different structures based on their equivalent residues. This is the link to the documentation of PCA in the Bio3D package - http://thegrantlab.org/bio3d_v2/tutorials/principal-component-analysis#:~:text=different%20analysis%20methods%3F-,Principal%20Component%20Analysis%20(PCA),-Following%20core%20identification When I run the final plotting step
plot(pc.xray, col=annotation[, "color"])
I face the following issue:
Error in annotation[, "color"] :
object of type 'closure' is not subsettable
I can see the annotation function is of type of closure and cannot be used in R-4.2.0 (The version of R I'm using). I wanted to know, if there is some alternative to this function. Basically, I want to visualise different groups of points in different colours in the PCA plot as they have done in this figure (Red and green).
1 answer
I think, this is an error in the documentation / tutorial.
annotation[, "color"]
is the notation one would use to select a column named color from a data.frame called annotation.
Because this data.frame is never created throughout the tutorial, annotation then resolves to a function of the same name. You can try this with any of the default functions, for example which():
> which[,"color"]
Error in which[, "color"] : object of type 'closure' is not subsettable
> which
function (x, arr.ind = FALSE, useNames = TRUE)
{
wh <- .Internal(which(x))
if (isTRUE(arr.ind) && !is.null(d <- dim(x)))
arrayInd(wh, d, dimnames(x), useNames = useNames)
else wh
}
<bytecode: 0x141a7f860>
<environment: namespace:base>
But of course we can treat which like an ordinary variable name and assign a data.frame to it. This is done here for demonstration purposes only and generally a bad practise.
> which <- data.frame(color=1)
> which[,"color"]
[1] 1
> which
color
1 1
Now, it is possible to use which[,"color"].
To fix your plot, you have to provide a vector of color values to col=.
Log in to answer this question.
It looks like in the example they don't actually create the
annotationobject. They do have:which produces the correct data structure (matrix). You could use this with something like
but i can't tell from that page what they are coloring.