Extract first and last column of fasta-header
3
0
Entering edit mode
2.4 years ago

Hi everyone,

I have a multi-fasta file name multi.fasta with the following structure:

>A 124 B
ATCGTA...
>C 567 D
GTCAG...

My goal is to create a new file, with the new fasta-headers containing only the first and last column. If I use

awk -F" " '/>/ {print $1,$(NF)}' multi-fasta > modified_multi-fasta

This will print the fasta headers with the first and last columns, but won't print the nucleotide sequences. Can you guys please help me out?

sequence • 1.2k views
ADD COMMENT
2
Entering edit mode
2.4 years ago
 awk '/^>/ {print $1,$(NF);next;} {print;}' 
ADD COMMENT
1
Entering edit mode
2.4 years ago
$ awk '/^>/{$2 =""}1' test.fa

>A  B
ATCGTA...
>C  D
GTCAG...

$ awk '/^>/{print $1,$NF}!/>/' test.fa
$ cut -f1,3 -d" " test.fa
$ sed -r '/^>/ s/\s.*\s/ /1' test.fa
$ tr -d 0-9 <test.fa | tr -s " "

>A B
ATCGTA...
>C D
GTCAG...
ADD COMMENT
0
Entering edit mode
2.4 years ago
Hugo ▴ 380

You can use the "Rename header / Multipart header" operation of SEDA (https://www.sing-group.org/seda/manual/operations.html#multipart-header), it is very useful for this kind of FASTA headers.

ADD COMMENT

Login before adding your answer.

Traffic: 2437 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