'Separation of dihedral angles of the desired sequence in the protein

I have a list of pdbid and I want to separate the dihedral angles of some sequences in protein .

pdbid      st          en
101m    4.A.GLU 15.A.ALA
102m    4.A.GLU 15.A.ALA
103m    4.A.GLU 15.A.ALA
104m    4.A.GLU 15.A.ALA
105m    4.A.GLU 15.A.ALA
106m    4.A.GLU 15.A.ALA
107m    4.A.GLU 15.A.ALA
  • st is start of sequences en is end of sequences.

And after separating the dihedral angles, I want to write the corresponding pdbid in front of it.

I wrote the following code:

  library(bio3d)

  # PDB structure object as obtained from function read.pdb.
 pdb=read.pdb(df$pdbid[1])

  #Calculate all torsion angles for a given protein PDB structure object
tor=torsion.pdb(pdb)
 
            phi        psi
1.A.VAL -144.91395  137.473333
2.A.LEU -95.02097   149.7834
3.A.SER -82.68263   166.676942
4.A.GLU -62.53142   -36.263406
5.A.GLY -59.64632   -42.035533
6.A.GLU -68.69144   -40.23538
7.A.TRP -63.52969   -36.769049
8.A.GLN -64.80557   -38.512821
9.A.LEU -64.82472   -42.143097
10.A.VAL    -63.77383   -50.465974
11.A.LEU    -69.74235   -25.698665
12.A.HIS    -70.86863   -41.810178
13.A.VAL    -74.99987   -33.340633
14.A.TRP    -63.20999   -32.690374
15.A.ALA    -61.13164   -30.030673
16.A.LYS    -75.94714   -43.271738
17.A.VAL    -54.76125   -43.181171
18.A.GLU    -64.33161   -12.649873
19.A.ALA    -70.38802   -22.502227

   
    
#separating phi angles from "4.A.GLU" to "15.A.ALA"
phi=tor$phi[df$st[1]:df$en[1]]

#separating psi angles
psi=tor$psi[df$st[1]:df$en[1]]
print(cbind(phi,psi))

#Put the codes in the loop
for(i in 2:nrow(df))
{
  pdb=read.pdb(df$pdbid[i])
  tor=torsion.pdb(pdb)
  psi=tor$psi[df$st[i]:df$en[i]]
  phi=tor$phi[df$st[i]:df$en[i]]
  print(cbind(phi,psi))
}

But I get the following error:

Error in df$st[1]:df$en[1] : NA/NaN argument In addition: Warning messages: 1: NAs introduced by coercion 2: NAs introduced by coercion

str(df)
'data.frame':   9 obs. of  3 variables:
 $ pdbid: chr  "101m" "102m" "103m" "104m" ...
 $ st   : chr  "4.A.GLU" "4.A.GLU" "4.A.GLU" "4.A.GLU" ...
 $ en   : chr  "15.A.ALA" "15.A.ALA" "15.A.ALA" "15.A.ALA" ...
str(tor)
List of 11
 $ psi   : num [1:295] 158.1 137.5 149.8 166.7 -36.3 ...
 $ phi   : num [1:295] NA -144.9 -95 -82.7 -62.5 ...
 $ omega : num [1:295] -179 179 177 179 179 ...
 $ chi1  : num [1:295] 54.3 175.7 -81 62.3 175.1 ...
 $ chi2  : num [1:295] -171.5 NA 72.7 NA 64.4 ...
 $ chi3  : num [1:295] -72.1 NA NA NA 17 ...
 $ chi4  : num [1:295] NA NA NA NA NA NA NA NA NA NA ...
 $ chi5  : logi [1:295] NA NA NA NA NA NA ...
 $ alpha : num [1:295] NA -139.4 -123.2 -108.3 58.3 ...
 $ coords: num [1:3, 1:17, 1:295] 24.28 8.37 -9.85 24.4 9.86 ...
  ..- attr(*, "dimnames")=List of 3
  .. ..$ xyz: chr [1:3] "x" "y" "z"
  .. ..$ atm: chr [1:17] "N" "CA" "C" "O" ...
  .. ..$ res: chr [1:295] "  0.A.MET" "  1.A.VAL" "  2.A.LEU" "  3.A.SER" ...
 $ tbl   : num [1:295, 1:7] NA -144.9 -95 -82.7 -62.5 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:295] "  0.A.MET" "  1.A.VAL" "  2.A.LEU" "  3.A.SER" ...
  .. ..$ : chr [1:7] "phi" "psi" "chi1" "chi2" ...
r


Solution 1:[1]

Of course this go wrong.

phi <- tor$phi[df$st[1]:df$en[1]] take that apart and look at df$st[1] # [1] "4.A.GLU" and df$en[1] # [1] "15.A.ALA"

You then try to create a range to subset, but "4.A.GLU":"15.A.ALA" makes no sense, as you provide NaN "not a number".

The topic is a bit beyond my knowledge, but looking at the data structure it seems that you just want to grab all phi and psi values from the generated tor results for that particular pdbid.

So you just need phi <- tor$phi and psi <- tor$psi there to create the two lists respectively.

Solution

If I understand your for loop well, you just want to create the psi and phi values for all pdbid's in your df dataset. You could do it like this.

results <- sapply(df$pdbid, USE.NAMES = TRUE, simplify = FALSE, FUN = function(pdbid) {
  pdb <- read.pdb(pdbid)
  tor <- torsion.pdb(pdb)
  data.frame(tor[c("phi", "psi")]) # only tor[c("phi", "psi")] if you want a list of lists instead of a list of data.frames
})

str(results)

# List of 7
#  $ 101m:'data.frame': 295 obs. of  2 variables:
#   ..$ phi: num [1:295] NA -144.9 -95 -82.7 -62.5 ...
#   ..$ psi: num [1:295] 158.1 137.5 149.8 166.7 -36.3 ...
#  $ 102m:'data.frame': 311 obs. of  2 variables:
#   ..$ phi: num [1:311] NA -141.2 -91.4 -84 -61.2 ...
#   ..$ psi: num [1:311] 161 132 151 168 -38 ...
#  $ 103m:'data.frame': 272 obs. of  2 variables:
#   ..$ phi: num [1:272] NA -132.7 -93.4 -82.8 -60.5 ...
#   ..$ psi: num [1:272] 150 134 150.3 164.7 -33.1 ...
#  $ 104m:'data.frame': 335 obs. of  2 variables:
#   ..$ phi: num [1:335] NA -79.3 -76.4 -62.6 -64.2 ...
#   ..$ psi: num [1:335] 137.7 143.4 169.7 -38.4 -36.9 ...
#  $ 105m:'data.frame': 271 obs. of  2 variables:
#   ..$ phi: num [1:271] NA -99.7 -94.8 -50.3 -62.4 ...
#   ..$ psi: num [1:271] 167 157.1 159.7 -44.4 -33.5 ...
#  $ 106m:'data.frame': 300 obs. of  2 variables:
#   ..$ phi: num [1:300] NA -140.6 -92.5 -83.6 -60.8 ...
#   ..$ psi: num [1:300] 167.8 131.1 151.5 165.5 -36.9 ...
#  $ 107m:'data.frame': 292 obs. of  2 variables:
#   ..$ phi: num [1:292] NA -148.5 -89.6 -82.1 -65.2 ...
#   ..$ psi: num [1:292] 174.4 124.4 151.6 168.3 -31.7 ...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1