Home > Mobile >  Converting multiple text sequence files into Fasta files in R
Converting multiple text sequence files into Fasta files in R

Time:07-15

I have 100s of DNA sequence files that are text files, and i want to convert them in Fasta format. I have tried with cat but its not giving expected output. How can I convert these files into fasta format in R?

example :

file1.txt

ATCTACGTACGTGCATG


file2.txt

CGTAGCATTGCATGATC

Expected output

file1.fa

>file1
ATCTACGTACGTGCATG


file2.fa

>file2
CGTAGCATTGCATGATC

CodePudding user response:

I can do using the for loop, but I didn't find a package or more simplest way.

This approach is working.

  files1<-list.files(pattern = "*.txt")
  for (i in 1:length(files1))
  {
  logFile = read.table(paste0(files1[i]))
  
  write.table(rbind(paste0(">",files1[i]),logFile),paste0(files1[i],".fa"),row.names = FALSE,col.names = FALSE,quote = FALSE)
  
  }
  
  • Related