1

I have a fasta file (seq.fa) which is a standard file format for genetic info, like so:

>TR1|c0_g1_i1
GTCGAGCATGGTCTTGGTCATCTTCCTTTCAAAGAA
>TR6|c0_g1_i1
GTGGAATATCGCCAGTGACCATCACTGATTAACCTG

I also have a file with names matching the headers (">TR..." names):

TR1|c0_g1_i1    scaf0432344_50037.734_wgs
TR6|c0_g1_i1    scaf0159424_10142.072_wgs

I need to make the "scaf0..." identifiers the first thing coming after the ">" file in the seq.fa.

I want to keep the "TR..." identifiers which are unique to each of my sequences, like so:

>scaf0432344_50037.734_wgs|TR1|c0_g1_i1
GTCGAGCATGGTCTTGGTCATCTTCCTTTCAAAGAA
>scaf0159424_10142.072_wgs|TR6|c0_g1_i1
GTGGAATATCGCCAGTGACCATCACTGATTAACCTG

The names file is in the same order as the sequences file!

Haven't tried anything since I'm not trained and have no idea what I'm doing :/

  • Is the first blockquote the contents of a single file? Do you want to /replace/ the TR... thing by the scaf0...? Are the TR... lines unique in the first file? Are they in the same order in both files? – L. Levrel Mar 14 '16 at 14:57
1

With awk

awk 'FNR==NR{
  a[">"$1]=$2;next
}
$1 in a{
  sub(/>/,">"a[$1]"|",$1)
}1' file2 seq.fa

Get the scaf value from file2 and save it in an array a with index ">"$1.

If $1 of seq.fa is an index in array a substitute the $1 to include the scaf value a[$1] after >.

Then print all lines in seq.fa

  • can you please explain your answer. It will take ages for me to understand this by myself. – Pacifist Mar 14 '16 at 16:43
1

As variant

join <(paste - - <sqa.fa | cut -c2-) name -o 2.2,1.1,1.2 |
sed 's/^/>/;s/\s/|/;s/\s/\n/'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.