new mafft v 6.857 with extensions
[jabaws.git] / binaries / src / mafft / core / mafft.tmpl.subopt
1 #! /bin/sh
2 er=0;
3 myself=`dirname $0`/`basename $0`; export myself
4 version="version 6.00 (2005/05/01)"; export version
5 LANG=C; export LANG
6 os=`uname`
7 progname=`basename $0`
8 if [ `echo $os | grep -i cygwin` ]; then
9         os="cygwin"
10 elif [ `echo $os | grep -i darwin` ]; then
11         os="darwin"
12 elif [ `echo $os | grep -i sunos` ]; then
13         os="sunos"
14 else
15         os="unix"
16 fi
17 export os
18
19 if [ $MAFFT_BINARIES ]; then
20         prefix=$MAFFT_BINARIES
21 else
22         prefix=_PREFIX
23 fi
24 export prefix
25 if [ ! -x $prefix/tbfast ]; then
26         echo ""
27         echo "correctly installed?" 2>&1
28         echo "mafft binaries have to be installed in" $prefix.
29         echo ""
30         exit 1
31         er=1
32 fi
33
34 defaultiterate=0
35 defaultcycle=2
36 defaultmodel=" -b 62 "
37 defaultgop="1.53"
38 defaultaof="0.123"
39 defaultfft=1
40 defaultrough=0
41 defaultdistance="sixtuples"
42 if [ $progname = "linsi" ]; then
43         defaultfft=0
44         defaultcycle=1
45         defaultiterate=1000
46         defaultdistance="local"
47 elif [ $progname = "ginsi" ]; then
48         defaultfft=1
49         defaultcycle=1
50         defaultiterate=1000
51         defaultdistance="global"
52 elif [ $progname = "einsi" ]; then
53         defaultfft=0
54         defaultcycle=1
55         defaultiterate=1000
56         defaultdistance="genaf"
57 elif [ $progname = "fftns" ]; then
58         defaultfft=1
59         defaultcycle=2
60 elif [ $progname = "fftnsi" ]; then
61         defaultfft=1
62         defaultcycle=2
63         defaultiterate=2
64 elif [ $progname = "nwns" ]; then
65         defaultfft=0
66         defaultcycle=2
67 elif [ $progname = "nwnsi" ]; then
68         defaultfft=0
69         defaultcycle=2
70         defaultiterate=2
71 fi
72 model=$defaultmodel
73 gop=$defaultgop
74 aof=$defaultaof
75 cycle=$defaultcycle
76 iterate=$defaultiterate
77 fft=$defaultfft
78 rough=$defaultrough
79 distance=$defaultdistance
80 LGOP="-6.00"
81 LEXP="-0.000"
82 lgop="-2.00"
83 lexp="-0.100"
84 laof="0.100"
85 seqtype="  "
86 param_it=" -x "
87 weighti="2.7"
88 quiet=0
89 sw=0
90 scorecalcopt=" "
91 coreout=0
92 corethr="0.5"
93 corewin="100"
94 coreext=" "
95 outputformat="pir"
96 outorder="input"
97 if [ $# -gt 0 ]; then
98         while [ $# -gt 1 ];
99         do
100                 if [ $1 = "--clustalout" ]; then 
101                         outputformat="clustal"
102                 elif [ $1 = "--reorder" ]; then 
103                         outorder="aligned"
104                 elif [ $1 = "--rough" ]; then 
105                         rough=1
106                 elif [ $1 = "--noscore" ]; then
107                         scorecalcopt=" -Z "
108                 elif [ $1 = "--fastswpair" ]; then
109                         distance="fasta"
110                         sw=1
111                 elif [ $1 = "--fastapair" ]; then
112                         distance="fasta"
113                         sw=0
114                 elif [ $1 = "--suboptpair" ]; then
115                         distance="subopt"
116                 elif [ $1 = "--blastpair" ]; then
117                         distance="blast"
118                 elif [ $1 = "--globalpair" ]; then
119                         distance="global"
120                 elif [ $1 = "--localpair" ]; then
121                         distance="local"
122                 elif [ $1 = "--genafpair" ]; then
123                         distance="genaf"
124                 elif [ $1 = "--nuc" ]; then 
125                         seqtype=" -D "
126                 elif [ $1 = "--amino" ]; then 
127                         seqtype=" -P "
128                 elif [ $1 = "--fft" ]; then 
129                         fft=1
130                 elif [ $1 = "--nofft" ]; then 
131                         fft=0
132                 elif [ $1 = "--quiet" ]; then 
133                         quiet=1
134                 elif [ $1 = "--nj" ]; then 
135                         param_it=" -n "
136                 elif [ $1 = "--coreext" ]; then 
137                         coreext=" -c "
138                 elif [ $1 = "--core" ]; then 
139                         coreout=1
140                 elif [ $1 = "--maxiterate" ]; then 
141                         shift   
142                         iterate=`expr $1 - 0`
143                 elif [ $1 = "--retree" ]; then 
144                         shift   
145                         cycle=`expr $1 - 0`          || er=1
146                 elif [ $1 = "--jtt" ]; then 
147                         shift   
148                         model=" -j "$1
149                 elif [ $1 = "--tm" ]; then 
150                         shift   
151                         model=" -m "$1
152                 elif [ $1 = "--bl" ]; then 
153                         shift   
154                         model=" -b "$1
155                 elif [ $1 = "--weighti" ]; then
156                         shift   
157                         weighti=$1
158                 elif [ $1 = "--op" ]; then 
159                         shift   
160                         gop=$1
161                 elif [ $1 = "--ep" ]; then 
162                         shift   
163                         aof=$1
164                 elif [ $1 = "--lop" ]; then 
165                         shift   
166                         lgop=$1
167                 elif [ $1 = "--LOP" ]; then 
168                         shift   
169                         LGOP=$1
170                 elif [ $1 = "--lep" ]; then 
171                         shift   
172                         laof=$1
173                 elif [ $1 = "--lexp" ]; then 
174                         shift   
175                         lexp=$1
176                 elif [ $1 = "--LEXP" ]; then 
177                         shift   
178                         LEXP=$1
179                 elif [ $1 = "--corethr" ]; then 
180                         shift   
181                         corethr=$1
182                 elif [ $1 = "--corewin" ]; then 
183                         shift   
184                         corewin=$1
185                 elif [ $1 -gt 0 -a $progname = "fftns" -o $1 -gt 0 -a $progname = "nwns" ]; then
186                         cycle=`expr $1 - 0`
187                 else
188                         echo "Unknown option: " $1 2>&1
189                         er=1;
190                 fi
191                 shift   
192         done;
193         if [ $fft -eq 1 ]; then
194                 param_fft=" -F "
195         else
196                 param_fft=" "
197         fi
198         if [ $sw -eq 1 ]; then
199                 swopt=" -A "
200         else
201                 swopt=" "
202         fi
203
204         if [ $distance = "fasta" ]; then
205                 if [ ! $FASTA_4_MAFFT ]; then
206                         FASTA_4_MAFFT=`which fasta34`
207                 fi
208
209                 if [ ! -x $FASTA_4_MAFFT ]; then
210                         echo ""
211                         echo "== Install FASTA ========================================================"
212                         echo "This option requires the fasta34 program (FASTA version x.xx or higher)"
213                         echo "installed in your PATH.  If you have the fasta34 program but have renamed"
214                         echo "(like /usr/local/bin/myfasta), set the FASTA_4_MAFFT environment variable"
215                         echo "to point your fasta34 (like setenv FASTA_4_MAFFT /usr/local/bin/myfasta)."
216                         echo "========================================================================="
217                         echo ""
218                         exit
219                 fi
220         fi
221         if [ $distance = "sixtuples" ]; then
222                 localparam=" "
223         else
224                 cycle=1
225                 localparam=" -l "$weighti
226         fi
227
228         if [ $distance = "fasta" -a $sw -eq 0 ]; then
229                 strategy="F-I"
230         elif [ $distance = "fasta" -a $sw -eq 1 ]; then
231                 strategy="H-I"
232         elif [ $distance = "subopt" ]; then
233                 strategy="S-I"
234         elif [ $distance = "blast" ]; then
235                 strategy="B-I"
236         elif [ $distance = "global" ]; then
237                 strategy="G-I"
238         elif [ $distance = "local" ]; then
239                 strategy="L-I"
240         elif [ $distance = "genaf" ]; then
241                 strategy="E-I"
242         elif [ $fft -eq 1 ]; then
243                 strategy="FFT-"
244         else
245                 strategy="NW-"
246         fi
247         strategy=$strategy"NS-"
248         if [ $iterate -gt 0 ]; then
249                 strategy=$strategy"i"
250         elif [ $rough -eq 1 ]; then
251                 strategy=$strategy"ROUGH"
252         else
253                 strategy=$strategy$cycle
254         fi
255
256         explanation='?'
257         performance='Not tested.'
258         if [ $strategy = "F-INS-i" ]; then
259                 explanation='Iterative refinement method incorporating LOCAL pairwise alignment information'
260                 performance='Most accurate, but very slow'
261         elif [ $strategy = "L-INS-i" ]; then
262                 explanation='Iterative refinement method incorporating LOCAL pairwise alignment information'
263                 performance='Probably most accurate, very slow'
264         elif [ $strategy = "E-INS-i" ]; then
265                 explanation='Iterative refinement method incorporating LOCAL pairwise alignment with generalized affine gap costs (Altshul 1998)'
266                 performance='Suitable for sequences with long unalignable regions, very slow'
267         elif [ $strategy = "G-INS-i" ]; then
268                 explanation='Iterative refinement method incorporating GLOBAL pairwise alignment information'
269                 performance='Suitable for sequences of similar lengths, very slow'
270         elif [ $strategy = "F-INS-1" ]; then
271                 explanation='Progressive method incorporating LOCAL pairwise alignment information'
272         elif [ $strategy = "L-INS-1" ]; then
273                 explanation='Progressive method incorporating LOCAL pairwise alignment information'
274         elif [ $strategy = "G-INS-1" ]; then
275                 explanation='Progressive method incorporating GLOBAL pairwise alignment information'
276         elif [ $strategy = "FFT-NS-i" -o $strategy = "NW-NS-i" ]; then
277                 explanation='Iterative refinement method (max. '$iterate' iterations)'
278                 if [ $iterate -gt 2 ]; then
279                         performance='Accurate but slow'
280                 else
281                         performance='Standard'
282                 fi
283         elif [ $strategy = "FFT-NS-2" -o $strategy = "NW-NS-2" ]; then
284                 explanation='Progressive method (guide trees were built '$cycle' times.)'
285                 performance='Fast but rough'
286         elif [ $strategy = "FFT-NS-1" -o $strategy = "NW-NS-1" ]; then
287                 explanation='Progressive method (rough guide tree was used.)'
288                 performance='Very fast but very rough'
289         fi
290
291         if [ $outputformat = "clustal" -a $outorder = "aligned" ]; then
292                 outputcommand="$prefix/f2cl -c $strategy -r order  "
293         elif [ $outputformat = "clustal" -a $outorder = "input" ]; then
294                 outputcommand="$prefix/f2cl -c $strategy  "
295         elif [ $outputformat = "pir" -a $outorder = "aligned" ]; then
296                 outputcommand="$prefix/f2cl -f -r order "
297         else
298                 outputcommand=" cat "
299         fi
300
301         TMPFILE=/tmp/`basename $0`.`whoami`.$$.`date +%y%m%d%H%M%S`
302         TMPFILE=/tmp/$progname.$$
303         umask 077
304         mkdir  $TMPFILE  || er=1
305         trap "rm -r $TMPFILE " 0
306         if [ $# -eq 1 ]; then
307                 if [ -s "$1" -o "$1" = - ]; then
308                         cat "$1" | tr "\r" "\n" > $TMPFILE/infile 
309                 else
310                         echo "Cannot open $1." 2>&1
311                         er=1
312                 fi
313         else
314                 echo '$#'"=$#" 2>&1
315                 er=1
316         fi
317         
318
319         if [ $er -eq 1 ]; then
320                 echo "" 2>&1
321                 echo "MAFFT" $version 2>&1
322                 echo ""  2>&1
323                 echo "    References: " 2>&1
324                 echo "      Katoh et al., 2002, NAR 30: 3059-3066" 2>&1
325                 echo "      Katoh et al., 2005, NAR 33: 511-518" 2>&1
326             echo "      http://www.biophys.kyoto-u.ac.jp/~katoh/programs/align/mafft" 2>&1
327                 echo "" 2>&1
328 #               echo "Usage: `basename $0` [options] inputfile > outputfile" 2>&1
329                 echo "    Options: " 2>&1
330                 echo "      --globalpair :      All pairwise global alignment information is included."  2>&1
331                 echo "                          default: off"  2>&1
332                 echo "      --localpair :       All pairwise local alignment information is included."  2>&1
333                 echo "                          default: off"  2>&1
334                 echo "      --op # :            Gap opening penalty (>0). default: $defaultgop " 2>&1
335                 echo "      --ep # :            Offset (>0, works like gap extension penalty). " 2>&1
336                 echo "                          default: $defaultaof " 2>&1
337                 echo "      --bl #, --jtt # :   Scoring matrix. default: BLOSUM62" 2>&1
338                 echo "                          Alternatives are BLOSUM (--bl) 30, 45, 62, 80, " 2>&1
339                 echo "                          or JTT (--jtt) # PAM. " 2>&1
340                 echo "      --nuc or --amino :  Sequence type. default: auto" 2>&1
341                 echo "      --retree # :        The number of tree building in progressive method " 2>&1
342                 echo "                          (see the paper for detail). default: $defaultcycle " 2>&1
343                 echo "      --maxiterate # :    Maximum number of iterative refinement. default: $defaultiterate " 2>&1
344                 echo "      --nj :              Tree dependent iterative refinement is performed" 2>&1
345                 echo "                          on an NJ tree. default: UPG tree" 2>&1
346                 if [ $defaultfft -eq 1 ]; then
347                         echo "      --fft or --nofft:   FFT is enabled or disabled. default: enabled" 2>&1
348                 else
349                         echo "      --fft or --nofft:   FFT is enabled or disabled. default: disabled" 2>&1
350                 fi
351 #               if [ $defaultrough -eq 1 ]; then 
352 #                       echo "      --rough :           Rough alignment, for >1,000 sequences. default: enabled" 2>&1
353 #               else
354 #                       echo "      --rough :           Rough alignment, for >1,000 sequences. default: disabled" 2>&1
355 #               i
356                 echo "      --clustalout:       Output: clustal format (not tested). default: fasta" 2>&1
357                 echo "      --reorder:          Outorder: aligned (not tested). default: input order" 2>&1
358                 echo "      --quiet :           Do not report progress." 2>&1
359                 echo ""  2>&1
360                 echo "    Input format: fasta format" 2>&1
361                 echo ""  2>&1
362                 echo "    Typical usages:" 2>&1
363                 echo "      % mafft --maxiterate 1000 --localpair input > output" 2>&1
364                 echo "           L-INS-i (most accurate and very slow, iterative refinement" 2>&1
365                 echo "           method incorporating LOCAL alignment information)" 2>&1
366                 echo "" 2>&1
367                 echo "      % mafft --maxiterate 1000 --globalpair input > output" 2>&1
368                 echo "           G-INS-i (slightly less accurate than L-INS-i and very slow," 2>&1
369                 echo "           iterative refinement method incorporating GLOBAL alignment" 2>&1
370                 echo "           information, suitable for sequences of similar lengths) " 2>&1
371                 echo "" 2>&1
372                 echo "      % mafft --maxiterate 1000 input > output" 2>&1
373                 echo "           FFT-NS-i (accurate and slow, iterative refinement method)" 2>&1
374                 echo "" 2>&1
375                 echo "      % mafft --retree 2 input > output (DEFAULT; same as mafft input > output)" 2>&1
376                 echo "           FFT-NS-2 (rough and fast, default, progressive method)" 2>&1
377                 echo "" 2>&1
378                 echo "      % mafft --retree 1 input > output" 2>&1
379                 echo "           FFT-NS-1 (very rough and very fast, progressive method with" 2>&1
380                 echo "           a rough guide tree)" 2>&1
381                 echo "" 2>&1
382                 exit 1; 
383         fi
384         
385         (
386         cd $TMPFILE;
387         if [ $rough -gt 0 ]; then
388                 $prefix/splitseq infile 500
389                 for spfile in sp-[0-9]*[0-9]
390                 do
391                         echo $spfile  > /dev/tty
392                         nseq=`grep -c '^[>|=]' $spfile`
393                         echo $nseq  > /dev/tty
394                         if [ $nseq -eq 1 ]; then
395                                 cp $spfile $spfile.aln
396                         else
397                                 $prefix/sextet5 $seqtype < $spfile > /dev/null  2>&1      || exit 1
398                                 $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft  -Ax < $spfile  > /dev/null  2>&1 || exit 1
399                                 cat pre > $spfile.aln
400                         fi
401                 done
402                 ngroup=0
403                 for alfile in sp-[0-9]*[0-9].aln
404                 do
405                         ngroup=`expr $ngroup + 1`
406                         echo $alfile > /dev/tty
407                         if [ $ngroup -eq 1 ]; then
408                                 cp $alfile alall
409                         else
410                                 $prefix/galn -A alall $alfile > altmp
411                                 mv altmp alall
412                         fi
413                 done
414                 cat alall
415         else
416                 if [ $quiet -gt 0 ]; then
417                         if [ $distance = "subopt" ]; then
418                                 $prefix/pairlocalalign   $seqtype -b 62  -g $lexp -f $lgop  -h $laof -O $LGOP -E $LEXP -S < infile > /dev/null  2>&1      || exit 1
419                                 $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   -Ax < infile   > /dev/null 2>&1 || exit 1
420                         elif [ $distance = "fasta" ]; then
421                                 $prefix/dndfast7 $swopt < infile > /dev/null  2>&1      || exit 1
422                                 $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   -Ax < infile   > /dev/null 2>&1 || exit 1
423                         elif [ $distance = "blast" ]; then
424                                 $prefix/dndblast < infile > /dev/null  2>&1      || exit 1
425                                 $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   -Ax < infile   > /dev/null 2>&1 || exit 1
426                         elif [ $distance = "global" ]; then
427                                 $prefix/pairlocalalign   $seqtype $model -f "-"$gop  -h "-"$aof  -F < infile > /dev/null  2>&1      || exit 1
428                                 $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   -Ax < infile   > /dev/null 2>&1 || exit 1
429                         elif [ $distance = "local" ]; then
430                                 $prefix/pairlocalalign   $seqtype -b 62  -g $lexp -f $lgop  -h $laof -L < infile > /dev/null  2>&1      || exit 1
431                                 $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   -Ax < infile   > /dev/null 2>&1 || exit 1
432                         elif [ $distance = "genaf" ]; then
433                                 $prefix/pairlocalalign   $seqtype -b 62  -g $lexp -f $lgop  -h $laof -O $LGOP -E $LEXP -N < infile > /dev/null  2>&1      || exit 1
434                                 $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   -Ax < infile   > /dev/null 2>&1 || exit 1
435                         else
436                                 $prefix/disttbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft -Ax < infile   > pre 2>/dev/null || exit 1
437                         fi
438                         while [ $cycle -gt 1 ]
439                         do
440                                 $prefix/tbfast $seqtype $model  -f "-"$gop  -h "-"$aof  $param_fft   -JAx < pre > /dev/null 2>&1 || exit 1
441                                 cycle=`expr $cycle - 1`
442                         done
443                         if [ $iterate -gt 0 ]; then
444                                 if [ $distance == "sixtuples" ]; then
445                                     $prefix/dndpre       < pre     > /dev/null 2>&1 || exit 1
446                                 fi
447                                 $prefix/dvtditr $scorecalcopt $localparam -F -z 50 $seqtype $model -f "-"$gop -h "-"$aof -A -c -I $iterate $param_it < pre     > /dev/null 2>&1 || exit 1
448                         fi
449                 else
450                         if [ $distance = "subopt" ]; then
451                                 $prefix/pairlocalalign   $seqtype -b 62  -g $lexp -f $lgop  -h $laof -O $LGOP -E $LEXP -S < infile > /dev/null  || exit 1
452                                 $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   -Ax < infile   > /dev/null || exit 1
453                         elif [ $distance = "fasta" ]; then
454                                 $prefix/dndfast7 $swopt < infile > /dev/null     || exit 1
455                                 $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  -Ax < infile   > /dev/null || exit 1
456                         elif [ $distance = "blast" ]; then
457                                 $prefix/dndblast < infile > /dev/null     || exit 1
458                                 $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  -Ax < infile   > /dev/null || exit 1
459                         elif [ $distance = "global" ]; then
460                                 $prefix/pairlocalalign   $seqtype $model -f "-"$gop  -h "-"$aof -F  < infile > /dev/null     || exit 1
461                                 $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  -Ax < infile   > /dev/null || exit 1
462                         elif [ $distance = "local" ]; then
463                                 $prefix/pairlocalalign   $seqtype -b 62  -g $lexp -f $lgop  -h $laof -L  < infile > /dev/null     || exit 1
464                                 $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  -Ax < infile   > /dev/null || exit 1
465                         elif [ $distance = "genaf" ]; then
466                                 $prefix/pairlocalalign   $seqtype -b 62  -g $lexp -f $lgop  -h $laof -O $LGOP -E $LEXP -N  < infile > /dev/null     || exit 1
467                                 $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  -Ax < infile   > /dev/null || exit 1
468                         else
469                                 $prefix/disttbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft  -Ax < infile   > pre || exit 1
470                         fi
471                         while [ $cycle -gt 1 ]
472                         do
473                                 $prefix/tbfast $seqtype $model  -f "-"$gop  -h "-"$aof $param_fft  -JAx < pre > /dev/null || exit 1
474                                 cycle=`expr $cycle - 1`
475                         done
476                         if [ $iterate -gt 0 ]; then
477                                 if [ $distance = "sixtuples" ]; then
478                                 $prefix/dndpre       < pre     > /dev/null 2>&1 || exit 1
479                                 fi
480                                 $prefix/dvtditr $scorecalcopt $localparam -F -z 50 $seqtype $model -f "-"$gop -h "-"$aof -A -c -I $iterate $param_it < pre     > /dev/null || exit 1
481                         fi
482                 fi
483 #               cat  < pre             || exit 1
484                 if [ $coreout -eq 0 ]; then
485                         $outputcommand < pre   || exit 1
486                 else
487                         $prefix/setcore -w $corewin -i $corethr $coreext < pre > pre2
488                         $outputcommand < pre2 || exit 1
489                 fi
490         fi
491         )
492         echo '' >/dev/tty
493         if [ $distance = "fasta" ]; then
494                 echo "Pairwise alignments were computed by FASTA" >/dev/tty
495                 echo "(Pearson & Lipman, 1988, PNAS 85:2444-2448)" >/dev/tty
496         fi
497         if [ $distance = "blast" ]; then
498                 echo "Pairwise alignments were computed by BLAST">/dev/tty
499                 echo "(Altschul et al., 1997, NAR 25:3389-3402)">/dev/tty
500         fi
501         printf "\n" >/dev/tty
502         echo 'Strategy:' >/dev/tty
503         printf ' '$strategy >/dev/tty
504         echo ' ('$performance')' >/dev/tty
505         echo ' '$explanation >/dev/tty
506         echo '' >/dev/tty
507         echo "Type '$0 --help' for other options." >/dev/tty
508         echo '' >/dev/tty
509         exit 0;
510 fi
511
512 prog="awk"
513
514 if [ $os != "darwin" ]; then
515         echo "checking nawk"
516         tmpawk=`which nawk 2>/dev/null | awk '{print $1}'`
517         if [ -x $tmpawk ]; then
518                 prog=$tmpawk
519         fi
520
521         echo "checking gawk"
522         tmpawk=`which gawk 2>/dev/null | awk '{print $1}'`
523         if [ -x $tmpawk ]; then
524                 prog=$tmpawk
525         fi
526 fi
527
528 echo "prog="$prog
529
530 umask 077
531 export defaultaof
532 export defaultgop
533 export defaultfft
534 export defaultcycle
535 export defaultiterate
536 (
537 $prog '
538 BEGIN {
539         prefix = ENVIRON["prefix"];
540         version = ENVIRON["version"];
541         myself = ENVIRON["myself"];
542         defaultgop = ENVIRON["defaultgop"]
543         defaultaof = ENVIRON["defaultaof"]
544         defaultfft = ENVIRON["defaultfft"]
545         defaultcycle = ENVIRON["defaultcycle"]
546         defaultiterate = ENVIRON["defaultiterate"]
547         while( 1 )
548         {
549                 options = ""
550                 printf( "\n" ) > "/dev/tty";
551                 printf( "---------------------------------------------------------------------\n" )      > "/dev/tty";
552                 printf( "\n" )                                                                           > "/dev/tty";
553                 printf( "   MAFFT %s\n", version )                                                       > "/dev/tty";
554                 printf( "\n" )                                                                           > "/dev/tty";
555                 printf( "        K. Katoh, K. Misawa, K. Kuma and T. Miyata (2002)\n" )                  > "/dev/tty";
556                 printf( "        Nucleic Acids Research 30: 3059-3066.\n" )                              > "/dev/tty";
557                 printf( "        http://www.biophys.kyoto-u.ac.jp/~katoh/programs/align/mafft\n" )       > "/dev/tty";
558                 printf( "---------------------------------------------------------------------\n" )      > "/dev/tty";
559                 printf( "\n" );
560         
561                 while( 1 )
562                 {
563                         printf( "\n" ) > "/dev/tty";
564                         printf( "Input file? (fasta format)\n@ " ) > "/dev/tty";
565                         res = getline < "/dev/tty";
566                         close( "/dev/tty" )
567                         if( res == 0 || NF == 0 )
568                                 continue;
569                         infile0 = sprintf( "%s", $1 );
570                         infile = sprintf( "%s", $1 );
571         
572                         res = getline < infile;
573                         close( infile );
574                         if( res == -1 )
575                                 printf( "%s: No such file.\n\n", infile );
576                         else if( res == 0 )
577                                 printf( "%s: Empty.\n", infile );
578                         else
579                         {
580                                 printf( "OK. infile = %s\n\n", infile );
581                                 break;
582                         }
583                 }
584                 nseq = 0;
585         
586                 while( 1 )
587                 {
588                         printf( "\n" ) > "/dev/tty";
589                         printf( "Output file?\n" ) > "/dev/tty";
590                         printf( "@ " ) > "/dev/tty";
591                         res = getline < "/dev/tty";
592                         close( "/dev/tty" );
593                         if( res == 0 || NF == 0 )
594                                 continue;
595                         else
596                         {
597                                 outfile = sprintf( "%s", $1 );
598                                 printf( "OK. outfile = %s\n\n", outfile );
599                                 break;
600                         }
601                 }
602         
603         
604                 while( 1 )
605                 {
606                         retree = defaultcycle
607                         printf( "\n" );
608                         printf( "Number of tree-rebuilding?\n" ) > "/dev/tty";
609                         printf( "@ [%d] ", retree ) > "/dev/tty";
610                         res = getline < "/dev/tty";
611                         close( "/dev/tty" );
612                         if( res == 0 )
613                                 continue;
614                         else if( NF == 0 )
615                                 ;
616                         else
617                                 retree = 0 + $1;
618                         if( retree < 1 || 10 < retree )
619                                 ;
620                         else
621                         {
622                                 printf( "OK. %d\n\n", retree );
623                                 break;
624                         }
625                 }
626         
627                 while( 1 )
628                 {
629                         niterate = defaultiterate;
630                         printf( "\n" );
631                         printf( "Maximum number of iterations?\n" ) > "/dev/tty";
632                         printf( "@ [%d] ", niterate ) > "/dev/tty";
633                         res = getline < "/dev/tty";
634                         close( "/dev/tty" );
635                         if( res == 0 )
636                                 continue;
637                         else if( NF == 0 )
638                                 ;
639                         else
640                                 niterate = 0 + $1;
641                         if( niterate < 0 || 1000 < niterate )
642                                 ;
643                         else
644                         {
645                                 printf( "OK. %d\n\n", niterate );
646                                 break;
647                         }
648                 }
649
650                 while( 1 )
651                 {
652                         fft = defaultfft;
653                         printf( "\n" );
654                         printf( "Use fft?\n" ) > "/dev/tty";
655                         printf( "@ [%s] ", fft?"Yes":"No" ) > "/dev/tty";
656                         res = getline < "/dev/tty";
657                         close( "/dev/tty" );
658                         if( res == 0 )
659                                 continue;
660                         else if( NF == 0 )
661                         {
662                                 break;
663                         }
664                         else if( NF == 0 || $0 ~ /^[Yy]/ )
665                         {
666                                 fft = 1;
667                                 break;
668                         }
669                         else if( NF == 0 || $0 ~ /^[Nn]/ )
670                         {
671                                 fft = 0;
672                                 break;
673                         }
674                 }
675                 if( fft )
676                 {
677                                 printf( "OK. FFT is enabled.\n\n" );
678                                 fftparam = " --fft ";
679                 }
680                 else
681                 {
682                                 printf( "OK. FFT is disabled.\n\n" );
683                                 fftparam = " --nofft ";
684                 }
685
686                 while( 1 )
687                 {
688                         scoringmatrix = 3;
689                         printf( "\n" );
690                         printf( "Scoring matrix? (ignored when DNA sequence is input.)\n" ) > "/dev/tty";
691                         printf( " 1. BLOSUM 30\n" ) > "/dev/tty";
692                         printf( " 2. BLOSUM 45\n" ) > "/dev/tty";
693                         printf( " 3. BLOSUM 62\n" ) > "/dev/tty";
694                         printf( " 4. BLOSUM 80\n" ) > "/dev/tty";
695                         printf( " 5. JTT 200\n" ) > "/dev/tty";
696                         printf( " 6. JTT 100\n" ) > "/dev/tty";
697                         printf( "@ [%d] ", scoringmatrix ) > "/dev/tty";
698                         res = getline < "/dev/tty";
699                         close( "/dev/tty" );
700                         if( res == 0 )
701                                 continue;
702                         else if( NF == 0 )
703                                 ;
704                         else
705                                 scoringmatrix = 0 + $1;
706                         if( scoringmatrix < 1 || 6 < scoringmatrix )
707                                 ;
708                         else
709                         {
710                                 break;
711                         }
712                 }
713                 if( scoringmatrix == 1 )
714                         scoringparam = " --bl 30 ";
715                 else if( scoringmatrix == 2 )
716                         scoringparam = " --bl 45 ";
717                 else if( scoringmatrix == 3 )
718                         scoringparam = " --bl 62 ";
719                 else if( scoringmatrix == 4 )
720                         scoringparam = " --bl 80 ";
721                 else if( scoringmatrix == 5 )
722                         scoringparam = " --jtt 200 ";
723                 else if( scoringmatrix == 6 )
724                         scoringparam = " --jtt 100 ";
725                 printf( "OK. %s\n\n",scoringparam );
726         
727                 while( 1 )
728                 {
729                         penalty = 0.0 + defaultgop;
730                         offset = 0.0 + defaultaof;
731                         printf( "\n" );
732                         printf( "Parameters (gap opening penalty, offset)?\n", penalty, offset ) > "/dev/tty";
733                         printf( "@ [%5.3f, %5.3f] ", penalty, offset ) > "/dev/tty";
734                         res = getline < "/dev/tty";
735                         close( "/dev/tty" );
736                         if( res == 0 )
737                                 continue;
738                         else if( NF == 2 )
739                         {
740                                 penalty = 0.0 + $1;
741                                 offset = 0.0 + $2;
742                         }
743                         else if( NF == 0 )
744                                 ;
745                         else
746                                 continue;
747                         if( penalty <= 0.0 || 10.0 < penalty )
748                                 ;
749                         else if( offset <= 0.0 || 10.0 < offset )
750                                 ;
751                         else
752                         {
753                                 printf( "OK. %5.3f %5.3f\n\n", penalty, offset );
754                                 break;
755                         }
756                 }
757         
758                 command = sprintf( "%s %s --retree %d --maxiterate %d %s --op %f --ep %f %s > %s", myself, fftparam, retree, niterate, scoringparam, penalty, offset, infile, outfile );
759                 printf( "%s\n\n", command );
760         
761         
762                 while( 1 )
763                 {
764                         go = 0;
765                         printf( "\n" );
766                         printf( "OK?\n" );
767                         printf( "@ [Y] " ) > "/dev/tty";
768                         res = getline < "/dev/tty";
769                         close( "/dev/tty" );
770                         if( res == 0 )
771                                 continue;
772                         else if( NF == 0 || $0 ~ /^[Yy]/ )
773                         {
774                                 go=1;
775                                 break;
776                         }
777                         else
778                                 break;
779                 }
780                 if( go ) break;
781                 printf( "\n" );
782                 printf( "\n" );
783         }
784         system( command );
785 }
786 '
787 )
788 exit 0;