If they are not in the same order, you may use unix sort on your fasta (e.g. Pierre Lindenbaum answer here) and on your weights files.
• 0 views
•
link
Hello, I would like to know if there is a way to insert the weight information from a file in each fasta header of a multifasta file, example:
File 1:
>header_1
CACGGTGGGATCGACCTTTTGCCGCTCGAGGGATTTCTGCACCCTGCCGA
>header_2
TGGAACAAGGCCGGCCTGCGCGGCTAGGTGATCAACAAGGGGTTCAACGG
>header_3
GCGAAAGCGATACCTGGACTCGCAGAACGAAGACCTGGCCGAAGCGGTGG
>header_4
GGTTTAGAACGTCGTGAGACAGTTCGGTCCCTATCTGCCGTGGACGTTTG
File 2:
>header_1 weight=5
>header_2 weight=7
>header_3 weight=9
>header_4 weight=1
Output:
>header_1 weight=5
CACGGTGGGATCGACCTTTTGCCGCTCGAGGGATTTCTGCACCCTGCCGA
>header_2 weight=7
TGGAACAAGGCCGGCCTGCGCGGCTAGGTGATCAACAAGGGGTTCAACGG
>header_3 weight=9
GCGAAAGCGATACCTGGACTCGCAGAACGAAGACCTGGCCGAAGCGGTGG
>header_4 weight=1
GGTTTAGAACGTCGTGAGACAGTTCGGTCCCTATCTGCCGTGGACGTTTG
Are you looking for something like this?
awk 'BEGIN{RS=">"}NR>1{sub("\n","\t"); gsub("\n",""); print RS$0}' file.fa | paste - weights.txt | awk -F'\t' '{print $3"\n"$2}'
This command only will work assuming that the order in the sequences of fasta file and the order of weigths is the same (as your example).
If they are not in the same order, you may use unix sort on your fasta (e.g. Pierre Lindenbaum answer here) and on your weights files.
Log in to answer this question.