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 ?