How to convert string into fasta using bash?
2
0
Entering edit mode
6.8 years ago
SaltedPork ▴ 170

Hi, I have a string of a fasta file (see below). You can see it's already in a fasta format, but its got spaces in the ID, and has newline characters. I have a Perl solution for this, but it's a bit hokey. I was wondering if any of you have the bash skills to turn this into a regular fasta?

Input:

">GA1redu 691-707f 57.9 product 2894bp 2006\r\nGCAGGACTCGGCTTGCT\r\n>HIVRES2redu \r\nGCTCTTGATAAATTTGATATGTCCAT"

Ideal Output:

>GA1redu 691-707f 57.9 product 2894bp 2006
GCAGGACTCGGCTTGCT
>HIVRES2redu
GCTCTTGATAAATTTGATATGTCCAT
fasta perl bash string • 2.3k views
ADD COMMENT
2
Entering edit mode

Another way is to use sed - echo -e '.....' | sed 's/\r//g' - which remove "\r" in your text.

ADD REPLY
3
Entering edit mode
6.8 years ago
echo -e '>GA1redu 691-707f 57.9 product 2894bp 2006\r\nGCAGGACTCGGCTTGCT\r\n>HIVRES2redu \r\nGCTCTTGATAAATTTGATATGTCCAT' | tr -d '\r'
ADD COMMENT
0
Entering edit mode

Pierre mate, I feel pretty silly given how simple the solution is. Thanks!

ADD REPLY
2
Entering edit mode
6.8 years ago
Paul ★ 1.5k

Or very easy change field separator "\r\n" to new one "\n" in awk like: echo -e '.....' | awk '$1=$1' FS="\r\n" OFS="\n" this is very easy to read and understand.

ADD COMMENT

Login before adding your answer.

Traffic: 1795 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6