Skip to content
Snippets Groups Projects
run_blastp 2.75 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


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


# expand any ~ or environment variables
#EXPANDED_DATABASE=`echo "echo $DATABASE" | /bin/csh -f`
eval EXPANDED_DATABASE="$DATABASE"
tjc's avatar
tjc committed

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

run_one_prog () {
    INPUT_FILE=$1
    OUTPUT_FILE=$2
tjc's avatar
tjc committed


    ### change these lines:
    
    PLATFORM_INFO=`uname`
	if [ "$PLATFORM_INFO" = "Darwin" ]
	then
		# Mac OSX: Attempt to initialise environment variables from profile.
		echo "running $HOME/.profile..."
		source $HOME/.profile 2>/dev/null	
	fi
	
	EXEC=${EXEC-`which $PROG 2>/dev/null`}
	
	if [ "$EXEC" = "" ] && [ -x /usr/local/ncbi/blast/bin/$PROG ]
	then
		EXEC=/usr/local/ncbi/blast/bin/$PROG
tjc's avatar
tjc committed
    fi
    
    if [ ! -x "$EXEC" ]
    then
    	echo "ERROR: Cannot find an executable $PROG blast program. Exiting."
    	exit 1
tjc's avatar
tjc committed
    fi
tjc's avatar
tjc committed

	#
    # Check for setting of NCBI BLASTDB environment variable
    #
	if [ "$BLASTDB" = "" ]; then

      	DATABASE=`echo $DATABASE_ARG | sed 's|\%||'`

      	if [ ! -f "$DATABASE" ]
      	then
 
        	# Check home directory...
        	echo "Checking $HOME/blast-data/ for database..."
        	if [ -f "$HOME/blast-data/$DATABASE" ]
        	then
          		DATABASE=$HOME/blast-data/$DATABASE
        	fi
      	fi

      	if [ ! -f "$DATABASE" ]
      	then
        	echo "ERROR: Cannot find database $DATABASE. Exiting."
        	exit 1
      	fi
tjc's avatar
tjc committed

tjc's avatar
tjc committed


    COMMAND="$EXEC -db $DATABASE -query $INPUT_FILE -num_threads 2"
	
    echo
    echo "input file: $INPUT_FILE"
    echo "output will be written to: $OUTPUT_FILE"
    echo "executing command: $COMMAND" 1>&2
	
tjc's avatar
tjc committed
    # add/change the flags to suit your site:
    nice -n 19 $COMMAND 2>&1 > $OUTPUT_FILE | tee ${PROG}_errors.new 1>&2
tjc's avatar
tjc committed

    #### end of changes


    # Artemis can read compressed files
    gzip -9 $OUTPUT_FILE &

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

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

chmod a+x $PROG.kill

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

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

exit 0