Created
June 2, 2011 16:01
-
-
Save jimtalksdata/1004698 to your computer and use it in GitHub Desktop.
Prototype vina script for resume support and error handling of multiple runs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "Short and simple VINA docking script - Jim" | |
echo "" | |
if [ $# -eq 0 ] | |
then | |
echo "Please enter the protein to dock (do not put the extension in): " | |
read prot | |
fi | |
if [ $# -eq 1 ] | |
then | |
prot="$1" | |
fi | |
if [ $# -gt 1 ] | |
then | |
echo "Too many parameters!" | |
fi | |
echo "" | |
echo "Protein: $prot" | |
decoys=`ls de*.pdbqt | wc -l` | |
ligands=`ls lg*.pdbqt | wc -l` | |
resumed="0" | |
resumel="0" | |
echo "Matching protein $prot with $decoys decoy(s) and $ligands ligand(s)..." | |
# Checks if conf file is identical, and if so, offers user opportunity to resume | |
if [ `grep "$prot" conf.txt | wc -l` -eq 1 ] | |
then | |
#Find all subfolders that do NOT contain a *.pdbqt file | |
#Thank you unix.com forums for this | |
lastdecoy=`find . -type d -print0 | xargs -0 ./filecheck.sh | grep "de[0-9]*"` | |
lastligand=`find . -type d -print0 | xargs -0 ./filecheck.sh | grep "lg[0-9]*"` | |
#TODO: Put error condition when more than one directory is returned for each find | |
#This indicates previous unstable terminations and should prompt user to wipe the whole directory | |
#to prevent a corrupt state. | |
if [ $lastdecoy ] | |
then | |
lde=`basename $lastdecoy` | |
fi | |
if [ $lastligand ] | |
then | |
llg=`basename $lastligand` | |
fi | |
if [ $lastdecoy ] | |
then | |
echo "Would you like to resume at decoy $lde (y/n)?" | |
read answer | |
elif [ $lastligand ] | |
then | |
echo "Would you like to resume at ligand $llg (y/n)?" | |
read answer | |
else | |
echo "It seems that a match has already completed in this directory." | |
# Delete previous match, on user request | |
echo "Would you like to completely start over (deleting all decoy and ligand directories) (y/n)?" | |
read answer2 | |
if [ "$answer2" == "y" ] || [ "$answer2" == "Y" ] | |
then | |
echo "Deleting ALL decoy directories..." | |
rm -rf ./de* | |
echo "Deleting ALL ligand directories..." | |
rm -rf ./lg* | |
fi | |
fi | |
# Delete unfinished directories | |
if [ "$answer" == "y" ] || [ "$answer" == "Y" ] | |
then | |
#Delete last entry | |
if [ ! -d /$lde ] | |
then | |
if [ $lastdecoy ] | |
then | |
echo "Deleting unfinished decoy directory $lde..." | |
rm -rf $lastdecoy | |
resumed="1" | |
fi | |
fi | |
if [ ! -d /$llg ] | |
then | |
if [ $lastligand ] | |
then | |
echo "Deleting unfinished ligand directory $llg..." | |
rm -rf $lastligand | |
resumel="1" | |
fi | |
fi | |
else | |
echo "Would you like to completely start over (deleting all decoy and ligand directories) (y/n)?" | |
if [ "$answer" == "y" ] || [ "$answer" == "Y" ] | |
then | |
echo "Deleting ALL decoy directories..." | |
rm -rf ./de* | |
echo "Deleting ALL ligand directories..." | |
rm -rf ./lg* | |
fi | |
fi | |
for f in de*.pdbqt; do | |
b=`basename $f .pdbqt` | |
if [ $resumed -eq 1 ] | |
then | |
if [ "$lde" == "$b" ] | |
then | |
resumed="0" | |
echo Processing de $b | |
mkdir -p $b | |
./vina --config conf.txt --ligand $f --out ${b}/out.pdbqt --log ${b}/log.txt | |
else | |
echo "Skipping de $b" | |
fi | |
else | |
echo Processing de $b | |
mkdir -p $b | |
./vina --config conf.txt --ligand $f --out ${b}/out.pdbqt --log ${b}/log.txt | |
fi | |
done | |
for f in lg*.pdbqt; do | |
b=`basename $f .pdbqt` | |
if [ $resumel -eq 1 ] | |
then | |
if [ "$llg" == "$b" ] | |
then | |
resumel="0" | |
echo Processing lg $b | |
mkdir -p $b | |
./vina --config conf.txt --ligand $f --out ${b}/out.pdbqt --log ${b}/log.txt | |
else | |
echo "Skipping de $b" | |
fi | |
else | |
echo Processing lg $b | |
mkdir -p $b | |
./vina --config conf.txt --ligand $f --out ${b}/out.pdbqt --log ${b}/log.txt | |
fi | |
done | |
# New protein, starting over | |
# NOT TESTED YET | |
else | |
echo "A match already exists here. Delete previous results (y/n)?" | |
echo "You can take the time to back them up now if you want." | |
read answer | |
if [ "$answer2" == "y" ] || [ "$answer2" == "Y" ] | |
then | |
echo "Deleting ALL decoy directories..." | |
rm -rf ./de* | |
echo "Deleting ALL ligand directories..." | |
rm -rf ./lg* | |
fi | |
sed -e 's/receptor = .*\.pdbqt/receptor = $prot\.pdbqt/g' conf.txt > conftemp.txt | |
rm conf.txt.bak | |
mv conf.txt conf.txt.bak | |
mv conftemp.txt conf.txt | |
echo "Starting new match with $prot..." | |
for f in de*.pdbqt; do | |
b=`basename $f .pdbqt` | |
echo Processing de $b | |
mkdir -p $b | |
./vina --config conf.txt --ligand $f --out ${b}/out.pdbqt --log ${b}/log.txt | |
done | |
for f in lg*.pdbqt; do | |
b=`basename $f .pdbqt` | |
echo Processing lg $b | |
mkdir -p $b | |
./vina --config conf.txt --ligand $f --out ${b}/out.pdbqt --log ${b}/log.txt | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment