change headers from fasta files
3
0
Entering edit mode
5.9 years ago

I have multifasta files containing sequences like these:

>16S_ribosomal_RNA
attgcaggtcagcatactgcagtgaattcgttcc

>16S_ribosomal_RNA
attgcaggtcagcatactgcagtgaattcgttcc

>16S_ribosomal_RNA
attgcaggtcagcatactgcagtgaattcgttcc

these sequences are contained in fasta files named as following :

Bacteria_especie_strain.fasta

and I would like that headers has the same name that the multifasta file :

>16S_ribosomal_RNA_Bacteria_especie_strain.fasta 
attgcaggtcagcatactgcagtgaattcgttcc

> 16S_ribosomal_RNA_Bacteria_especie_strain.fasta 
attgcaggtcagcatactgcagtgaattcgttcc

>16S_ribosomal_RNA_Bacteria_especie_strain.fasta 
attgcaggtcagcatactgcagtgaattcgttcc
sequence • 1.5k views
ADD COMMENT
3
Entering edit mode
5.9 years ago
cschu181 ★ 2.8k
awk -v fn="Bacteria_especie_strain.fasta"  '/^>/ { print $0"_"fn; next; } { print $0; }' Bacteria_especie_strain.fasta > Bacteria_especie_strain.fasta.modified_headers
ADD COMMENT
3
Entering edit mode
5.9 years ago
h.mon 35k

See answers from Question: Changing names of Fasta headers.

ADD COMMENT
1
Entering edit mode
5.9 years ago

Output from awk:

 $ awk   '/^>/ { print $0"_"FILENAME; next}1' Bacteria_especie_strain.fasta

>16S_ribosomal_RNA_Bacteria_especie_strain.fasta
attgcaggtcagcatactgcagtgaattcgttcc
>16S_ribosomal_RNA_Bacteria_especie_strain.fasta
attgcaggtcagcatactgcagtgaattcgttcc
>16S_ribosomal_RNA_Bacteria_especie_strain.fasta
attgcaggtcagcatactgcagtgaattcgttcc

output from sed and parallel:

$ parallel  'sed "/^>/ s/.*/&_{}/g"' {} ::: Bacteria_especie_strain.fasta 

>16S_ribosomal_RNA_Bacteria_especie_strain.fasta
attgcaggtcagcatactgcagtgaattcgttcc
>16S_ribosomal_RNA_Bacteria_especie_strain.fasta
attgcaggtcagcatactgcagtgaattcgttcc
>16S_ribosomal_RNA_Bacteria_especie_strain.fasta
attgcaggtcagcatactgcagtgaattcgttcc

input:

$ cat Bacteria_especie_strain.fasta 

>16S_ribosomal_RNA
attgcaggtcagcatactgcagtgaattcgttcc
>16S_ribosomal_RNA
attgcaggtcagcatactgcagtgaattcgttcc
>16S_ribosomal_RNA
attgcaggtcagcatactgcagtgaattcgttcc
ADD COMMENT

Login before adding your answer.

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