gravatar for ceciliahermosilla

3 hours ago by

I have this DNAStringSet (genomes) and need to put each genome as an individual FASTA file in a directory, but that they remain StringSets of length=1. The name of each file is concatenated in a vector (names), since they are too many I created this loop:

n <- seq_len(length(names))
   for(i in 1:n){
      for(j in seq_len(length(names))){
         writeXStringSet(genomes[i],names[j])
      }
   }

and returned this:

>Warning message:
In 1:n : numerical expression has 195 elements: only the first used

I checked the results, the files where there with the right names but the sequence of all of them was the first one. I changed the loop:

for(i in seq_len(length(genomes))){
   for(j in seq_len(length(names))){
      writeXStringSet(genomes[i],names[j])
   }
}

No error appeared, but now all files contain the last sequence of the StringSet.

I'm new using R and the Biostrings package. Is there a way I could fix this or do something else, so I can get all the files with their corresponding genome on it?

Thank you in advance!

Sample of the objects:

>genomes
DNAStringSet object of length 3:
    width seq                                           names
[1] 47 TATAAAACACCCTCAATTCAAGGGTTTAATTTTTCACAATCATTAAA HP83
[2] 47 TAAAACACCCTCAATTCAAGGGTTTCATTTTTTAAAACTATTAAATA HPS49
[3] 47 AAAAACCTTGTTTTAGTCTTTTTTATAGATTTCATGTTCAAGTCTTC P49

>names <- c("HP83.fasta","HPS49.fasta","P49.fasta")



Source link