I need to extract sequences one after another consecutively from a large fasta files (multiple fasta files) and each extracted files to be saved in new fasta file (I mean the first sequence extracted from multiple fasta file to be saved as gene1 and second sequence extracted from multiple fasta file to be saved in another file and so on). For that, I tried a script like this,
for file in *.fasta do cat "$file" \
| awk '/^>/ {printf("%s%s\t",(N>0?"\n":""),$0);N++;next;} \
{printf("%s",$0);} \
END {printf("\n");}' \
| awk '{if ( NR==1 ) print $0;}' \
| awk '{print $1"\n"$2}' | uniq > "new_${file}"
But, its not serving my purpose. Firstly, I could not loop my sequence extraction procedure from multiple fasta file and save as gene1 and gene2 and so on.
For example,
I have fasta files as follows,
org1.fasta
>locus1
ATGCGTAGAG
>LG12
TATGCATGAT
>bpl
TAGATGGAT
org2.fasta
>ysr
ATGTAGCGA
>inc
TGATCTATG
>pym
ATGCATAGA
org3.fasta
>siv
TAGTAGTAT
>tdp
ATGAGTCGA
>tem
ATGCTHATG
I need to extract first positioned sequences from all the org1.fasta org2.fasta and org3.fasta
files and save in a new file gene1.fasta
and second positioned sequences as gene2.fasta
and third positioned sequences to be saved as gene3.fasta
.
Expected output,
gene1.fasta
>locus1
ATGCGTAGAG
>ysr
ATGTAGCGA
>siv
TAGTAGTAT
gene2.fasta
>LG12
TATGCATGAT
>inc
TGATCTATG
>tdp
ATGAGTCGA
gene3.fasta
>bpl
TAGATGGAT
>pym
ATGCATAGA
>tem
ATGCTHATG
Please help me to do the same. Thanks in advance.