This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How can I save a text file in colon saperated file in r ?

I got a text file in a single column but I want in below format:

1:18.91304347 2:18.91304347 3:3.478260869 4:3.478260869 5:6.739130435 6:0.217391304 7:4.347826087 8:0.434782609 9:3.47826087 10:3.260869565 11:4.347826087 12:0.652173913 13:5 14:1.086956522 15:9.782608696 16:1.304347826 17:15.86956522 18:10.2173913 19:6.739130435 20:2.391304348
1 1:1.086956522 2:0.217391304 3:0.652173913 4:0.652173913 5:4.782608696 6:1.521739131 7:0.652173913 8:4.347826087 9:2.608695652 10:7.173913043 11:1.52173913 12:1.304347826 13:0.434782609 14:0.652173913 15:0.217391304 16:2.826086957 17:1.304347826 18:2.391304348 19:0 20:2.826086957

I got my out put in single column so if any one have idea how to save file in above format please tell me.

I try to count dipeptide from the multiple protein sequences which is in fasta formatted file.

My code is:

# read fasta sequences in file "sequences.fasta"
seqs <- read.fasta("multiple.fasta")
seqs

ls <- list(seqs)
ls

B <- lapply(seqs, function(x) count(x, 2, alphabet = s2c("acdefghiklmnpqrstvwy")))
B

names(B)
# get the list of the length of all sequences
ld1<- lapply(names(B), function(x){length(seqs[[x]])})
ld1

l<-data.frame(B)
l
tables=apply(l,2,table)
tables

dups=which(duplicated(tables))
dups

testframe <- subset(l, select = -c(dups))
testframe

# create a dataframe removing 1st column
test <- testframe[-1]

#finding dipeptide compositions
for(i in 1:6)
{
  s<-(test[,i]*(100))/(ld1[[i]])
  print(s)

  write.table(s, "C:/Users/PUJA/Desktop/Thesis/s.txt", sep="\t ", append = TRUE)

}
r

1 answer

You want to write the results as a character vector. You'll need to get everything in the format you want beforehand, possibly by subsetting the table and/or pasting with ":"

If you're all set up, write the object with write() as opposed to write.table().

Log in to answer this question.