#!/bin/bash

# makepanels.sh - Create PCD panels for tbl2asn.blmenu.

# Synopsis: makepanels.sh infile

#    infile - a template file containing a PCD panel for the second query term
#        in either NCBINUC.blmenu or NCBIPROT.blmenu. The first query term has
#        to be edited by hand because it is arranged differently than the 
#        subsequent terms.
#        This script creates an output file called 'panels', that must be pasted
#        into the .blmenu file in a text editor.
#        
#        infile must be nuctemplate.txt if the panel is to be pasted into
#             NCBINUC.blmenu, or prottemplate.txt if the panel is to be
#             pasted into NCBIPROT.blmenu 

infile=$1
outfile=panels
begin=1
end=6

# infile is query term 1 
cat $infile > $outfile

# keep apending a copy of infile to the output, each time,
# incrementing the number of the query term in all relevant fields
for ((i=$begin+1; i <=$end; i++))
do
    echo $i
    cat $infile |\
    sed -e "s/Q1FIELD/Q${i}FIELD/g" |\
    sed -e "s/q1field/q${i}field/g" |\
    sed -e "s/Q1VAL/Q${i}VAL/g" |\
    sed -e "s/q1val/q${i}val/g" |\
    sed -e "s/q1/q${i}/g" |\
    sed -e "s/Q1/Q${i}/g" \
     >> $outfile
done
