Problem in annotation function for visualization of points in PCA plot
1
0
Entering edit mode
16 months ago
Kshitij • 0

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).

enter image description here

Clustering PCA Bio3D Visualization R • 601 views
ADD COMMENT
0
Entering edit mode

It looks like in the example they don't actually create the annotation object. They do have:

anno <- pdb.annotate(hits$pdb.id)
head(anno[, c("resolution", "ligandId", "citation")])

which produces the correct data structure (matrix). You could use this with something like

color.vec <- ifelse(resolution < 2, 'red', 'green')
plot(pc.xray, col=color.vec)

but i can't tell from that page what they are coloring.

ADD REPLY
0
Entering edit mode
16 months ago

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=.

ADD COMMENT

Login before adding your answer.

Traffic: 1479 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6