Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing fasta files using R package seqinr?

Tags:

r

fasta

When I use write.fasta in seqinr, the file that it outputs looks like this:

>Sequence name 1

>Sequence name 2

>Sequence name 3
...etc

Sequence 1 Sequence 2 Sequence 3 ...etc

In other words, the sequence names are all at the beginning of the file, and then the sequences are output together at the end of the file.

What I'd like to do is this:

>Sequence name 1
Sequence 1
>Sequence name 2
Sequence 2
>Sequence name 3
Sequence 3
...etc

Is that possible with write.fasta?

like image 327
Jennifer Collins Avatar asked Aug 06 '12 00:08

Jennifer Collins


2 Answers

I got stuck with this and got some help from a friend. You need to define the sequences in a list here is an example of code where the input from maxquant output is a csv with a column called sequence and a name column called 'leading razor protein':

library(tidyverse)
library(seqinr)
MU = read_csv('data.csv')
seqs = as.list(dplyr::pull(MU, Sequence))
names = dplyr::pull(MU, `Leading razor protein`)
write.fasta(seqs, names, "MU.fasta",
            open = "w", as.string = FALSE)
like image 104
Denis Avatar answered Sep 28 '22 10:09

Denis


I was having a similar problem. What I did was to convert the vector that contained the sequences to a list and it worked fine.

e.g., write.fasta(as.list(seq),names,file)

like image 31
Mayela Avatar answered Sep 28 '22 11:09

Mayela