How to extract FASTA headers in R
I have downloaded a reference uniprotkb FASTA file. How can I only extract the FASTA headers of each gene (raw-wise) into a CSV file using R?
• 2,260 views
•
link
1 answer
Here's one example using R:
library(seqinr)
fa <- read.fasta(file = "samples.fasta", seqtype = "DNA")
CON=file("output.csv", "w")
writeLines("genes", CON)
writeLines(names(fa), CON)
close(CON)
However, is R necessary in this case? Can you just use simpler UNIX tools?
echo "genes" > output.csv
grep ">" samples.fasta | cut -c2- >> output.csv
edit: if you want specific parts of the fasta headers, you will need to be more specific in your question
• 0 views
•
link
Log in to answer this question.
I came across this handy tool. CSV⬌FASTA https://cdcgov.github.io/CSV2FASTA/
This does not answer your question - it does not use R. Please accept the answer that addresses your question, do not add answers that explicitly break a requirement without specifying that the requirement is broken.
I'm moving this answer to a comment now.