This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to remove the header line with ">" in a fasta file

Hi,

I am a beginner in bioinformatics. I have a fasta file like below (plz ignore the "|")

> Chr3:183153228-183153246
TGGAAAGGACGAAACACCGCG
> Chr3:183286843-183286861
CTAGAAATAGCAAGTTAAA

How do I remove the header so that I can extract the sequence

TGGAAAGGACGAAACACCGCG
CTAGAAATAGCAAGTTAAA

Thank you for your help.

sequencing genome

3 answers

On Linux grep -v ">" file name

Just as an alternative

sed '/^>/d' foo.fa > out.fa

If you just want to remove all lines starting with ">", you could just use grep, among other options.

grep -v ">" file.fasta > file_without_header.txt

I am wondering why do you want to do that. If you erase that line, all of your sequences will be mixed up without any distinction one to the other unless all of them use a single line. In addition, most programs can handle that line by maintaining the identity of each sequence

I agree, what's your reasoning for doing this?

In fact my point of why would one want to do that, what is the motivation behind it.

This was recently discussed in a similar thread on Biostars and I had posted the reason below, which I will reproduce here.

Reason I do this sometimes is to cluster (sort|uniq) and/or count number of unique sequences.

If you want to do that, you can pipe everything through: grep -v '>' file.fasta | sort | uniq | wc -l to get the number of unique sequences, or grep -v '>' file.fasta | sort | uniq -c to get the number of times each sequence appears. However, clustering would be different than counting. The examples here gets you counts, if you want to cluster (you'll want to change the headers), than you would need some script to do so. I recommend biopython to parse your sequences for ease of use. Again, all assuming the op is on linux, and no coding experience. Alternatively, you can use collapser from fastx_toolkit

Can you clarify what is the meaning of clustering in this thread?

Log in to answer this question.