This is a test version of Biostars. For the public version, visit https://www.biostars.org.
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?

r

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.

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

Log in to answer this question.