#!/bin/bash # Set the PBS info. #PBS -N dynalign_DIRECTORY_STRING #PBS -l nodes=1:ppn=4:walltime=48:00:00 #PBS -q long #PBS -j oe #cd $PBS_O_WORKDIR # Create the unique script variables necessary for this calculation. COMMAND="COMMAND_STRING" DIRECTORY=DIRECTORY_STRING EMAIL="EMAIL_STRING" HTMLCOMMAND="COMMAND_HTML_STRING" NUMSEQS=2 # Export the data path and run the main calculation command. source ../../../../Utilities/Scripts/RunScriptTools || echo 'Internal Server error. Please contact the website administrator.' > errors.txt #include common functions, including sendResultsEmail. calcStarted 'dynalign' 'Dynalign' 'DIRECTORY_STRING' 'EMAIL_TO' writeStatus "Running dynalign..." runTool dynalign-smp $COMMAND writeStatus -d "Drawing Structures...\n" # 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 dynalign${num}.fasta seq${num}/dynalign.fasta mv dynalign${num}.ct seq${num}/dynalign.ct cd seq${num} # Create the comprehensive PS and PDF files. writeStatus " Drawing Sequence $num Structures (Combined)..." runTool draw dynalign.ct dynalign.ps writeStatus -d #if [[ ! -s ../errors.txt ]]; then ps2pdf dynalign.ps dynalign.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 dynalign.ps | wc -l` if (( $NUMSTRUCTURES == 1 )); then #if [[ ! -s ../errors.txt ]]; then gs -dNOPAUSE -dBATCH -q -r300 -dJPEGQ=100 -sDEVICE=jpeg -sOutputFile=dynalign.jpeg dynalign.ps 1>/dev/null 2>>../errors.txt; fi runTool draw dynalign.ct dynalign.svg -n 1 --svg else if [[ ! -s ../errors.txt ]]; then SEQLENGTH=`head -n 1 dynalign.ct | awk '{print $1}'` let SEQLENGTH++; awk '{print > (NR%"'"$SEQLENGTH"'"?i:i++)".ct";}' i=1 dynalign.ct fi typeset -i i END; let END=$NUMSTRUCTURES; let i=1; writeStatus " Drawing Structures:" while (( i <= END )); do (( $i != 1 && $i % 5 == 1 )) && writeStatus "\n Drawing Structures:" writeStatus " $num.$i" runTool draw dynalign.ct ${i}.ps -n $i #if [[ ! -s ../errors.txt ]]; then ps2pdf ${i}.ps ${i}.pdf 1>/dev/null 2>>../errors.txt; fi runTool draw dynalign.ct ${i}.svg -n $i --svg let i++; done writeStatus " \ndone.\n" 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" dynalign.svg then cp ../../../../Utilities/Pages/NoStructures.html Results.html rm -f dynalign* 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 writeStatus "Done Drawing Structures.\n" # 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 dynalign.html ../../../../index.html | tail -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1` sed -i "s@Results@Results
($INTERFACEDESC)@g" Results.html sed -i 's@ALIGNMENT_ROOT@dynalign@g' Results.html sed -i 's@INTERFACE_PAGE@dynalign/dynalign.html@g' Results.html sed -i 's@INTERFACE_NAME@dynalign@g' Results.html sed -i "s@FULL_RESULTS_DIRECTORY@ResultsPages/$DIRECTORY@g" Results.html sed -i "s@COMMAND_LINE@dynalign-smp $HTMLCOMMAND@g" Results.html fi ###################################################################### # Perform end-of-calculation tasks ###################################################################### calcCompleted #send results email, notify web client, etc