0

I have set of files in a folder as follows :

nlb_1.pdb
nlb_2.pdb
nlb1_1.pdb
nlb1_2.pdb

How to access all the files in the folder in rscript and execute following commands for each of the files :

library(bio3d)
nlb_1 <- read.pdb('nlb_1.pdb',multi = TRUE)
ca.inds_nlb_1 <- atom.select(nlb_1,elety = 'CA')
shome
  • 1,342
  • 1
  • 12
  • 30

2 Answers2

0

First, you need to make a temp vector of the files in your folder:

temp = list.files(path = "path/to/your/folder", pattern="*.pdb")

Then, lapply the read.pdb function to read them in a list that here we call datasets

datasets = lapply(temp, read.pdb, multi = TRUE)

Then you can loop through your datasets applying the function you like.

David Jorquera
  • 2,046
  • 12
  • 35
0

just use the list.files command.

files=list.files(desired_folder,full=TRUE,pattern='pdb$')

library(bio3d)
processed_files=lapply(files,function(x){
       temp=read.pdb(x,multi=TRUE)
       atom.select(temp,elety='CA')
})

the elements in the list will be result of the process from your files.

G.Fernandes
  • 321
  • 2
  • 4