0

I have a file A that contains accession number family name and name and file B that contains ID and sequences.

I want to use the accession number in B to retrieve the family name and virus name in A and add it to the second column in B.

Example

File A

NC_001348 PEPS Herpesviridae Human herpesvirus 3, complete genome.txt
NC_001350 PEPS Herpesviridae Saimiriine herpesvirus 2 complete genome.txt
NC_001491 PEPS Herpesviridae Equid herpesvirus 1, complete genome.txt
NC_001798 PEPS Herpesviridae Human herpesvirus 2 strain HG52, complete genome.txt
NC_001806 PEPS Herpesviridae Human herpesvirus 1 strain 17, complete genome.txt
NC_001826 PEPS Herpesviridae Murine herpesvirus 68 strain WUMS, complete genome.txt
NC_001844 PEPS Herpesviridae Equid herpesvirus 4, complete genome.txt
NC_001847 PEPS Herpesviridae Bovine herpesvirus 1, complete genome.txt
NC_001987 PEPS Herpesviridae Ateline herpesvirus 3 complete genome.txt
NC_002229 PEPS Herpesviridae Gallid herpesvirus 2, complete genome.txt

File B

NC_001348_71671_71760_KY215944.1    GCGCGGCTGGTGATGCAATGCGTGACCAGCTACTGGCGCAACTCGCGCTGCGCCGCCTTTGTGAACAGCTTCCCCATGGTGATGTACATC
NC_001350_89668_89757_HQ221963.1    CTTTCAGGATTTTCTGGCAGTTTTGCTGTCAAGAATGACATGATCTGGTGATGCCATATCTCAATATACAGCGCAGTGCTCACTGGTCTG
NC_001491_126502_126591_AF480884.1  AACGTGTCGGTGCGCACGGCCGTCAGGGCGAAGCCCGGGTGGATGTGGGCCTTGGTCTGCAGCACCAGCGACACCGGCGAGATCTTGTAC
NC_001798_97563_97652_AY714813.1    CGCAGGTGCCCGAAGACGTCGCAGACGGCCGCCCGCAGGGCCATGCACTGCATGGAGCCCGTGGTGCCGCCCGGCCCCCGGTCCAGGTGC
NC_001806_196955_197044_FJ483970.2  TCATCGATCTCAGTCTGTCGGCCGCTCCACGGCTCTGACTGGACTTTCCAAAGTACATACTGCAGTCAGAGCTGTCGAGCGGTTAACAGA

Expected Output

NC_001348_71671_71760_KY215944.1    Herpesviridae Human herpesvirus 3, complete genome  GCGCGGCTGGTGATGCAATGCGTGACCAGCTACTGGCGCAACTCGCGCTGCGCCGCCTTTGTGAACAGCTTCCCCATGGTGATGTACATC
NC_001350_89668_89757_HQ221963.1    Herpesviridae Saimiriine herpesvirus 2 complete genome  CTTTCAGGATTTTCTGGCAGTTTTGCTGTCAAGAATGACATGATCTGGTGATGCCATATCTCAATATACAGCGCAGTGCTCACTGGTCTG
NC_001491_126502_126591_AF480884.1  Herpesviridae Equid herpesvirus 1, complete genome  AACGTGTCGGTGCGCACGGCCGTCAGGGCGAAGCCCGGGTGGATGTGGGCCTTGGTCTGCAGCACCAGCGACACCGGCGAGATCTTGTAC
NC_001798_97563_97652_AY714813.1    Herpesviridae Human herpesvirus 2 strain HG52, complete genome  CGCAGGTGCCCGAAGACGTCGCAGACGGCCGCCCGCAGGGCCATGCACTGCATGGAGCCCGTGGTGCCGCCCGGCCCCCGGTCCAGGTGC
NC_001806_196955_197044_FJ483970.2  Herpesviridae Human herpesvirus 1 strain 17, complete genome    TCATCGATCTCAGTCTGTCGGCCGCTCCACGGCTCTGACTGGACTTTCCAAAGTACATACTGCAGTCAGAGCTGTCGAGCGGTTAACAGA
0

Command:

c=`awk '{print NR}' file2| sort -nr | sed -n '1p'`;for ((i=1;i<=$c;i++)); do j=`awk -v i="$i" 'NR==i{$1=$2="";print $0}' file1`; awk -v i="$i" -v j="$j" 'NR == i{$3=$2;$2=j;print $0}' file2; done| sed "s/complete genome.txt/complete genome/g"

output

c=`awk '{print NR}' file2| sort -nr | sed -n '1p'`;for ((i=1;i<=$c;i++)); do j=`awk -v i="$i" 'NR==i{$1=$2="";print $0}' file1`; awk -v i="$i" -v j="$j" 'NR == i{$3=$2;$2=j;print $0}' file2; done| sed "s/complete genome.txt/complete genome/g"
NC_001348_71671_71760_KY215944.1   Herpesviridae Human herpesvirus 3, complete genome GCGCGGCTGGTGATGCAATGCGTGACCAGCTACTGGCGCAACTCGCGCTGCGCCGCCTTTGTGAACAGCTTCCCCATGGTGATGTACATC
NC_001350_89668_89757_HQ221963.1   Herpesviridae Saimiriine herpesvirus 2 complete genome CTTTCAGGATTTTCTGGCAGTTTTGCTGTCAAGAATGACATGATCTGGTGATGCCATATCTCAATATACAGCGCAGTGCTCACTGGTCTG
NC_001491_126502_126591_AF480884.1   Herpesviridae Equid herpesvirus 1, complete genome AACGTGTCGGTGCGCACGGCCGTCAGGGCGAAGCCCGGGTGGATGTGGGCCTTGGTCTGCAGCACCAGCGACACCGGCGAGATCTTGTAC
NC_001798_97563_97652_AY714813.1   Herpesviridae Human herpesvirus 2 strain HG52, complete genome CGCAGGTGCCCGAAGACGTCGCAGACGGCCGCCCGCAGGGCCATGCACTGCATGGAGCCCGTGGTGCCGCCCGGCCCCCGGTCCAGGTGC
NC_001806_196955_197044_FJ483970.2   Herpesviridae Human herpesvirus 1 strain 17, complete genome TCATCGATCTCAGTCTGTCGGCCGCTCCACGGCTCTGACTGGACTTTCCAAAGTACATACTGCAGTCAGAGCTGTCGAGCGGTTAACAGA
  • Thanks Praveen Kumar BS, it works perfectly. I won't mind a python script too – Ibk Apr 8 at 19:28
  • Will post in python too KIndly upvote my answer – Praveen Kumar BS Apr 8 at 19:34
  • Hi Kumar, its like there is a little glitch. – Ibk Apr 8 at 20:59
  • Hi Kumar, Its like there is a little glitch. File A and B are not perfect match. The first nine characters of each line in File B are supposed to run through file A which are unique, then return the name of the accession number after PEPS and add it as second column to file B to form a new file. – Ibk Apr 8 at 21:04

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.