#### Convert secondary structure information into open 3D structure using Shapior's 
#### RNA2D3D program
#### Usage: bash get2d3d.sh input.bpl
#### input.bpl is the input file with the sequence and base pairs
#### See given template of input.bpl file, the sequence should have 
#### a maximum of 50 spaces in each line
###############################################################################
# Help                                                                         #
################################################################################
Help()
{
   # Display Help
   echo "Generate 3D open structure from given secondary structure information"
   echo
   echo "Usage: "
   echo "      bash convert2d3d.sh input.bpl"
   echo 
   echo "      input.bpl      input file with the sequence and base pairs"
   echo 
   echo "      see the template input.bpl at scripts_path/rna2d3d/input.bpl"
   echo "      the nulceotide sequence should have a maximum of 50 spaces in each line"
   echo "      the output pdb file has extension is "_open.pdb""
   echo
}
# Get the options
while getopts ":h" option; do
   case $option in
      h) # display Help
         Help
         exit;;
   esac
done
# While no arguments
if [[ $# -eq 0 ]] ; then
    Help
    exit 0
fi

## load singularity
module load singularity
module load python/2.7
input_file=$1
input_base=${input_file%.*}
export SINGULARITY_BINDPATH="$PWD"
singularity run  $analysisPath"/rna2d3d/rna2d3d-biowulf.simg" $input_file -compact -sstrand -o std

## edit the output pdb file
python $analysisPath"/rna2d3d/replace.py" $input_base"_bplist.std.pdb" 
mv $input_base"_bplist.std.pdb" $input_base"_open.pdb"
## remove temp files
rm -rf sstrand.* tmp* 

