Edit solution: https://tejashree1modak.github.io/bioblogs/fasta_rename/
I am looking to rename my scaffolds using a scaffold_mapping.txt file in unix where the .txt file looks like:
$ head scaffold_mapping.txt
>#ID_covAvg_fold_lengthLength
>scaffold_1_c1_cov61.3780_length417825
>scaffold_3_c1_cov45.0025_length77714
>scaffold_4_c1_cov84.2432_length70007
>scaffold_5_c2_cov57.6219_length67890
>scaffold_6_c1_cov331.1665_length65908
>scaffold_7_c1_cov138.5574_length64984
>scaffold_9_c1_cov77.1170_length59223
>scaffold_2_c2_cov51.1554_length55365
>scaffold_11_c1_cov44.1476_length53538
Each scaffold in the fasta file is currently named like this:
> scaffold_1_c1
And I would like their names to match the scaffold_mapping.txt file, so that the previous example would then be:
> scaffold_1_c1_cov61.3780_length417825
I hoped it'd be easy with sed but the '>' is complicating matters
$ sed -f scaffold_mapping1.txt assembly.contigs.fasta > output1.fasta
sed: file scaffold_mapping1.txt line 1: unknown command: `>'
It's not that "the '>' is complicating matters", you're just telling sed to interpret a file that doesn't contain a sed script.
The question isn't clear but best I can tell this is what the OP wants, using any POSIX awk:
which will output the posted expected output:
from the posted sample input.