Debian Codegraph @

etc/run_blastp

raw
1 #!/bin/sh -
2
3 # this script will run a search program on a sequence input file or on each
4 # file in a file of filenames
5
6 # to customise this script see the function called run_one_prog below
7
8 PROG=blastp
9
10
11 if [ $# = 4 -a x$1 = x-onefile ]
12 then
13 shift
14 ONEFILE=t
15 DATABASE=$3 export DATABASE
16 else
17 if [ $# = 2 ]
18 then
19 DATABASE=$2 export DATABASE
20 else
21 echo usage: $0 -onefile input_file output_file database
22 echo or: $0 file_of_filenames database
23 exit 1
24 fi
25 fi
26
27
28 # expand any ~ or environment variables
29 #EXPANDED_DATABASE=`echo "echo $DATABASE" | /bin/csh -f`
30 eval EXPANDED_DATABASE="$DATABASE"
31
32 ### change this function to suit your site:
33
34 run_one_prog () {
35 INPUT_FILE=$1
36 OUTPUT_FILE=$2
37 DATABASE_ARG=$3
38
39
40 ### change these lines:
41
42 PLATFORM_INFO=`uname`
43 if [ "$PLATFORM_INFO" = "Darwin" ]
44 then
45 # Mac OSX: Attempt to initialise environment variables from profile.
46 echo "running $HOME/.profile..."
47 source $HOME/.profile 2>/dev/null
48 fi
49
50 EXEC=${EXEC-`which $PROG 2>/dev/null`}
51
52 if [ "$EXEC" = "" ] && [ -x /usr/local/ncbi/blast/bin/$PROG ]
53 then
54 EXEC=/usr/local/ncbi/blast/bin/$PROG
55 fi
56
57 if [ ! -x "$EXEC" ]
58 then
59 echo "ERROR: Cannot find an executable $PROG blast program. Exiting."
60 exit 1
61 fi
62
63 #
64 # Check for setting of NCBI BLASTDB environment variable
65 #
66 if [ "$BLASTDB" = "" ]; then
67
68 DATABASE=`echo $DATABASE_ARG | sed 's|\%||'`
69
70 if [ ! -f "$DATABASE" ]
71 then
72
73 # Check home directory...
74 echo "Checking $HOME/blast-data/ for database..."
75 if [ -f "$HOME/blast-data/$DATABASE" ]
76 then
77 DATABASE=$HOME/blast-data/$DATABASE
78 fi
79 fi
80
81 if [ ! -f "$DATABASE" ]
82 then
83 echo "ERROR: Cannot find database $DATABASE. Exiting."
84 exit 1
85 fi
86
87 fi
88
89
90 COMMAND="$EXEC -db $DATABASE -query $INPUT_FILE -num_threads 2"
91
92 echo
93 echo "input file: $INPUT_FILE"
94 echo "output will be written to: $OUTPUT_FILE"
95 echo "executing command: $COMMAND" 1>&2
96
97 # add/change the flags to suit your site:
98 nice -n 19 $COMMAND 2>&1 > $OUTPUT_FILE | tee ${PROG}_errors.new 1>&2
99
100 #### end of changes
101
102
103 # Artemis can read compressed files
104 gzip -9 $OUTPUT_FILE &
105
106 if [ -s ${PROG}_errors.new ]
107 then
108 ( echo ERROR running $PROG: ; echo;
109 echo ===================================================
110 cat ${PROG}_errors.new ) >> $OUTPUT_FILE
111 cat ${PROG}_errors.new >> ${PROG}_errors
112 fi
113 }
114
115 (echo "#!/bin/sh -"; echo "kill $$") > $PROG.kill
116
117 chmod a+x $PROG.kill
118
119 if [ x$ONEFILE = x ]
120 then
121 for i in `cat $1`
122 do
123 run_one_prog $i $i.out $EXPANDED_DATABASE
124 done
125
126 else
127 run_one_prog $1 $2 $EXPANDED_DATABASE
128 fi
129
130 exit 0