1

I have hundred PDB files that I want to loop through in the directory and carry out some editing operations and save them as new PDB files using R script. Right now, I am using the following code but unable to save the results as separate PDB files:

library(bio3d)
files <- list.files(path="/Users/s/chk/", pattern="*.pdb", full.names=TRUE, recursive=FALSE)
lapply(files, function(x) {
  pdb1 <- read.pdb(x) # load file
  pdb1$atom$chain[7872:11984] <- "C"
  pdb1$atom$chain[11986:15384] <- "D"
  pdb1$atom$chain[15743:23255] <- "E"
  pdb1$atom$chain[23614:27726] <- "F"
  pdb1$atom$chain[27728:31126] <- "G"
  pdb1$atom$chain[31485:35597] <- "I"
  pdb1$atom$chain[35599:39017] <- "J"
  out <- function(pdb1)
    # write to file
    write.pdb(out,"test.pdb")
})

What to change so it will save up as different PDB files ?

user438383
  • 5,716
  • 8
  • 28
  • 43
shome
  • 1,342
  • 1
  • 12
  • 30
  • Please don't post the same question in multiple different places. – user438383 Dec 28 '20 at 11:39
  • 3
    Does this answer your question? [Using lapply to apply a function over list of data frames and saving output to files with different names](https://stackoverflow.com/questions/17018138/using-lapply-to-apply-a-function-over-list-of-data-frames-and-saving-output-to-f) – user438383 Dec 28 '20 at 11:39

0 Answers0