@@ -35,6 +35,18 @@ function err_test() {
3535 fi
3636}
3737
38+ function warn() {
39+ local t=$( date +" %Y-%m-%d %k:%M:%S" )
40+ echo -e " [$t ] $SELF WARNING :: $1 " 1>&2
41+ return 1
42+ }
43+
44+ function die() {
45+ local t=$( date +" %Y-%m-%d %k:%M:%S" )
46+ echo -e " [$t ] $SELF ERROR :: $1 " 1>&2
47+ exit 1
48+ }
49+
3850function check_prgm() {
3951 if ( ! hash $1 > dev/null ); then
4052 echo " $SELF ERROR: Program '$1 ' not found, please check your PATH or install it."
164176banlist=$ppath /level_banlist.txt
165177use_xrev=0
166178if [ " $doHMM " -eq " 1" ]; then
167- if [ -r $banlist ]; then
168- $spath /fastaExtractor.pl -R -A $alvl_hmm_file $banlist > $alvl_file .tmp.fasta
169- [ " $rmGAP " -eq " 1" ] && $spath /removeGapColumns.pl $alvl_file .tmp.fasta
170- $spath /partitionTaxa.pl $alvl_file .tmp.fasta $tpath
179+ if [ -r " $banlist " ]; then
180+ " $spath " /fastaExtractor.pl -R -A $alvl_hmm_file $banlist > $alvl_file .tmp.fasta \
181+ && [ " $rmGAP " -eq " 1" ] && $spath /removeGapColumns.pl $alvl_file .tmp.fasta \
182+ || die " Extraction and/or gap removal failed."
183+ " $spath " /partitionTaxa.pl $alvl_file .tmp.fasta $tpath \
184+ || die " Partioning by taxa failed."
171185 # rm $alvl_file.tmp.fasta
172186 else
173- [ " $rmGAP " -eq " 1" ] && $spath /removeGapColumns.pl $alvl_hmm_file
174- $spath /partitionTaxa.pl $alvl_hmm_file $tpath
187+ [ " $rmGAP " -eq " 1" ] && $spath /removeGapColumns.pl $alvl_hmm_file \
188+ && " $spath " /partitionTaxa.pl $alvl_hmm_file $tpath \
189+ || die " Gap removal and/or partitioning failed."
175190 fi
176191
177192 rm $tpath /* _hmm.mod 2> /dev/null
178193 size=$( grep ' >' $alvl_file -c)
179- if [ -r null.fasta ]; then
180- $modelfromalign null -alignfile $ppath /null.fasta -alphabet DNA 2> /dev/null
181- rm $ppath /null.weightoutput
182- mv $ppath /null.mod $tpath
194+ if [ -r " null.fasta" ]; then
195+ $modelfromalign null -alignfile $ppath /null.fasta -alphabet DNA 2> /dev/null \
196+ && rm $ppath /null.weightoutput \
197+ && mv $ppath /null.mod $tpath \
198+ || die " ModelfromAlign failed for custom null"
183199 echo " $SELF : using custom null model"
184200 else
185201 if [ -r " $tpath /null.mod" ]; then
186- rm $tpath /null.mod
202+ rm " $tpath " /null.mod
187203 fi
188204
189- if [ -d $ppath /x-rev -o -d $mpath /x-rev ]; then
205+ if [ -d " $ppath /x-rev" -o -d " $mpath /x-rev" ]; then
190206 use_xrev=1
191207 [ ! -d $ppath /x-rev ] && mkdir $ppath /x-rev
192208 [ ! -d $mpath /x-rev ] && mkdir $mpath /x-rev
@@ -197,14 +213,20 @@ if [ "$doHMM" -eq "1" ];then
197213 fi
198214
199215 echo " $SELF : generating pHMMs"
200- for f in $tpath /* fasta; do
201- m=` basename $f .fasta` _hmm
202- taxa=(${taxa[*]} $m )
203- [ " $rmGAP " -eq " 1" ] && $spath /removeGapColumns.pl $f
204- $modelfromalign $m -alignfile $f -alphabet DNA 2> /dev/null
205- rm $m .weightoutput
206- mv $m .mod $tpath
207- done
216+ if test -n " $( shopt -s nullglob; echo " $tpath " /* fasta) " ; then
217+ for f in $tpath /* fasta; do
218+ m=` basename $f .fasta` _hmm
219+ taxa=(${taxa[*]} $m )
220+ [ " $rmGAP " -eq " 1" ] && $spath /removeGapColumns.pl $f
221+ $modelfromalign $m -alignfile $f -alphabet DNA 2> /dev/null \
222+ && rm $m .weightoutput \
223+ && mv $m .mod $tpath \
224+ || die " ModelfromAlign failed for '$f '"
225+ done
226+ else
227+ ls " $tpath "
228+ die " A 'level.fasta' is expected but found the above."
229+ fi
208230
209231 if [ " $use_xrev " -eq " 1" ]; then
210232 echo " $SELF : generating reverse pHMMs"
0 commit comments