Read, concatenate and merge the multiple fasta sequence files in R
1
0
Entering edit mode
6.6 years ago
3335098459 ▴ 30

Hi everyone,

I am using Windows and R-Studio. I am looking for a particular R-package or commands to read, write, concatenate and relabel the sequences in a fasta formatted file. I know other GUI softwares but I need to perform this in R.

Please help me. Regards Awan

R genome sequence • 5.0k views
ADD COMMENT
2
Entering edit mode

Did you take a look at seqinr package ? read.fasta and write.fasta are include, maybe there are functions to relabel and concat ( https://cran.r-project.org/web/packages/seqinr/seqinr.pdf ).

See also seqRFLP

ADD REPLY
2
Entering edit mode
6.6 years ago
ATpoint 85k

For writing fasta to disk, you can use:

Write.Fasta <- function(Sequences, Names, FastaPath){
  if (length(Sequences) != length(Names)) stop="Sequences and Names of unequal length!"
  X <- data.frame(paste(">", Names, sep=""), Sequences)
  D <- do.call(rbind, lapply(seq(nrow(X)), function(i) t(X[i, ])))
  write.table(x = D, sep="\n", col.names = F, row.names = F, quote = F, file = FastaPath)
}

## Example:
Write.Fasta(Sequences = my.seqs, Names = my.names, FastaPath = "/Path/To/file.fa")
ADD COMMENT

Login before adding your answer.

Traffic: 2489 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6