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