Skip to content
Snippets Groups Projects
run_blastx.sanger 2.58 KiB
Newer Older
tjc's avatar
tjc committed
#!/bin/sh -

# this script will run a search program on a sequence input file or on each
# file in a file of filenames

# to customise this script see the function called run_one_prog below


tjc's avatar
tjc committed
RCS_HEADER="$Header: /cvsroot/pathsoft/artemis/etc/run_blastx.sanger,v 1.2 2005/07/11 15:06:21 tjc Exp $"

cleanUp()
{
  echo $1
  cat $1 | while thisLine=`line`
  do
    rm -f $thisLine
  done
  rm -f $1
}
tjc's avatar
tjc committed

PROG=`echo $RCS_HEADER | sed 's/.*run_\(.*\),v.*/\1/'`


if [ $# = 4 -a x$1 = x-onefile ]
then
    shift
    ONEFILE=t
    DATABASE=$3 export DATABASE
else
    if [ $# = 2 ]
    then
        DATABASE=$2 export DATABASE
    else
        echo usage: $0 -onefile input_file output_file database
        echo    or: $0 file_of_filenames database
        exit 1
    fi
fi

tjc's avatar
tjc committed
if [ $DATABASE = "psu/Kineto_aa" ]; then
  BLASTDB=/lustre/pathogen/blast; export BLASTDB
fi
tjc's avatar
tjc committed

# expand any ~ or environment variables
EXPANDED_DATABASE=`echo "echo $DATABASE" | /bin/csh -f`

tjc's avatar
tjc committed
echo $BLASTDB
tjc's avatar
tjc committed
### change this function to suit your site:

run_one_prog () {
    INPUT_FILE=$1
    OUTPUT_FILE=$2
    DATABASE=$3
tjc's avatar
tjc committed
    DIRNAME=$4
tjc's avatar
tjc committed

    ### change these lines:
    EXEC=blastall

    echo "about to start $EXEC with input from $INPUT_FILE and output to"
    echo "$OUTPUT_FILE using database $DATABASE"


    EXTRA_ARGS=

    # add/change the flags to suit your site:

    HOSTNAME=`hostname`
    REMOTE=N

    case $HOSTNAME in
        deskpro*)
          REMOTE=Y ;;
        *)
    esac

    if [ $REMOTE = "Y" ]; then
      WDIR=`pwd`
      export WDIR
      rsh babel "cd $WDIR; lsrun -v blastwrap.pl $EXEC -d $DATABASE -i $INPUT_FILE -p blastx \
                            $EXTRA_ARGS >! $OUTPUT_FILE"
    else
tjc's avatar
tjc committed
      bsub -q  long -o $OUTPUT_FILE -e ${PROG}_errors.new -I flexi_blast.pl -x $DATABASE $INPUT_FILE $EXTRA_ARGS
tjc's avatar
tjc committed
    fi

    #### end of changes


    # Artemis can read compressed files
    count=0; while  (test ! -f $OUTPUT_FILE)  && (test $count -lt 1000) ; do sleep 2; count+=1; done
tjc's avatar
tjc committed

    gzip -9 $OUTPUT_FILE
    zip -j ${DIRNAME}blastx.zip ${OUTPUT_FILE}.gz
    rm -f ${OUTPUT_FILE}.gz

#   if [ -s ${PROG}_errors.new ]
#   then
#       ( echo ERROR running $PROG: ; echo; 
#         echo ===================================================
#         cat ${PROG}_errors.new ) >> $OUTPUT_FILE
#       cat ${PROG}_errors.new >> ${PROG}_errors
#   fi
tjc's avatar
tjc committed
}

(echo "#!/bin/sh -"; echo "kill $$") > $PROG.kill

chmod a+x $PROG.kill
tjc's avatar
tjc committed
DIR=`dirname $PWD/$1`
tjc's avatar
tjc committed

if [ x$ONEFILE = x ]
then
    for i in `cat $1`
    do
tjc's avatar
tjc committed
        run_one_prog $i $i.out $echo $EXPANDED_DATABASE "$DIR/"
tjc's avatar
tjc committed
    done

else
tjc's avatar
tjc committed
    run_one_prog $1 $2 $EXPANDED_DATABASE "$DIR/"
tjc's avatar
tjc committed
fi

tjc's avatar
tjc committed
cleanUp $1
tjc's avatar
tjc committed
exit 0