0
votes

I have my code below that I am using to generate multiple fasta files from an alignment and a tree. I would like to write these multiple fasta files in individual directories, but my code is writing the folder and file side by side, instead of writing the file inside the folder. Thank you in advance.

l = 182
i = 1
repeat {
  a = (tree[[i]]$tip.label)     #sequences names
  b = div_seqs[names(div_seqs) %in% a]   #sequences
  mylabel <- "seqs" 
  tempdir = dir.create(paste0(mylabel, "_", i))
  myfile <- (paste0(mylabel, "_", i, ".fas"))
  file.path(tempdir(), write.fasta(b, a, file = myfile, open = "w", nbchar = 600, as.string = FALSE))
  i = i+1
  if (i==l+1){
    break
  }
} ```

1

1 Answers

0
votes

I managed to find a way:

l = 182
i = 1
repeat {
  setwd(folder)
  a = (tree[[i]]$tip.label) 
  b = div_seqs[names(div_seqs) %in% a] 
  mylabel <- "seqs" 
  dir.create(paste0(mylabel, "_", i))
  myfile <- (paste0(mylabel, "_", i, ".fas"))
  setwd(paste0(folder, "/", mylabel, "_", i))
  write.fasta(b, a, file = myfile, open = "w", nbchar = 600, as.string = FALSE)
  i = i+1
  if (i==l+1){
    break
  }
} ```