#!/bin/bash

# makepanels.sh - Create PCD panels for blncbi query builder menus.

# 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=2
end=8

# infile is query term 2 
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/BOOL2/BOOL$i/g" |\
    sed -e "s/LPAREN2/LPAREN$i/g" |\
    sed -e "s/RPAREN2/RPAREN$i/g" |\
    sed -e "s/FEAKEY2/FEAKEY$i/g" |\
    sed -e "s/feakey2/feakey$i/g" |\
    sed -e "s/%Q2/%Q$i/g" |\
    sed -e "s/\"Q2/\"Q$i/g" |\
    sed -e "s/\"q2/\"q$i/g" |\
    sed -e "s/term\ 2/term\ $i/g" \
    >> $outfile
done
