reading multiple PDB files with Bio3D

Issue #338 resolved
sanvi created an issue

I would like to read the multiple PDB files from a folder and would like to calculate the radius of gyration of each PDB file.

I calculated the radius of of gyration for a single file using the following program.

data<- read.pdb("/home/sanvi/Desktop/4q21.pdb")
mass <- rep(12, length(data$xyz)/3)
rgyr(data, mass)

For multiple files, I used the following code.

list <-  list.files(path="/home/sanvi/Desktop/pdbs", pattern=".pdb")
for(i in 1:length(list)){

  d2 = read.pdb(list[i])
  mass <- rep(12, length(d2$xyz)/3

  rgyr(d2,mass)}

Error: unexpected symbol in:
"                
                rgyr"

How can I calculate the radius of gyration for multiple PDB files?

Comments (12)

  1. Xinqiu Yao

    Hi,

    Please check your codes carefully and make sure they are free of bugs. For example, you may need full.names=TRUE in list.files(). Also, you have missed a ")" in "mass <- ...".

    Another (faster) way is using lapply to loop over all pdb files. For example,

    files <- list.files('/home/sanvi/Desktop', '.*\\.pdb$', full.names=TRUE)
    rgs <- lapply(files, function(x) {
        data <- read.pdb(x)
        mass <- rep(12, length(data$xyz)/3)
        rgyr(data, mass)
    })
    
  2. sanvi reporter

    Hi Xin-Qiu Yao,

    Thank you very much for your help! When I tried your code, I get the following error.

    Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : 
      scan() expected 'a real', got '3-0.52' 
    
  3. Xinqiu Yao

    Hi,

    Make sure the files contains the pdb files you want. The code I showed above was just an example and you need to check e.g. the path is exactly where you stored your pdb files!

  4. Log in to comment