R: How to use output of 'translate' function to write a table?

769 views Asked by At

I have a file (data.txt) that contains 2 DNA sequences (ORF):

data = readDNAStringSet(file="data.txt") 
data
# A DNAStringSet instance of length 2
# width seq                                                       names
#[1]  57 ATGACCCCCACCTCCATCCCCACACTTCTATCCCGCTGCCCCGCCTCTCTCCCCTAA  GPG
#[2]  54 ATGACCCATGAGCACCATGCAGCCAAAACCCTGGGAATCGGCAAAGCCATCTAG     PfK

I want to convert them to aminoacids:

t=vector(mode="list", length=length(data))
for (i in seq_along(data))
{
t[[i]]=translate(data[[i]])
}
t
#[[1]]
#19-letter "AAString" instance
#seq: MTPTSIPTLLSRCPASLP*

#[[2]]
#18-letter "AAString" instance
#seq: MTHEHHAAKTLGIGKAI*

then write a table and have an output using:

tt=do.call(rbind,t)
write.table(tt,"aa.txt",sep="\t\t")

but these commands don't work. I couldn't find the problem. How can I write a table?

Note: translate is a function from the [seqinr] and readDNAStringSet is a function from the [Biostrings].

1

There are 1 answers

0
sgibb On BEST ANSWER

I don't know why you need seqinr. Biostrings does everything you need.

library("Biostrings")

dna <- readDNAStringSet(file="data.txt")
aa <- translate(dna)

write.table(as.character(aa), file="aa.txt", sep="\t\t")

Maybe you want to use writeXStringSet instead of write.table.