#!/bin/bash
# Set the PBS info.
#PBS -N Predict3_DIRECTORY_STRING
#PBS -l nodes=1:ppn=4:long,walltime=48:00:00
#PBS -q batch
#PBS -j oe
cd $PBS_O_WORKDIR
source ../../../../Utilities/Scripts/RunScriptTools || echo 'Internal Server error. Please contact the website administrator.' > errors.txt #include common functions, including sendResultsEmail.
calcStarted 'Predict3' 'Predict a Secondary Structure Common to Three or More Sequences' 'DIRECTORY_STRING' 'EMAIL_TO'
DIRECTORY=DIRECTORY_STRING
FULLCOMMAND="COMMAND_STRING"
FULLHTML="COMMAND_HTML_STRING"
NUMSEQS=NUM_SEQS_STRING
######################################################################
# Do the multilign calculation.
######################################################################
# Create the unique script variables necessary for this calculation.
COMMAND=`echo $FULLCOMMAND | cut -d ';' -f '1'`
HTMLCOMMAND=`echo $FULLHTML | cut -d ';' -f '1'`
# Run the main calculation command.
runTool multilign-smp $COMMAND
# For each input sequence, create its results files and individual HTML page in a separate subfolder.
typeset -i i SEQS;
let SEQS=NUMSEQS;
let num=1;
while (( num <= SEQS )); do
# Make the next subfolder and move the relevant files into it.
# Then move to the subfolder.
mkdir seq${num};
mv multilign${num}.ct seq${num}/multilign.ct
cd seq${num}
# Create the comprehensive PS and PDF files.
runTool draw multilign.ct multilign.ps
if [[ ! -s ../errors.txt ]]; then ps2pdf multilign.ps multilign.pdf 1>/dev/null 2>>../errors.txt; fi
# If only one structure is present, create a JPEG and SVG file to be available to the user.
# Otherwise, split the CT file into individual structures and make CT, PS, PDF, and SVG files for each structure.
# Individual JPEG files are not created because they take too long and occupy too much space; they are made only if and when the user requests them.
NUMSTRUCTURES=0
if [[ ! -s ../errors.txt ]]; then
NUMSTRUCTURES=`grep -r showpage multilign.ps | wc -l`
if (( $NUMSTRUCTURES == 1 )); then
if [[ ! -s ../errors.txt ]]; then gs -dNOPAUSE -dBATCH -q -r300 -dJPEGQ=100 -sDEVICE=jpeg -sOutputFile=multilign.jpeg multilign.ps 1>/dev/null 2>>../errors.txt; fi
runTool draw multilign.ct multilign.svg -n 1 --svg
else
if [[ ! -s ../errors.txt ]]; then
SEQLENGTH=`head -n 1 multilign.ct | awk '{print $1}'`
let SEQLENGTH++;
awk '{print > (NR%"'"$SEQLENGTH"'"?i:i++)".ct";}' i=1 multilign.ct
fi
typeset -i i END;
let END=$NUMSTRUCTURES;
let i=1;
while (( i <= END )); do
runTool draw multilign.ct ${i}.ps -n $i
if [[ ! -s ../errors.txt ]]; then ps2pdf ${i}.ps ${i}.pdf 1>/dev/null 2>>../errors.txt; fi
runTool draw multilign.ct ${i}.svg -n $i --svg
let i++;
done
fi
fi
# If no errors occurred in results files generation, create a results page using a templated HTML file.
# If no structures were generated, use a static notification HTML page as the results page.
# If only one structure was generated, place it in a specialized static HTML page.
# If multiple structures were generated, place it in a dynamic, expandable HTML page.
# If one or more structures were made, place the proper interface name, results directory, and command line in the results page.
if [[ ! -s ../errors.txt ]]; then
if grep -Fqs "contains no pairs" multilign.svg
then
cp ../../../../Utilities/Pages/NoStructures.html Results.html
rm -f multilign*
else
if (( $NUMSTRUCTURES == 1 )); then
copyTemplate ResultsPageSingleCTSingleStructure Results.html
else
copyTemplate ResultsPageSingleCTManyStructures Results.html
sed -i "s@STRUCTURE_NUMBER@$END@g" Results.html
awk '/download structure 1 links/,/structure 1 links end here -->/{print}' ../../../../../Utilities/Templates/ResultsPageSingleCTManyStructures.html > individualDiv.txt
typeset -i i END;
let END=$NUMSTRUCTURES;
let i=1;
while (( i <= END )); do
sed "s/1/$i/g" individualDiv.txt >> extendedDivs.txt
let i++;
done
sed -i '/download structure 1 links/,/structure 1 links end here -->/d' Results.html
sed -i "N;/Download Individual Structures/r extendedDivs.txt" Results.html
fi
fi
sed -i "s@FULL_RESULTS_DIRECTORY@ResultsPages/$DIRECTORY/seq${num}@g" Results.html
fi
# If an error did occur in results file generation, create an error page using a templated HTML file, delete all generated files, and break out of the loop.
if [[ -s ../errors.txt ]]; then
#copyTemplate Error ../Results.html
#sed -i "N;/errorText/r ../errors.txt" ../Results.html
rm -f ../Results.html
cd ..
rm -rf seq*
break
fi
# Move back to the main directory and increment the loop.
cd ..
let num++;
done
# If an error results page was not already made, put the results pages together into one big one.
if [[ ! -s Results.html ]]; then
copyTemplate ResultsPageManyAlignedStructures Results.html
sed -i '/image box starts/,/command line ends/d' Results.html
let num=1;
while (( num <= SEQS )); do
echo "
Structures derived from sequence $num:
" > combinedTemp.txt
sed -n "/image box starts here/,/download links end here/p" seq$num/Results.html >> combinedTemp.txt
echo "
" >> combinedTemp.txt
sed "s@id=\"@id=\"$num@g" combinedTemp.txt >> combined.txt
sed -i "s@src=\"INTERFACE_NAME.svg\"@src=\"/seq${num}/INTERFACE_NAME.svg\"@g" combined.txt
let num++;
done
sed -i "N;/alignment file ends here/r combined.txt" Results.html
rm -f combined*.txt
INTERFACEDESC=`grep -r --after-context=1 multilign.html ../../../../index.html | tail -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1`
sed -i "s@Results@Results
($INTERFACEDESC)@g" Results.html
insertTextFile ALIGNMENT_TEXT multilign/multilign.ali Results.html
sed -i 's@ALIGNMENT_ROOT@multilign/multilign@g' Results.html
sed -i 's@INTERFACE_PAGE@multilign/multilign.html@g' Results.html
sed -i 's@INTERFACE_NAME@multilign@g' Results.html
sed -i "s@FULL_RESULTS_DIRECTORY@ResultsPages/$DIRECTORY@g" Results.html
sed -i "s@COMMAND_LINE@multilign-smp $HTMLCOMMAND@g" Results.html
sed -i 's@multilign/ResultsPages@Predict3/ResultsPages@g' Results.html
sed -i 's@/seq@/multilign/seq@g' Results.html
sed -i 's@"/multilign@"multilign@g' Results.html
sed -i 's@src="seq@src="multilign/seq@g' Results.html
sed -i 's@/multilign.config@/multilign/multilign.config@g' Results.html
fi
# Move all files created for this section into the multilign directory.
mkdir multilign;
mv seq* multilign/;
mv multilign.config multilign/;
mv multilign.ali multilign/
mv Results.html multilign/;
######################################################################
# Do the TurboFold calculation.
######################################################################
# Create the unique script variables necessary for this calculation.
COMMAND=`echo $FULLCOMMAND | cut -d ';' -f '2'`
HTMLCOMMAND=`echo $FULLHTML | cut -d ';' -f '2'`
# Run the main calculation command.
runTool TurboFold-smp $COMMAND
# For each input sequence, create its results files and individual HTML page in a separate subfolder.
typeset -i i SEQS;
let SEQS=NUMSEQS;
let num=1;
while (( num <= SEQS )); do
# Make the next subfolder and move the relevant files into it.
# Then move to the subfolder.
mkdir seq${num};
mv TurboFold${num}.ct seq${num}/TurboFold.ct
cd seq${num}
# Create the comprehensive PS and PDF files.
runTool draw TurboFold.ct TurboFold.ps
if [[ ! -s ../errors.txt ]]; then ps2pdf TurboFold.ps TurboFold.pdf 1>/dev/null 2>>../errors.txt; fi
# If only one structure is present, create a JPEG and SVG file to be available to the user.
# Otherwise, split the CT file into individual structures and make CT, PS, PDF, and SVG files for each structure.
# Individual JPEG files are not created because they take too long and occupy too much space; they are made only if and when the user requests them.
NUMSTRUCTURES=0
if [[ ! -s ../errors.txt ]]; then
NUMSTRUCTURES=`grep -r showpage TurboFold.ps | wc -l`
if (( $NUMSTRUCTURES == 1 )); then
if [[ ! -s ../errors.txt ]]; then gs -dNOPAUSE -dBATCH -q -r300 -dJPEGQ=100 -sDEVICE=jpeg -sOutputFile=TurboFold.jpeg TurboFold.ps 1>/dev/null 2>>../errors.txt; fi
runTool draw TurboFold.ct TurboFold.svg -n 1 --svg
else
if [[ ! -s ../errors.txt ]]; then
SEQLENGTH=`head -n 1 TurboFold.ct | awk '{print $1}'`
let SEQLENGTH++;
awk '{print > (NR%"'"$SEQLENGTH"'"?i:i++)".ct";}' i=1 TurboFold.ct
fi
typeset -i i END;
let END=$NUMSTRUCTURES;
let i=1;
while (( i <= END )); do
runTool draw TurboFold.ct ${i}.ps -n $i
if [[ ! -s ../errors.txt ]]; then ps2pdf ${i}.ps ${i}.pdf 1>/dev/null 2>>../errors.txt; fi
runTool draw TurboFold.ct ${i}.svg -n $i --svg
let i++;
done
fi
fi
# If no errors occurred in results files generation, create a results page using a templated HTML file.
# If no structures were generated, use a static notification HTML page as the results page.
# If only one structure was generated, place it in a specialized static HTML page.
# If multiple structures were generated, place it in a dynamic, expandable HTML page.
# If one or more structures were made, place the proper interface name, results directory, and command line in the results page.
if [[ ! -s ../errors.txt ]]; then
if grep -Fqs "contains no pairs" TurboFold.svg
then
cp ../../../../Utilities/Pages/NoStructures.html Results.html
rm -f TurboFold*
else
if (( $NUMSTRUCTURES == 1 )); then
copyTemplate ResultsPageSingleCTSingleStructure Results.html
else
copyTemplate ResultsPageSingleCTManyStructures Results.html
sed -i "s@STRUCTURE_NUMBER@$END@g" Results.html
awk '/download structure 1 links/,/structure 1 links end here -->/{print}' ../../../../../Utilities/Templates/ResultsPageSingleCTManyStructures.html > individualDiv.txt
typeset -i i END;
let END=$NUMSTRUCTURES;
let i=1;
while (( i <= END )); do
sed "s/1/$i/g" individualDiv.txt >> extendedDivs.txt
let i++;
done
sed -i '/download structure 1 links/,/structure 1 links end here -->/d' Results.html
sed -i "N;/Download Individual Structures/r extendedDivs.txt" Results.html
fi
fi
sed -i "s@FULL_RESULTS_DIRECTORY@ResultsPages/$DIRECTORY/seq${num}@g" Results.html
fi
# If an error did occur in results file generation, create an error page using a templated HTML file, delete all generated files, and break out of the loop.
if [[ -s ../errors.txt ]]; then
#copyTemplate Error ../Results.html
#sed -i "N;/errorText/r ../errors.txt" ../Results.html
rm -f ../Results.html
cd ..
rm -rf seq*
break
fi
# Move back to the main directory and increment the loop.
cd ..
let num++;
done
# If an error results page was not already made, put the results pages together into one big one.
if [[ ! -s Results.html ]]; then
copyTemplate ResultsPageManyAlignedStructures Results.html
sed -i '/image box starts/,/command line ends/d' Results.html
let num=1;
while (( num <= SEQS )); do
echo "Structures derived from sequence $num:
" > combinedTemp.txt
sed -n "/image box starts here/,/download links end here/p" seq$num/Results.html >> combinedTemp.txt
echo "
" >> combinedTemp.txt
sed "s@id=\"@id=\"$num@g" combinedTemp.txt >> combined.txt
sed -i "s@src=\"INTERFACE_NAME.svg\"@src=\"/seq${num}/INTERFACE_NAME.svg\"@g" combined.txt
let num++;
done
sed -i "N;/alignment file ends here/r combined.txt" Results.html
#sed -i '/alignment file starts/,/alignment file ends/d' Results.html
rm -f combined*.txt
INTERFACEDESC=`grep -r --after-context=1 TurboFold.html ../../../../index.html | tail -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1`
sed -i "s@Results@Results
($INTERFACEDESC)@g" Results.html
insertFileInTemplate ALIGNMENT_TEXT TurboFold.aln Results.html
replaceInFile Results.html ALIGNMENT_ROOT.ali TurboFold.aln
sed -i 's@INTERFACE_PAGE@TurboFold/TurboFold.html@g' Results.html
sed -i 's@INTERFACE_NAME@TurboFold@g' Results.html
sed -i "s@FULL_RESULTS_DIRECTORY@ResultsPages/$DIRECTORY@g" Results.html
sed -i "s@COMMAND_LINE@TurboFold-smp $HTMLCOMMAND@g" Results.html
sed -i 's@TurboFold/ResultsPages@Predict3/ResultsPages@g' Results.html
sed -i 's@/seq@/TurboFold/seq@g' Results.html
sed -i 's@"/TurboFold@"TurboFold@g' Results.html
sed -i 's@src="seq@src="TurboFold/seq@g' Results.html
sed -i 's@/TurboFold.config@/TurboFold/TurboFold.config@g' Results.html
fi
# Move all files created for this section into the TurboFold directory.
mkdir TurboFold;
mv seq* TurboFold/;
mv TurboFold.config TurboFold/;
mv Results.html TurboFold/;
######################################################################
# Check for errors, then create the results page.
######################################################################
# If an error results page was not already made, put the results pages together into one big one.
if [[ ! -s Results.html ]]; then
copyTemplate ResultsPageManyAlignedStructures Results.html
sed -i '/results header starts/,/command line ends/d' Results.html
COMBINEDHEADER='
'
echo -e $COMBINEDHEADER > combined.txt
sed -n "/results header starts/,/command line ends/p" multilign/Results.html > combinedTemp.txt
echo "
" >> combinedTemp.txt
sed "s@id=\"@id=\"1@g" combinedTemp.txt >> combined.txt
sed -n "/results header starts/,/command line ends/p" TurboFold/Results.html > combinedTemp.txt
sed "s@id=\"@id=\"2@g" combinedTemp.txt >> combined.txt
sed -i 'N;/id="main"/r combined.txt' Results.html
rm -f combined*.txt
sed -i 's@INTERFACE_PAGE@Predict3/Predict3.html@g' Results.html
sed -i 's@INTERFACE_NAME@Predict a Secondary Structure Common to Three or More Sequences@g' Results.html
fi
######################################################################
# Perform end-of-calculation tasks
######################################################################
calcCompleted #send results email, notify web client, etc