insert weight values in multifasta file
1
0
Entering edit mode
8.9 years ago
Macho • 0

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
Assembly fasta RNA-Seq • 1.3k views
ADD COMMENT
1
Entering edit mode
8.9 years ago
iraun 6.2k

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).

ADD COMMENT
0
Entering edit mode

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.

ADD REPLY

Login before adding your answer.

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