Question: (Closed) Removing space form fasta file header
0
gravatar for kudzu
5.1 years ago by
kudzu0
United States
kudzu0 wrote:

Could anyone suggest me the easier way (linux command line) to remove space(S) from header of the fasta file?

sequence • 3.4k views
ADD COMMENTlink modified 5.1 years ago by thackl2.8k • written 5.1 years ago by kudzu0
2
perl -lane "s/\s+//g if /^>/; print " file.fa > newfile.fa
perl -lane "s/\s+/_/g if /^>/; print " file.fa > newfile.fa
perl -lane "s/\s+/./g if /^>/; print " file.fa > newfile.fa
ADD REPLYlink modified 12 months ago by _r_am31k • written 5.1 years ago by Shicheng Guo8.5k

Hello kudzu!

Questions similar to yours can already be found at:

We have closed your question to allow us to keep similar content in the same thread.

If you disagree with this please tell us why in a reply below. We'll be happy to talk about it.

Cheers!

PS: 135035
ADD REPLYlink written 5.1 years ago by Michael Dondrup48k
3
gravatar for thackl
5.1 years ago by
thackl2.8k
MIT
thackl2.8k wrote:

This has been answered before: How to remove space in headers of fasta files

Since FASTA should not contain spaces anywhere else than in header, removing all spaces is the easiest/fastest way:

tr -d ' ' <in.fa >out.fa  # remove all spaces
tr ' ' '_' <in.fa >out.fa # replace spaces by _

If you want to change headers only:

sed '/^>/{s/ /_/g}' <in.fa >out.fa 
sed '/^>/{s/ \+/_/}' # replace only first occurance of (multiple) spaces
sed '/^>/{s/\s/_/g}' # \s will also target tabs
ADD COMMENTlink modified 12 months ago by _r_am31k • written 5.1 years ago by thackl2.8k

That was very quick and easy command to remove all spaces. Thank you very much for your quick response thackl (Y)

ADD REPLYlink modified 12 months ago by _r_am31k • written 5.1 years ago by kudzu0
Please log in to add an answer.
The thread is closed. No new answers may be added.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 981 users visited in the last hour