7f2efc78466e2142178d447c21bcc1bfd0bf8041
[jabaws.git] / binaries / src / mafft / scripts / mafft
1 #! /bin/sh
2
3
4 er=0;
5 myself=`dirname "$0"`/`basename "$0"`; export myself
6 version="v6.857b (2011/05/30)"; export version
7 LANG=C; export LANG
8 os=`uname`
9 progname=`basename "$0"`
10 if [ `echo $os | grep -i cygwin` ]; then
11         os="cygwin"
12 elif [ `echo $os | grep -i darwin` ]; then
13         os="darwin"
14 elif [ `echo $os | grep -i sunos` ]; then
15         os="sunos"
16 elif [ `echo $os | grep -i linux` ]; then
17         os="linux"
18 else
19         os="unix"
20 fi
21 export os
22
23 if [ "$MAFFT_BINARIES" ]; then
24         prefix="$MAFFT_BINARIES"
25 else
26         prefix=/usr/local/libexec/mafft
27 fi
28 export prefix
29
30 if [ $# -gt 0 ]; then
31         if [ "$1" = "--man" ]; then 
32                 man "$prefix/mafft.1"
33                 exit 0;
34         fi
35 fi
36
37 if [ ! -x "$prefix/tbfast" ]; then
38         echo "" 1>&2
39         echo "correctly installed?" 1>&2
40         echo "mafft binaries have to be installed in \$MAFFT_BINARIES" 1>&2
41         echo "or the $prefix directory". 1>&2
42         echo "" 1>&2
43         exit 1
44         er=1
45 fi
46
47 defaultiterate=0
48 defaultcycle=2
49 defaultgop="1.53"
50 #defaultaof="0.123"
51 defaultaof="0.000"
52 defaultlaof="0.100"
53 defaultlgop="-2.00"
54 defaultfft=1
55 defaultrough=0
56 defaultdistance="sixtuples"
57 #defaultdistance="local"
58 defaultweighti="2.7"
59 defaultweightr="0.0"
60 defaultweightm="1.0"
61 defaultmccaskill=0
62 defaultcontrafold=0
63 defaultalgopt="  "
64 defaultalgoptit="  "
65 defaultsbstmodel=" -b 62 "
66 defaultfmodel=" "
67 defaultkappa=" "
68 if [ $progname = "xinsi" -o $progname = "mafft-xinsi" ]; then
69         defaultfft=1
70         defaultcycle=1
71         defaultiterate=1000
72         defaultdistance="scarna"
73         defaultweighti="3.2"
74         defaultweightr="8.0"
75         defaultweightm="2.0"
76         defaultmccaskill=1
77         defaultcontrafold=0
78         defaultalgopt=" -A "
79         defaultalgoptit=" -AB " ## chui
80         defaultaof="0.0"
81         defaultsbstmodel=" -b 62 "
82         defaultkappa=" "
83         defaultfmodel=" -a "
84 elif [ $progname = "qinsi" -o $progname = "mafft-qinsi" ]; then
85         defaultfft=1
86         defaultcycle=1
87         defaultiterate=1000
88         defaultdistance="global"
89         defaultweighti="3.2"
90         defaultweightr="8.0"
91         defaultweightm="2.0"
92         defaultmccaskill=1
93         defaultcontrafold=0
94         defaultalgopt=" -A "
95         defaultalgoptit=" -AB " ## chui
96         defaultaof="0.0"
97         defaultsbstmodel=" -b 62 "
98         defaultkappa=" "
99         defaultfmodel=" -a "
100 elif [ $progname = "linsi" -o $progname = "mafft-linsi" ]; then
101         defaultfft=0
102         defaultcycle=1
103         defaultiterate=1000
104         defaultdistance="local"
105 elif [ $progname = "ginsi" -o $progname = "mafft-ginsi" ]; then
106         defaultfft=1
107         defaultcycle=1
108         defaultiterate=1000
109         defaultdistance="global"
110 elif [ $progname = "einsi" -o $progname = "mafft-einsi" ]; then
111         defaultfft=0
112         defaultcycle=1
113         defaultiterate=1000
114         defaultdistance="localgenaf"
115 elif [ $progname = "fftns" -o $progname = "mafft-fftns" ]; then
116         defaultfft=1
117         defaultcycle=2
118         defaultdistance="sixtuples"
119 elif [ $progname = "fftnsi" -o $progname = "mafft-fftnsi" ]; then
120         defaultfft=1
121         defaultcycle=2
122         defaultiterate=2
123         defaultdistance="sixtuples"
124 elif [ $progname = "nwns" -o $progname = "mafft-nwns" ]; then
125         defaultfft=0
126         defaultcycle=2
127         defaultdistance="sixtuples"
128 elif [ $progname = "nwnsi" -o $progname = "mafft-nwnsi" ]; then
129         defaultfft=0
130         defaultcycle=2
131         defaultiterate=2
132         defaultdistance="sixtuples"
133 fi
134 outputfile=""
135 namelength=15
136 anysymbol=0
137 parallelizationstrategy="BAATARI2"
138 kappa=$defaultkappa
139 sbstmodel=$defaultsbstmodel
140 fmodel=$defaultfmodel
141 gop=$defaultgop
142 aof=$defaultaof
143 cycle=$defaultcycle
144 iterate=$defaultiterate
145 fft=$defaultfft
146 rough=$defaultrough
147 distance=$defaultdistance
148 forcefft=0
149 memopt=" "
150 weightopt=" "
151 GGOP="-6.00"
152 LGOP="-6.00"
153 LEXP="-0.000"
154 GEXP="-0.000"
155 lgop=$defaultlgop
156 lexp="-0.100"
157 laof=$defaultlaof
158 pggop="-2.00"
159 pgexp="-0.10"
160 pgaof="0.10"
161 rgop="-1.530"
162 rgep="-0.000"
163 seqtype="  "
164 weighti=$defaultweighti
165 weightr=$defaultweightr
166 weightm=$defaultweightm
167 rnaalifold=0
168 mccaskill=$defaultmccaskill
169 contrafold=$defaultcontrafold
170 quiet=0
171 debug=0
172 sw=0
173 algopt=$defaultalgopt
174 algoptit=$defaultalgoptit
175 scorecalcopt=" "
176 coreout=0
177 corethr="0.5"
178 corewin="100"
179 coreext=" "
180 outputformat="pir"
181 outorder="input"
182 seed="x"
183 seedtable="x"
184 auto=0
185 groupsize=-1
186 partsize=50
187 partdist="sixtuples"
188 partorderopt=" -x "
189 treeout=0
190 distout=0
191 treein=0
192 topin=0
193 treeinopt="  "
194 seedfiles="/dev/null"
195 seedtablefile="/dev/null"
196 aamatrix="/dev/null"
197 treeinfile="/dev/null"
198 rnascoremtx=" "
199 laraparams="/dev/null"
200 foldalignopt=" "
201 treealg=" -X "
202 scoreoutarg=" "
203 numthreads=0
204 randomseed=0
205 addfile="/dev/null"
206 addarg0=" "
207 outnum=" "
208 if [ $# -gt 0 ]; then
209         while [ $# -gt 1 ];
210         do
211                 if [ "$1" = "--auto" ]; then 
212                         auto=1
213                 elif [ "$1" = "--anysymbol" ]; then 
214                         anysymbol=1
215                 elif [ "$1" = "--preservecase" ]; then 
216                         anysymbol=1
217                 elif [ "$1" = "--clustalout" ]; then 
218                         outputformat="clustal"
219                 elif [ "$1" = "--phylipout" ]; then 
220                         outputformat="phylip"
221                 elif [ "$1" = "--reorder" ]; then 
222                         outorder="aligned"
223                         partorderopt=" "
224                 elif [ "$1" = "--inputorder" ]; then 
225                         outorder="input"
226                         partorderopt=" -x "
227                 elif [ "$1" = "--unweight" ]; then 
228                         weightopt=" -u "
229                 elif [ "$1" = "--algq" ]; then 
230                         algopt=" -Q "
231                         algoptit=" -QB "
232                 elif [ "$1" = "--namelength" ]; then 
233                         shift   
234                         namelength=`expr "$1" - 0`
235                 elif [ "$1" = "--groupsize" ]; then 
236                         shift   
237                         groupsize=`expr "$1" - 0`
238                 elif [ "$1" = "--partsize" ]; then 
239                         shift   
240                         partsize=`expr "$1" - 0`
241                 elif [ "$1" = "--parttree" ]; then 
242                         distance="parttree"
243                         partdist="sixtuples"
244                 elif [ "$1" = "--dpparttree" ]; then 
245                         distance="parttree"
246                         partdist="localalign"
247                 elif [ "$1" = "--fastaparttree" ]; then 
248                         distance="parttree"
249                         partdist="fasta"
250                 elif [ "$1" = "--treeout" ]; then 
251                         treeout=1
252                 elif [ "$1" = "--distout" ]; then 
253                         distout=1
254                 elif [ "$1" = "--fastswpair" ]; then
255                         distance="fasta"
256                         sw=1
257                 elif [ "$1" = "--fastapair" ]; then
258                         distance="fasta"
259                         sw=0
260                 elif [ "$1" = "--averagelinkage" ]; then
261                         treealg=" -E "
262                 elif [ "$1" = "--minimumlinkage" ]; then
263                         treealg=" -q "
264                 elif [ "$1" = "--noscore" ]; then
265                         scorecalcopt=" -Z "
266                 elif [ "$1" = "--6merpair" ]; then
267                         distance="sixtuples"
268                 elif [ "$1" = "--blastpair" ]; then
269                         distance="blast"
270                 elif [ "$1" = "--globalpair" ]; then
271                         distance="global"
272                 elif [ "$1" = "--localpair" ]; then
273                         distance="local"
274                 elif [ "$1" = "--scarnapair" ]; then
275                         distance="scarna"
276                 elif [ "$1" = "--larapair" ]; then
277                         distance="lara"
278                 elif [ "$1" = "--slarapair" ]; then
279                         distance="slara"
280                 elif [ "$1" = "--foldalignpair" ]; then
281                         distance="foldalignlocal"
282                 elif [ "$1" = "--foldalignlocalpair" ]; then
283                         distance="foldalignlocal"
284                 elif [ "$1" = "--foldalignglobalpair" ]; then
285                         distance="foldalignglobal"
286                 elif [ "$1" = "--globalgenafpair" ]; then
287                         distance="globalgenaf"
288                 elif [ "$1" = "--localgenafpair" ]; then
289                         distance="localgenaf"
290                 elif [ "$1" = "--genafpair" ]; then
291                         distance="localgenaf"
292                 elif [ "$1" = "--memsave" ]; then
293                         memopt=" -M -B "         # -B (bunkatsunashi no riyu ga omoidasenai)
294                 elif [ "$1" = "--nomemsave" ]; then
295                         memopt=" -N "
296                 elif [ "$1" = "--nuc" ]; then 
297                         seqtype=" -D "
298                 elif [ "$1" = "--amino" ]; then 
299                         seqtype=" -P "
300                 elif [ "$1" = "--fft" ]; then 
301                         fft=1
302                         forcefft=1
303                 elif [ "$1" = "--nofft" ]; then 
304                         fft=0
305                 elif [ "$1" = "--quiet" ]; then 
306                         quiet=1
307                 elif [ "$1" = "--debug" ]; then 
308                         debug=1
309                 elif [ "$1" = "--coreext" ]; then 
310                         coreext=" -c "
311                 elif [ "$1" = "--core" ]; then 
312                         coreout=1
313                 elif [ "$1" = "--out" ]; then 
314                         shift   
315                         outputfile="$1"
316                 elif [ "$1" = "--thread" ]; then 
317                         shift
318                         numthreads=`expr "$1" - 0` 
319                 elif [ "$1" = "--randomseed" ]; then 
320                         shift
321                         randomseed=`expr "$1" - 0` 
322                 elif [ "$1" = "--bestfirst" ]; then 
323                         parallelizationstrategy="BESTFIRST"
324                 elif [ "$1" = "--adhoc0" ]; then 
325                         parallelizationstrategy="BAATARI0"
326                 elif [ "$1" = "--adhoc1" ]; then 
327                         parallelizationstrategy="BAATARI1"
328                 elif [ "$1" = "--adhoc2" ]; then 
329                         parallelizationstrategy="BAATARI2"
330                 elif [ "$1" = "--simplehillclimbing" ]; then 
331                         parallelizationstrategy="BAATARI2"
332                 elif [ "$1" = "--scoreout" ]; then 
333                         scoreoutarg="-S -B"
334                 elif [ "$1" = "--outnum" ]; then 
335                         scoreoutarg="-n"
336                 elif [ "$1" = "--addprofile" ]; then 
337                         shift   
338                         addarg0="-I"
339                         addfile="$1"
340                 elif [ "$1" = "--add" ]; then 
341                         shift   
342                         addarg0="-K -I"
343                         addfile="$1"
344                 elif [ "$1" = "--maxiterate" ]; then 
345                         shift   
346                         iterate=`expr "$1" - 0` 
347                 elif [ "$1" = "--retree" ]; then 
348                         shift   
349                         cycle=`expr "$1" - 0`
350                 elif [ "$1" = "--aamatrix" ]; then 
351                         shift   
352                         sbstmodel=" -b -1 "
353                         aamatrix="$1"
354                 elif [ "$1" = "--treein" ]; then 
355                         shift   
356                         treeinopt=" -U "
357                         treein=1
358                         treeinfile="$1"
359                 elif [ "$1" = "--topin" ]; then 
360                         shift   
361                         treeinopt=" -V "
362                         treein=1
363                         treeinfile="$1"
364                         echo "The --topin option has been disabled." 1>&2
365                         echo "There was a bug in version < 6.530."   1>&2
366                         echo "This bug has not yet been fixed."      1>&2
367                         exit 1
368                 elif [ "$1" = "--kappa" ]; then 
369                         shift   
370                         kappa=" -k $1 "
371                 elif [ "$1" = "--fmodel" ]; then 
372                         fmodel=" -a "
373                 elif [ "$1" = "--jtt" ]; then 
374                         shift   
375                         sbstmodel=" -j $1"
376                 elif [ "$1" = "--kimura" ]; then 
377                         shift   
378                         sbstmodel=" -j $1"
379                 elif [ "$1" = "--tm" ]; then 
380                         shift   
381                         sbstmodel=" -m $1"
382                 elif [ "$1" = "--bl" ]; then 
383                         shift   
384                         sbstmodel=" -b $1"
385                 elif [ "$1" = "--weighti" ]; then
386                         shift   
387                         weighti="$1"
388                 elif [ "$1" = "--weightr" ]; then
389                         shift   
390                         weightr="$1"
391                 elif [ "$1" = "--weightm" ]; then
392                         shift   
393                         weightm="$1"
394                 elif [ "$1" = "--rnaalifold" ]; then
395                         rnaalifold=1
396                 elif [ "$1" = "--mccaskill" ]; then
397                         mccaskill=1
398                         contrafold=0
399                 elif [ "$1" = "--contrafold" ]; then
400                         mccaskill=0
401                         contrafold=1
402                 elif [ "$1" = "--ribosum" ]; then
403                         rnascoremtx=" -s "
404                 elif [ "$1" = "--op" ]; then 
405                         shift   
406                         gop="$1"
407                 elif [ "$1" = "--ep" ]; then 
408                         shift   
409                         aof="$1"
410                 elif [ "$1" = "--rop" ]; then 
411                         shift   
412                         rgop="$1"
413                 elif [ "$1" = "--rep" ]; then 
414                         shift   
415                         rgep="$1"
416                 elif [ "$1" = "--lop" ]; then 
417                         shift   
418                         lgop="$1"
419                 elif [ "$1" = "--LOP" ]; then 
420                         shift   
421                         LGOP="$1"
422                 elif [ "$1" = "--lep" ]; then 
423                         shift   
424                         laof="$1"
425                 elif [ "$1" = "--lexp" ]; then 
426                         shift   
427                         lexp="$1"
428                 elif [ "$1" = "--LEXP" ]; then 
429                         shift   
430                         LEXP="$1"
431                 elif [ "$1" = "--GEXP" ]; then 
432                         shift   
433                         GEXP="$1"
434                 elif [ "$1" = "--GOP" ]; then 
435                         shift   
436                         GGOP="$1"
437                 elif [ "$1" = "--gop" ]; then 
438                         shift   
439                         pggop="$1"
440                 elif [ "$1" = "--gep" ]; then 
441                         shift   
442                         pgaof="$1"
443                 elif [ "$1" = "--gexp" ]; then 
444                         shift   
445                         pgexp="$1"
446                 elif [ "$1" = "--laraparams" ]; then 
447                         shift   
448                         laraparams="$1"
449                 elif [ "$1" = "--corethr" ]; then 
450                         shift   
451                         corethr="$1"
452                 elif [ "$1" = "--corewin" ]; then 
453                         shift   
454                         corewin="$1"
455                 elif [ "$1" = "--seedtable" ]; then
456                         shift
457                         seedtable="y"
458                         seedtablefile="$1"
459                 elif [ "$1" = "--seed" ]; then
460                         shift
461                         seed="m"
462                         seedfiles="$seedfiles $1"
463                 elif [ $progname = "fftns" -o  $progname = "nwns" ]; then
464                         if [ "$1" -gt 0 ]; then
465                                 cycle=`expr "$1" - 0`
466                         fi
467                 else
468                         echo "Unknown option:  $1" 1>&2
469                         er=1;
470                 fi
471                 shift   
472         done;
473
474
475
476 #       TMPFILE=/tmp/$progname.$$
477         TMPFILE=`mktemp -dt $progname.XXXXXXXXXX`
478         if [ $? -ne 0 ]; then
479                 echo "mktemp seems to be obsolete. Re-trying without -t" 1>&2
480                 TMPFILE=`mktemp -d /tmp/$progname.XXXXXXXXXX`
481         fi      
482         umask 077
483 #       mkdir  $TMPFILE  || er=1
484         if [ $debug -eq 1 ]; then
485                 trap "tar cfvz debuginfo.tgz $TMPFILE; rm -rf $TMPFILE " 0
486         else
487                 trap "rm -rf $TMPFILE " 0
488         fi
489         if [ $# -eq 1 ]; then
490                 if [ -r "$1" -o "$1" = - ]; then
491
492                         if [ -r "$addfile" ]; then
493                                 printf '';
494                         else
495                                 echo "$0": Cannot open "$addfile". 1>&2
496                                 exit 1;
497                         fi
498
499                         cat "$1"              | tr "\r" "\n" > $TMPFILE/infile 
500                         echo ""                             >> $TMPFILE/infile
501                         cat "$addfile"        | tr "\r" "\n" | grep -v "^$" >> $TMPFILE/infile
502                         cat "$addfile"        | tr "\r" "\n" | grep -v "^$" > $TMPFILE/_addfile
503                         cat "$aamatrix"       | tr "\r" "\n" | grep -v "^$" > $TMPFILE/_aamtx
504                         cat "$treeinfile"     | tr "\r" "\n" | grep -v "^$" > $TMPFILE/_guidetree
505                         cat "$seedtablefile"  | tr "\r" "\n" | grep -v "^$" > $TMPFILE/_seedtablefile
506                         cat "$laraparams"     | tr "\r" "\n" | grep -v "^$" > $TMPFILE/_lara.params
507 #                       echo $seedfiles
508                         infilename="$1"
509                         seedfilesintmp="/dev/null"
510                         seednseq="0"
511                         set $seedfiles > /dev/null
512                         while [ $# -gt 1 ];
513                         do
514                                 shift
515                                 if [ -r "$1" ]; then
516                                         cat "$1" | tr "\r" "\n" >  $TMPFILE/seed$#
517                                 else
518                                         echo "$0": Cannot open "$1". 1>&2
519                                         exit 1;
520                                 fi
521                                 seednseq=$seednseq" "`grep -c '^[>|=]' $TMPFILE/seed$#`
522                                 seedfilesintmp=$seedfilesintmp" "seed$#
523                         done
524 #                       ls $TMPFILE
525 #                       echo $seedfilesintmp
526 #                       echo $seednseq
527
528
529                 else
530                         echo "$0": Cannot open "$1". 1>&2
531                         er=1
532 #                       exit 1;
533                 fi
534         else
535                 echo '$#'"=$#" 1>&2
536                 er=1
537         fi
538
539
540         if [ $os != "linux" ]; then
541                 numthreads=0
542         fi
543
544         if [ $numthreads -eq 0 -a $parallelizationstrategy = "BESTFIRST" ]; then
545                 echo 'Impossible' 1>&2;
546                 exit 1;
547         fi
548
549         if [ $auto -eq 1 ]; then
550                 "$prefix/countlen" < $TMPFILE/infile > $TMPFILE/size
551                 nseq=`awk '{print $1}' $TMPFILE/size`
552                 nlen=`awk '{print $3}' $TMPFILE/size`
553                 if [ $nlen -lt 2000 -a $nseq -lt 100 ]; then
554                         distance="local"
555                         iterate=1000
556                 elif [ $nlen -lt 10000 -a $nseq -lt 500 ]; then
557                         distance="sixtuples"
558                         iterate=2
559                 else
560                         distance="sixtuples"
561                         iterate=0
562                 fi
563                 if [ $quiet -eq 0 ]; then
564                         echo "nseq = " $nseq              1>&2
565                         echo "nlen = " $nlen              1>&2
566                         echo "distance = " $distance      1>&2
567                         echo "iterate = " $iterate        1>&2
568                 fi
569         fi
570
571         if [ $parallelizationstrategy = "BESTFIRST" -o  $parallelizationstrategy = "BAATARI0" ]; then
572                 iteratelimit=254
573         else
574                 iteratelimit=16
575         fi
576         if [ $iterate -gt $iteratelimit ]; then    #??
577                 iterate=$iteratelimit
578         fi
579
580         if [ $rnaalifold -eq 1 ]; then
581                 rnaopt=" -e $rgep -o $rgop -c $weightm -r $weightr -R $rnascoremtx "
582 #               rnaoptit=" -o $rgop -BT -c $weightm -r $weightr -R "
583                 rnaoptit=" -o $rgop -F -c $weightm -r $weightr -R "
584         elif [ $mccaskill -eq 1 -o $contrafold -eq 1 ]; then
585                 rnaopt=" -o $rgop -c $weightm -r $weightr "
586 #               rnaoptit=" -e $rgep -o $rgop -BT -c $weightm -r $weightr $rnascoremtx "
587                 rnaoptit=" -e $rgep -o $rgop -F -c $weightm -r $weightr $rnascoremtx "
588         else
589                 rnaopt="  "
590                 rnaoptit=" -F "
591         fi
592
593         model="$sbstmodel $kappa $fmodel"
594
595         if [ $er -eq 1 ]; then
596                 echo "------------------------------------------------------------------------------" 1>&2
597                 echo "  MAFFT" $version 1>&2
598 #               echo "" 1>&2
599 #               echo "  Input format: fasta" 1>&2
600 #               echo ""  1>&2
601 #               echo "  Usage: `basename $0` [options] inputfile > outputfile" 1>&2
602             echo "  http://mafft.cbrc.jp/alignment/software/" 1>&2
603                 echo "  NAR 30:3059-3066 (2002), Briefings in Bioinformatics 9:286-298 (2008)"        1>&2
604 #               echo "------------------------------------------------------------------------------" 1>&2
605 #               echo "  % mafft in > out" 1>&2
606                 echo "------------------------------------------------------------------------------" 1>&2
607 #               echo ""  1>&2
608                 echo "High speed:" 1>&2
609                 echo "  % mafft in > out" 1>&2
610                 echo "  % mafft --retree 1 in > out (fast)" 1>&2
611                 echo "" 1>&2
612                 echo "High accuracy (for <~200 sequences x <~2,000 aa/nt):" 1>&2
613                 echo "  % mafft --maxiterate 1000 --localpair  in > out (% linsi in > out is also ok)" 1>&2
614                 echo "  % mafft --maxiterate 1000 --genafpair  in > out (% einsi in > out)" 1>&2
615                 echo "  % mafft --maxiterate 1000 --globalpair in > out (% ginsi in > out)" 1>&2
616                 echo "" 1>&2
617                 echo "If unsure which option to use:" 1>&2
618                 echo "  % mafft --auto in > out" 1>&2
619                 echo "" 1>&2
620 #               echo "Other options:" 1>&2
621                 echo "--op # :         Gap opening penalty, default: 1.53" 1>&2
622                 echo "--ep # :         Offset (works like gap extension penalty), default: 0.0" 1>&2
623                 echo "--maxiterate # : Maximum number of iterative refinement, default: 0" 1>&2
624                 echo "--clustalout :   Output: clustal format, default: fasta" 1>&2
625                 echo "--reorder :      Outorder: aligned, default: input order" 1>&2
626                 echo "--quiet :        Do not report progress" 1>&2
627                 echo "--thread # :     Number of threads. (# must be <= number of physical cores - 1)" 1>&2
628 #               echo "" 1>&2
629 #               echo " % mafft --maxiterate 1000 --localpair in > out (L-INS-i)" 1>&2
630 #               echo " most accurate in many cases, assumes only one alignable domain" 1>&2 
631 #               echo "" 1>&2
632 #               echo " % mafft --maxiterate 1000 --genafpair in > out (E-INS-i)" 1>&2
633 #               echo " works well if many unalignable residues exist between alignable domains" 1>&2
634 #               echo "" 1>&2
635 #               echo " % mafft --maxiterate 1000 --globalpair in > out (G-INS-i)" 1>&2
636 #               echo " suitable for globally alignable sequences            " 1>&2
637 #               echo "" 1>&2
638 #               echo " % mafft --maxiterate 1000 in > out (FFT-NS-i)" 1>&2
639 #               echo " accurate and slow, iterative refinement method      " 1>&2
640 #               echo "" 1>&2
641 #               echo "If the input sequences are long (~1,000,000nt)," 1>&2
642 #               echo " % mafft --retree 1 --memsave --fft in > out (FFT-NS-1-memsave, new in v5.8)" 1>&2
643 #               echo "" 1>&2
644 #               echo "If many (~5,000) sequences are to be aligned," 1>&2
645 #               echo "" 1>&2
646 #               echo " % mafft --retree 1 [--memsave] --nofft in > out (NW-NS-1, new in v5.8)" 1>&2
647 #               echo "" 1>&2
648 #               echo " --localpair :      All pairwise local alignment information is included"  1>&2
649 #               echo "                    to the objective function, default: off"  1>&2
650 #               echo " --globalpair :     All pairwise global alignment information is included"  1>&2
651 #               echo "                    to the objective function, default: off"  1>&2
652 #               echo " --op # :           Gap opening penalty, default: $defaultgop " 1>&2
653 #               echo " --ep # :           Offset (works like gap extension penalty), default: $defaultaof " 1>&2
654 #               echo " --bl #, --jtt # :  Scoring matrix, default: BLOSUM62" 1>&2
655 #               echo "                    Alternatives are BLOSUM (--bl) 30, 45, 62, 80, " 1>&2
656 #               echo "                    or JTT (--jtt) # PAM. " 1>&2
657 #               echo " --nuc or --amino : Sequence type, default: auto" 1>&2
658 #               echo " --retree # :       The number of tree building in progressive method " 1>&2
659 #               echo "                    (see the paper for detail), default: $defaultcycle " 1>&2
660 #               echo " --maxiterate # :   Maximum number of iterative refinement, default: $defaultiterate " 1>&2
661 #               if [ $defaultfft -eq 1 ]; then
662 #                       echo " --fft or --nofft:  FFT is enabled or disabled, default: enabled" 1>&2
663 #               else
664 #                       echo " --fft or --nofft:  FFT is enabled or disabled, default: disabled" 1>&2
665 #               fi
666 #               echo " --memsave:         Memory saving mode" 1>&2
667 #               echo "                    (for long genomic sequences), default: off" 1>&2
668 #               echo " --clustalout :     Output: clustal format, default: fasta" 1>&2
669 #               echo " --reorder :        Outorder: aligned, default: input order" 1>&2
670 #               echo " --quiet :          Do not report progress" 1>&2
671 #               echo "-----------------------------------------------------------------------------" 1>&2
672                 exit 1; 
673         fi
674         if [ $sw -eq 1 ]; then
675                 swopt=" -A "
676         else
677                 swopt=" "
678         fi
679
680         if [ $distance = "fasta" -o $partdist = "fasta" ]; then
681                 if [ ! "$FASTA_4_MAFFT" ]; then
682                         FASTA_4_MAFFT=`which fasta34`
683                 fi
684
685                 if [ ! -x "$FASTA_4_MAFFT" ]; then
686                         echo ""       1>&2
687                         echo "== Install FASTA ========================================================" 1>&2
688                         echo "This option requires the fasta34 program (FASTA version x.xx or higher)"   1>&2
689                         echo "installed in your PATH.  If you have the fasta34 program but have renamed" 1>&2
690                         echo "(like /usr/local/bin/myfasta), set the FASTA_4_MAFFT environment variable" 1>&2
691                         echo "to point your fasta34 (like setenv FASTA_4_MAFFT /usr/local/bin/myfasta)." 1>&2
692                         echo "=========================================================================" 1>&2
693                         echo "" 1>&2
694                         exit 1
695                 fi
696         fi
697         if [ $distance = "lara" -o $distance = "slara" ]; then
698                 if [ ! -x "$prefix/mafft_lara" ]; then
699                         echo ""       1>&2
700                         echo "== Install LaRA =========================================================" 1>&2
701                         echo "This option requires LaRA (Bauer et al. http://www.planet-lisa.net/)."     1>&2
702                         echo "The executable have to be renamed to 'mafft_lara' and installed into "     1>&2
703                         echo "the $prefix directory. "                                                   1>&2
704                         echo "A configuration file of LaRA also have to be given"                        1>&2
705                         echo "mafft-xinsi --larapair --laraparams parameter_file"                        1>&2
706                         echo "mafft-xinsi --slarapair --laraparams parameter_file"                       1>&2
707                         echo "=========================================================================" 1>&2
708                         echo "" 1>&2
709                         exit 1
710                 fi
711                 if [ ! -s "$laraparams" ]; then
712                         echo ""       1>&2
713                         echo "== Configure LaRA =======================================================" 1>&2
714                         echo "A configuration file of LaRA have to be given"                             1>&2
715                         echo "mafft-xinsi --larapair --laraparams parameter_file"                        1>&2
716                         echo "mafft-xinsi --slarapair --laraparams parameter_file"                       1>&2
717                         echo "=========================================================================" 1>&2
718                         echo "" 1>&2
719                         exit 1
720                 fi
721         fi
722         if [ $distance = "foldalignlocal" -o $distance = "foldalignglobal" ]; then
723         if [ ! -x "$prefix/foldalign210" ]; then
724                         echo ""       1>&2
725                         echo "== Install FOLDALIGN ====================================================" 1>&2
726                         echo "This option requires FOLDALIGN (Havgaard et al. http://foldalign.ku.dk/)." 1>&2
727                         echo "The executable have to be renamed to 'foldalign210' and installed into "   1>&2
728                         echo "the $prefix directory. "                                                   1>&2
729                         echo "=========================================================================" 1>&2
730                         echo "" 1>&2
731                         exit 1
732                 fi
733         fi
734         if [ $distance = "scarna" ]; then
735                 if [ ! -x "$prefix/mxscarnamod" ]; then
736                         echo ""       1>&2
737                         echo "== Install MXSCARNA ======================================================" 1>&2
738                         echo "MXSCARNA (Tabei et al. BMC Bioinformatics 2008 9:33) is required."          1>&2
739                         echo "Please 'make' at the 'extensions' directory of the MAFFT source package,"   1>&2
740                         echo "which contains the modified version of MXSCARNA."                           1>&2
741                         echo "http://align.bmr.kyushu-u.ac.jp/mafft/software/source.html "                1>&2
742                         echo "==========================================================================" 1>&2
743                         echo "" 1>&2
744                         exit 1
745                 fi
746         fi
747         if [ $mccaskill -eq 1 ]; then
748                 if [ ! -x "$prefix/mxscarnamod" ]; then
749                         echo ""       1>&2
750                         echo "== Install MXSCARNA ======================================================" 1>&2
751                         echo "MXSCARNA (Tabei et al. BMC Bioinformatics 2008 9:33) is required."          1>&2
752                         echo "Please 'make' at the 'extensions' directory of the MAFFT source package,"   1>&2
753                         echo "which contains the modified version of MXSCARNA."                           1>&2
754                         echo "http://align.bmr.kyushu-u.ac.jp/mafft/software/source.html "                1>&2
755                         echo "==========================================================================" 1>&2
756                         echo "" 1>&2
757                         exit 1
758                 fi
759         fi
760         if [ $contrafold -eq 1 ]; then
761                 if [ ! -x "$prefix/contrafold" ]; then
762                         echo ""       1>&2
763                         echo "== Install CONTRAfold ===================================================" 1>&2
764                         echo "This option requires CONTRAfold"                                           1>&2
765                         echo "(Do et al. http://contra.stanford.edu/contrafold/)."                       1>&2
766                         echo "The executable 'contrafold' have to be installed into "                    1>&2
767                         echo "the $prefix directory. "                                                   1>&2
768                         echo "=========================================================================" 1>&2
769                         echo "" 1>&2
770                         exit 1
771                 fi
772         fi
773
774 #old
775 #       if [ $treeout -eq 1 ]; then
776 #               parttreeoutopt="-t"
777 #               if [ $cycle -eq 0 ]; then
778 #                       treeoutopt="-t -T"
779 #                       groupsize=1
780 #                       iterate=0 
781 #                       if [ $distance = "global" -o $distance = "local" -o $distance = "localgenaf" -o $distance = "globalgenaf" ]; then
782 #                               distance="distonly"
783 #                       fi
784 #               else
785 #                       treeoutopt="-t"
786 #               fi
787 #       else
788 #               parttreeoutopt=" "
789 #               if [ $cycle -eq 0 ]; then
790 #                       treeoutopt="-t -T"
791 #                       iterate=0 
792 #                       if [ $distance = "global" -o $distance = "local" -o $distance = "localgenaf" -o $distance = "globalgenaf" ]; then
793 #                               distance="distonly"
794 #                       fi
795 #               else
796 #                       treeoutopt=" "
797 #               fi
798 #       fi
799
800 #new
801         if [ $cycle -eq 0 ]; then
802                 treeoutopt="-t -T"
803                 iterate=0 
804                 if [ $distance = "global" -o $distance = "local" -o $distance = "localgenaf" -o $distance = "globalgenaf" ]; then
805                         distance="distonly"
806                 fi
807                 if [ $treeout -eq 1 ]; then
808                         parttreeoutopt="-t"
809                         groupsize=1
810                 else
811                         parttreeoutopt=" "
812                 fi
813                 if [ $distout -eq 1 ]; then
814                         distoutopt="-y -T"
815                 fi
816         else
817                 if [ $treeout -eq 1 ]; then
818                         parttreeoutopt="-t"
819                         treeoutopt="-t"
820                 else
821                         parttreeoutopt=" "
822                         treeoutopt=" "
823                 fi
824                 if [ $distout -eq 1 ]; then
825                         distoutopt="-y"
826                 fi
827         fi
828 #
829
830         formatcheck=`grep -c '^[[:blank:]]\+>' $TMPFILE/infile | head -1 `
831         if [ $formatcheck -gt 0 ]; then
832                 echo "The first character of a description line must be " 1>&2
833                 echo "the greater-than (>) symbol, not a blank."           1>&2
834                 echo "Please check the format around the following line(s):"  1>&2
835                 grep -n '^[[:blank:]]\+>' $TMPFILE/infile  1>&2
836                 exit 1
837         fi
838
839         nseq=`grep -c '^[>|=]' $TMPFILE/infile | head -1 ` 
840         if [ $nseq -eq 2 ]; then
841                 cycle=1
842         fi
843         if [ $cycle -gt 3 ]; then
844                 cycle=3
845         fi
846
847         if [ $nseq -gt 4000 -a $iterate -gt 1 ]; then
848                 echo "Too many sequences to perform iterative refinement!" 1>&2
849                 echo "Please use a progressive method." 1>&2
850                 exit 1
851         fi
852
853
854         if [ $distance = "sixtuples" -a \( $seed = "x" -a $seedtable = "x" \) ]; then
855                 localparam=" "
856         elif [ $distance = "sixtuples" -a \( $seed != "x" -o $seedtable != "x" \) ]; then
857                 if [ $cycle -lt 2 ]; then
858                         cycle=2                # nazeda
859                 fi
860                 if [ $iterate -lt 2 ]; then
861                         echo "############################################################################" 1>&2
862                         echo "# Warning:" 1>&2
863                         echo "#   Progressive alignment method is incompatible with the --seed option." 1>&2
864                         echo "#   Automatically switched to the iterative refinement method." 1>&2
865                         echo "#   " 1>&2
866                         echo "# Also consider using the '--add' option, which is compatible with" 1>&2
867                         echo "#   the progressive method and FASTER than the '--seed' option." 1>&2
868                         echo "#   Usage is:" 1>&2
869                         echo "#   % mafft --add newSequences existingAlignment > output" 1>&2
870                         echo "############################################################################" 1>&2
871                         iterate=2
872                 fi
873                 localparam="-l "$weighti
874         elif [ $distance = "parttree" ]; then
875                 localparam=" "
876                 if [ $groupsize -gt -1 ]; then
877                         cycle=1
878                 fi
879         else
880                 localparam=" -l "$weighti
881                 if [ $cycle -gt 1 ]; then  # 09/01/08
882                         cycle=1
883                 fi
884         fi
885
886         if [ $distance = "localgenaf" -o $distance = "globalgenaf" ]; then
887                 aof="0.000"
888         fi
889
890         if [ "$memopt" = " -M -B " -a "$distance" != "sixtuples" ]; then
891                 echo "Impossible" 1>&2
892                 exit 1
893         fi
894 #exit
895
896         if [ $distance = "parttree" ]; then
897                 if [ $seed != "x" -o $seedtable != "x" ]; then
898                         echo "Impossible" 1>&2
899                         exit 1
900                 fi
901                 if [ $iterate -gt 1 ]; then
902                         echo "Impossible" 1>&2
903                         exit 1
904                 fi
905                 if [ $outorder = "aligned" ]; then
906                         outorder="input"
907                 fi
908                 outorder="input"   # partorder ga kiku
909                 if [ $partdist = "localalign" ]; then
910                         splitopt=" -L "    # -L -l -> fast 
911                 elif [ $partdist = "fasta" ]; then
912                         splitopt=" -S "
913                 else
914                         splitopt="  "
915                 fi
916         fi
917
918
919 #       if [ $nseq -gt 5000 ]; then
920 #               fft=0
921 #       fi
922         if [ $forcefft -eq 1 ]; then
923                 param_fft=" -G "
924                 fft=1
925         elif [ $fft -eq 1 ]; then
926                 param_fft=" -F "
927         else
928                 param_fft=" "
929         fi
930
931         if [ $seed != "x" -a $seedtable != "x" ]; then
932                         echo 'Use either one of seedtable and seed.  Not both.' 1>&2
933                         exit 1
934         fi
935 #       if [ $seedtable != "x" -a $anysymbol -gt 0 ]; then
936 #                       echo 'The combination of --seedtable and --anysymbol is not supported.' 1>&2
937 #                       exit 1
938 #       fi
939
940         if [ $treein -eq 1 ]; then
941 #               if [ $iterate -gt 0 ]; then
942 #                       echo 'Not supported yet.' 1>&2
943 #                       exit 1
944 #               fi
945                 cycle=1
946         fi
947
948         if [ "$addarg0" != " " ]; then
949                 "$prefix/countlen" < $TMPFILE/_addfile > $TMPFILE/addsize
950                 nadd=`awk '{print $1}' $TMPFILE/addsize`
951                 if [ $nadd -eq "0" ]; then
952                         echo Check $addfile 1>&2
953                         exit 1;
954                 fi
955                 addarg="$addarg0 $nadd"
956                 cycle=1
957                 iterate=0
958                 if [ $seed != "x" -o $seedtable != "x" ]; then
959                         echo 'Impossible' 1>&2;
960                         echo 'Use either ONE of --seed, --seedtable, --addprofile and --add.' 1>&2
961                         exit 1;
962                 fi
963         fi
964
965         if [ $mccaskill -eq 1 -o $rnaalifold -eq 1 -o $contrafold -eq 1 ]; then
966                 if [ $distance = "sixtuples" ]; then
967                         echo 'Not supported.' 1>&2
968                         echo 'Please add --globalpair, --localpair, --scarnapair,' 1>&2
969                         echo '--larapair, --slarapair, --foldalignlocalpair or --foldalignglobalpair' 1>&2
970                         exit 1
971                 fi
972         fi
973
974         if [ $mccaskill -eq 1 -o $rnaalifold -eq 1 -o $contrafold -eq 1 ]; then
975                 if [ $distance = "scarna" -o $distance = "lara" -o $distance = "slara" -o $distance = "foldalignlocal" -o $distance = "foldalignglobal" ]; then
976                         strategy="X-I"
977                 elif [ $distance = "global" -o $distance = "local" -o $distance = "localgenaf" -o "globalgenaf" ]; then
978                         strategy="Q-I"
979                 fi
980         elif [ $distance = "fasta" -a $sw -eq 0 ]; then
981                 strategy="F-I"
982         elif [ $distance = "fasta" -a $sw -eq 1 ]; then
983                 strategy="H-I"
984         elif [ $distance = "blast" ]; then
985                 strategy="B-I"
986         elif [ $distance = "global" -o $distance = "distonly" ]; then
987                 strategy="G-I"
988         elif [ $distance = "local" ]; then
989                 strategy="L-I"
990         elif [ $distance = "localgenaf" ]; then
991                 strategy="E-I"
992         elif [ $distance = "globalgenaf" ]; then
993                 strategy="K-I"
994         elif [ $fft -eq 1 ]; then
995                 strategy="FFT-"
996         else
997                 strategy="NW-"
998         fi
999         strategy=$strategy"NS-"
1000         if [ $iterate -gt 0 ]; then
1001                 strategy=$strategy"i"
1002         elif [ $distance = "parttree" ]; then
1003                 if [ $partdist = "fasta" ]; then
1004                         strategy=$strategy"FastaPartTree-"$cycle
1005                 elif [ $partdist = "localalign" ]; then
1006                         strategy=$strategy"DPPartTree-"$cycle
1007                 else
1008                         strategy=$strategy"PartTree-"$cycle
1009                 fi
1010         else
1011                 strategy=$strategy$cycle
1012         fi
1013
1014         explanation='?'
1015         performance='Not tested.'
1016         if [ $strategy = "F-INS-i" ]; then
1017                 explanation='Iterative refinement method (<'$iterate') with LOCAL pairwise alignment information'
1018                 performance='Most accurate, but very slow'
1019         elif [ $strategy = "L-INS-i" ]; then
1020                 explanation='Iterative refinement method (<'$iterate') with LOCAL pairwise alignment information'
1021                 performance='Probably most accurate, very slow'
1022         elif [ $strategy = "E-INS-i" ]; then
1023                 explanation='Iterative refinement method (<'$iterate') with LOCAL pairwise alignment with generalized affine gap costs (Altschul 1998)'
1024                 performance='Suitable for sequences with long unalignable regions, very slow'
1025         elif [ $strategy = "G-INS-i" ]; then
1026                 explanation='Iterative refinement method (<'$iterate') with GLOBAL pairwise alignment information'
1027                 performance='Suitable for sequences of similar lengths, very slow'
1028         elif [ $strategy = "X-INS-i" ]; then
1029                 explanation='RNA secondary structure information is taken into account.'
1030                 performance='For short RNA sequences only, extremely slow'
1031         elif [ $strategy = "F-INS-1" ]; then
1032                 explanation='Progressive method incorporating LOCAL pairwise alignment information'
1033         elif [ $strategy = "L-INS-1" ]; then
1034                 explanation='Progressive method incorporating LOCAL pairwise alignment information'
1035         elif [ $strategy = "G-INS-1" ]; then
1036                 explanation='Progressive method incorporating GLOBAL pairwise alignment information'
1037         elif [ $strategy = "FFT-NS-i" -o $strategy = "NW-NS-i" ]; then
1038                 explanation='Iterative refinement method (max. '$iterate' iterations)'
1039                 if [ $iterate -gt 2 ]; then
1040                         performance='Accurate but slow'
1041                 else
1042                         performance='Standard'
1043                 fi
1044         elif [ $strategy = "FFT-NS-2" -o $strategy = "NW-NS-2" ]; then
1045                 explanation='Progressive method (guide trees were built '$cycle' times.)'
1046                 performance='Fast but rough'
1047         elif [ $strategy = "FFT-NS-1" -o $strategy = "NW-NS-1" ]; then
1048                 explanation='Progressive method (rough guide tree was used.)'
1049                 performance='Very fast but very rough'
1050         fi
1051
1052         if [ $outputformat = "clustal" -a $outorder = "aligned" ]; then
1053                 outputopt=" -c $strategy -r $TMPFILE/order  "
1054         elif [ $outputformat = "clustal" -a $outorder = "input" ]; then
1055                 outputopt=" -c $strategy  "
1056         elif [ $outputformat = "phylip" -a $outorder = "aligned" ]; then
1057                 outputopt=" -y -r $TMPFILE/order "
1058         elif [ $outputformat = "phylip" -a $outorder = "input" ]; then
1059                 outputopt=" -y "
1060         elif [ $outputformat = "pir" -a $outorder = "aligned" ]; then
1061                 outputopt=" -f -r $TMPFILE/order "
1062         else
1063                 outputopt="null"
1064         fi
1065         
1066         (
1067                 cd $TMPFILE;
1068
1069                 if [ $quiet -gt 0 ]; then
1070
1071                         if [ $anysymbol -eq 1 ]; then
1072                                 mv infile orig
1073                                 "$prefix/replaceu" -i orig > infile 2>/dev/null || exit 1
1074                         fi
1075
1076                         if [ $seed != "x" ]; then
1077                                 mv infile infile2
1078                                 if [ $anysymbol -eq 1 ]; then
1079                                         mv orig orig2
1080                                         cat /dev/null > orig
1081                                 fi
1082                                 cat /dev/null > infile
1083                                 cat /dev/null > hat3.seed
1084                                 seedoffset=0
1085 #                               echo "seednseq="$seednseq
1086 #                               echo "seedoffset="$seedoffset
1087                                 set $seednseq > /dev/null
1088 #                               echo $#
1089                                 while [ $# -gt 1 ]
1090                                 do
1091                                         shift
1092 #                                       echo "num="$#
1093
1094                                         if [ $anysymbol -eq 1 ]; then
1095                                                 cat seed$# >> orig
1096                                                 "$prefix/replaceu" -i seed$# -o $seedoffset > clean 2>/dev/null || exit 1
1097                                                 mv clean seed$#
1098                                         fi
1099                                         "$prefix/multi2hat3s" -t $nseq -o $seedoffset -i seed$# >> infile 2>/dev/null || exit 1
1100                                         cat hat3 >> hat3.seed
1101 #                                       echo "$1"
1102                                         seedoffset=`expr $seedoffset + $1`
1103 #                                       echo "$1"
1104 #                                       echo "seedoffset="$seedoffset
1105                                 done;
1106 #                               echo "seedoffset="$seedoffset
1107                                 if [ $anysymbol -eq 1 ]; then
1108                                         "$prefix/replaceu" -i orig2 -o $seedoffset >> infile 2>/dev/null || exit 1  # yarinaoshi
1109                                         cat orig2 >> orig
1110                                 else
1111                                         cat infile2 >> infile
1112                                 fi
1113                         elif [ $seedtable != "x" ]; then
1114                                 cat _seedtablefile > hat3.seed
1115                         else
1116                                 cat /dev/null > hat3.seed
1117                         fi
1118 #                       cat hat3.seed
1119
1120
1121                         if [ $mccaskill -eq 1 ]; then
1122                                 "$prefix/mccaskillwrap" -C $numthreads -d "$prefix" -i infile > hat4 2>/dev/null || exit 1
1123                         elif [ $contrafold -eq 1 ]; then
1124                                 "$prefix/contrafoldwrap" -d "$prefix" -i infile > hat4 2>/dev/null || exit 1
1125                         fi
1126                         if [ $distance = "fasta" ]; then
1127                                 "$prefix/dndfast7" $swopt < infile > /dev/null  2>&1      || exit 1
1128                                 cat hat3.seed hat3 > hatx
1129                                 mv hatx hat3
1130                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
1131                         elif [ $distance = "blast" ]; then
1132                                 "$prefix/dndblast" < infile > /dev/null  2>&1      || exit 1
1133                                 cat hat3.seed hat3 > hatx
1134                                 mv hatx hat3
1135                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
1136                         elif [ $distance = "foldalignlocal" ]; then
1137                                 "$prefix/pairlocalalign" -C $numthreads $seqtype $foldalignopt $model -g $lexp -f $lgop -h $laof -H -d "$prefix" < infile > /dev/null  2>&1      || exit 1
1138                                 cat hat3.seed hat3 > hatx
1139                                 mv hatx hat3
1140                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
1141                         elif [ $distance = "foldalignglobal" ]; then
1142                                 "$prefix/pairlocalalign" -C $numthreads $seqtype $foldalignopt $model -g $pgexp -f $pggop -h $pgaof -H -o -global -d "$prefix" < infile > /dev/null  2>&1      || exit 1
1143                                 cat hat3.seed hat3 > hatx
1144                                 mv hatx hat3
1145                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
1146                         elif [ $distance = "slara" ]; then
1147                                 "$prefix/pairlocalalign" -C $numthreads -p $laraparams  $seqtype $model  -f $lgop  -T -d "$prefix" < infile > /dev/null  2>&1      || exit 1
1148                                 cat hat3.seed hat3 > hatx
1149                                 mv hatx hat3
1150                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
1151                         elif [ $distance = "lara" ]; then
1152                                 "$prefix/pairlocalalign" -C $numthreads -p $laraparams  $seqtype $model  -f $lgop  -B -d "$prefix" < infile > /dev/null  2>&1      || exit 1
1153                                 cat hat3.seed hat3 > hatx
1154                                 mv hatx hat3
1155                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
1156                         elif [ $distance = "scarna" ]; then
1157                                 "$prefix/pairlocalalign"   -C $numthreads $seqtype $model  -f $pggop  -s -d "$prefix" < infile > /dev/null  2>&1      || exit 1
1158                                 cat hat3.seed hat3 > hatx
1159                                 mv hatx hat3
1160                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
1161                         elif [ $distance = "global" ]; then
1162                                 "$prefix/pairlocalalign"   -C $numthreads $seqtype $model -g $pgexp -f $pggop  -h $pgaof  -F < infile > /dev/null  2>&1      || exit 1
1163                                 cat hat3.seed hat3 > hatx
1164                                 mv hatx hat3
1165                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
1166                         elif [ $distance = "local" ]; then
1167                                 "$prefix/pairlocalalign"   -C $numthreads $seqtype $model  -g $lexp -f $lgop  -h $laof -L < infile > /dev/null  2>&1      || exit 1
1168                                 cat hat3.seed hat3 > hatx
1169                                 mv hatx hat3
1170                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
1171                         elif [ $distance = "globalgenaf" ]; then
1172                                 "$prefix/pairlocalalign"   -C $numthreads $seqtype $model  -g $pgexp -f $pggop  -h $pgaof -O $GGOP -E $GEXP -K  < infile > /dev/null 2>&1    || exit 1
1173                                 cat hat3.seed hat3 > hatx
1174                                 mv hatx hat3
1175                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
1176                         elif [ $distance = "localgenaf" ]; then
1177                                 "$prefix/pairlocalalign"   -C $numthreads $seqtype $model -g $lexp -f $lgop  -h $laof -O $LGOP -E $LEXP -N < infile > /dev/null  2>&1      || exit 1
1178                                 cat hat3.seed hat3 > hatx
1179                                 mv hatx hat3
1180                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
1181                         elif [ $distance = "distonly" ]; then
1182                                 "$prefix/pairlocalalign"   -C $numthreads $seqtype $model -g $pgexp -f $pggop  -h $pgaof  -t < infile > /dev/null  2>&1      || exit 1
1183                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
1184                         elif [ $distance = "parttree" ]; then
1185                                 "$prefix/splittbfast" -Q $splitopt $partorderopt $parttreeoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft -p $partsize -s $groupsize $treealg -i infile   > pre 2>/dev/null || exit 1
1186                                 mv hat3.seed hat3
1187                         else
1188                                 "$prefix/disttbfast" -O $outnum $addarg -C $numthreads $memopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $algopt $treealg $scoreoutarg < infile   > pre 2>/dev/null || exit 1
1189                                 mv hat3.seed hat3
1190                         fi
1191                         while [ $cycle -gt 1 ]
1192                         do
1193                                 if [ $distance = "parttree" ]; then
1194                                         mv pre infile
1195                                         "$prefix/splittbfast" -Z -Q $splitopt $partorderopt $parttreeoutopt $memopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft -p $partsize -s $groupsize $treealg -i infile   > pre 2>/dev/null || exit 1
1196                                 else
1197                                         "$prefix/tbfast" -O $outnum -C $numthreads $rnaopt $weightopt $treeoutopt $distoutopt $memopt $seqtype $model  -f "-"$gop  -h "-"$aof $param_fft  $localparam $algopt -J $treealg $scoreoutarg < pre > /dev/null 2>&1 || exit 1
1198                                 fi
1199                                 cycle=`expr $cycle - 1`
1200                         done
1201                         if [ $iterate -gt 0 ]; then
1202                                 if [ $distance = "sixtuples" ]; then
1203                                     "$prefix/dndpre" -C $numthreads < pre     > /dev/null 2>&1 || exit 1
1204                                 fi
1205                                 "$prefix/dvtditr" -C $numthreads -t $randomseed $rnaoptit $memopt $scorecalcopt $localparam -z 50 $seqtype $model -f "-"$gop -h "-"$aof  -I $iterate $weightopt $treeinopt $algoptit $treealg -p $parallelizationstrategy  $scoreoutarg < pre     > /dev/null 2>&1 || exit 1
1206                         fi
1207                 else
1208
1209                         if [ $anysymbol -eq 1 ]; then
1210                                 mv infile orig
1211                                 "$prefix/replaceu" -i orig > infile || exit 1
1212                         fi
1213
1214                         if [ $seed != "x" ]; then
1215                                 mv infile infile2
1216                                 if [ $anysymbol -eq 1 ]; then
1217                                         mv orig orig2
1218                                         cat /dev/null > orig
1219                                 fi
1220                                 cat /dev/null > infile
1221                                 cat /dev/null > hat3.seed
1222                                 seedoffset=0
1223 #                               echo "seednseq="$seednseq
1224 #                               echo "seedoffset="$seedoffset
1225                                 set $seednseq > /dev/null
1226 #                               echo $#
1227                                 while [ $# -gt 1 ]
1228                                 do
1229                                         shift
1230 #                                       echo "num="$#
1231
1232                                         if [ $anysymbol -eq 1 ]; then
1233                                                 cat seed$# >> orig
1234                                                 "$prefix/replaceu" -i seed$# -o $seedoffset > clean || exit 1
1235                                                 mv clean seed$#
1236                                         fi
1237                                         "$prefix/multi2hat3s" -t $nseq -o $seedoffset -i seed$# >> infile || exit 1
1238                                         cat hat3 >> hat3.seed
1239 #                                       echo "$1"
1240                                         seedoffset=`expr $seedoffset + $1`
1241 #                                       echo "$1"
1242 #                                       echo "seedoffset="$seedoffset
1243                                 done;
1244 #                               echo "seedoffset="$seedoffset
1245                                 if [ $anysymbol -eq 1 ]; then
1246                                         "$prefix/replaceu" -i orig2 -o $seedoffset >> infile || exit 1 # yarinaoshi
1247                                         cat orig2 >> orig
1248                                 else
1249                                         cat infile2 >> infile
1250                                 fi
1251                         elif [ $seedtable != "x" ]; then
1252                                 cat _seedtablefile > hat3.seed
1253                         else
1254                                 cat /dev/null > hat3.seed
1255                         fi
1256 #                       cat hat3.seed
1257
1258                         if [ $mccaskill -eq 1 ]; then
1259                                 "$prefix/mccaskillwrap" -C $numthreads -d "$prefix" -i infile > hat4  || exit 1
1260                         elif [ $contrafold -eq 1 ]; then
1261                                 "$prefix/contrafoldwrap" -d "$prefix" -i infile > hat4  || exit 1
1262                         fi
1263                         if [ $distance = "fasta" ]; then
1264                                 "$prefix/dndfast7" $swopt < infile > /dev/null     || exit 1
1265                                 cat hat3.seed hat3 > hatx
1266                                 mv hatx hat3
1267                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  $algopt $treealg $scoreoutarg < infile   > /dev/null || exit 1
1268                         elif [ $distance = "blast" ]; then
1269                                 "$prefix/dndblast" < infile > /dev/null     || exit 1
1270                                 cat hat3.seed hat3 > hatx
1271                                 mv hatx hat3
1272                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  $algopt $treealg $scoreoutarg < infile   > /dev/null || exit 1
1273                         elif [ $distance = "foldalignlocal" ]; then
1274                                 "$prefix/pairlocalalign" -C $numthreads $seqtype $foldalignopt $model -g $lexp -f $lgop -h $laof -H -d "$prefix" < infile > /dev/null || exit 1
1275                                 cat hat3.seed hat3 > hatx
1276                                 mv hatx hat3
1277                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
1278                         elif [ $distance = "foldalignglobal" ]; then
1279                                 "$prefix/pairlocalalign" -C $numthreads $seqtype $foldalignopt $model -g $pgexp -f $pggop  -h $pgaof -H -o -global -d "$prefix" < infile > /dev/null || exit 1
1280                                 cat hat3.seed hat3 > hatx
1281                                 mv hatx hat3
1282                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
1283                         elif [ $distance = "slara" ]; then
1284                                 "$prefix/pairlocalalign" -C $numthreads -p $laraparams  $seqtype $model  -f $lgop  -T -d "$prefix" < infile > /dev/null || exit 1
1285                                 cat hat3.seed hat3 > hatx
1286                                 mv hatx hat3
1287                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
1288                         elif [ $distance = "lara" ]; then
1289                                 "$prefix/pairlocalalign" -C $numthreads -p $laraparams  $seqtype $model  -f $lgop  -B -d "$prefix" < infile > /dev/null || exit 1
1290                                 cat hat3.seed hat3 > hatx
1291                                 mv hatx hat3
1292                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
1293                         elif [ $distance = "scarna" ]; then
1294                                 "$prefix/pairlocalalign"   -C $numthreads $seqtype $model  -f $pggop  -s -d "$prefix" < infile > /dev/null   || exit 1
1295                                 cat hat3.seed hat3 > hatx
1296                                 mv hatx hat3
1297                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
1298                         elif [ $distance = "global" ]; then
1299                                 "$prefix/pairlocalalign"   -C $numthreads $seqtype $model -g $pgexp -f $pggop  -h $pgaof   -F  < infile > /dev/null     || exit 1
1300                                 cat hat3.seed hat3 > hatx
1301                                 mv hatx hat3
1302                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  $algopt $treealg $scoreoutarg < infile   > /dev/null || exit 1
1303                         elif [ $distance = "local" ]; then
1304                                 "$prefix/pairlocalalign"   -C $numthreads $seqtype $model  -g $lexp -f $lgop  -h $laof -L  < infile > /dev/null     || exit 1
1305                                 cat hat3.seed hat3 > hatx
1306                                 mv hatx hat3
1307                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  $algopt $treealg $scoreoutarg < infile   > /dev/null || exit 1
1308                         elif [ $distance = "globalgenaf" ]; then
1309                                 "$prefix/pairlocalalign"   -C $numthreads $seqtype $model  -g $pgexp -f $pggop  -h $pgaof -O $GGOP -E $GEXP -K  < infile > /dev/null     || exit 1
1310                                 cat hat3.seed hat3 > hatx
1311                                 mv hatx hat3
1312                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  $algopt $treealg $scoreoutarg < infile   > /dev/null || exit 1
1313                         elif [ $distance = "localgenaf" ]; then
1314                                 "$prefix/pairlocalalign"   -C $numthreads $seqtype $model  -g $lexp -f $lgop  -h $laof -O $LGOP -E $LEXP -N  < infile > /dev/null     || exit 1
1315                                 cat hat3.seed hat3 > hatx
1316                                 mv hatx hat3
1317                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  $algopt $treealg $scoreoutarg < infile   > /dev/null || exit 1
1318                         elif [ $distance = "distonly" ]; then
1319                                 "$prefix/pairlocalalign"   -C $numthreads $seqtype $model -g $pgexp -f $pggop  -h $pgaof  -t < infile > /dev/null            || exit 1
1320                                 "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  $algopt $treealg $scoreoutarg < infile   > /dev/null || exit 1
1321                         elif [ $distance = "parttree" ]; then
1322                                 "$prefix/splittbfast" -Q $splitopt $partorderopt $parttreeoutopt $memopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft -p $partsize -s $groupsize $treealg -i infile   > pre || exit 1
1323                                 mv hat3.seed hat3
1324                         else
1325                                 "$prefix/disttbfast" -O $outnum $addarg -C $numthreads $memopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft  $algopt $treealg $scoreoutarg < infile   > pre || exit 1
1326                                 mv hat3.seed hat3
1327                         fi
1328
1329                         while [ $cycle -gt 1 ]
1330                         do
1331                                 if [ $distance = "parttree" ]; then
1332                                         mv pre infile
1333                                         "$prefix/splittbfast" -Z -Q $splitopt $partorderopt $parttreeoutopt $memopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft -p $partsize -s $groupsize $treealg -i infile  > pre || exit 1
1334                                 else
1335                                         "$prefix/tbfast" -O $outnum -C $numthreads $rnaopt $weightopt $treeoutopt $distoutopt $memopt $seqtype $model  -f "-"$gop  -h "-"$aof $param_fft $localparam $algopt -J $treealg $scoreoutarg < pre > /dev/null || exit 1
1336                                 fi
1337                                 cycle=`expr $cycle - 1`
1338                         done
1339                         if [ $iterate -gt 0 ]; then
1340                                 if [ $distance = "sixtuples" ]; then
1341                                 "$prefix/dndpre" -C $numthreads < pre     > /dev/null 2>&1 || exit 1
1342                                 fi
1343                                 "$prefix/dvtditr" -C $numthreads -t $randomseed $rnaoptit $memopt $scorecalcopt $localparam -z 50 $seqtype $model -f "-"$gop -h "-"$aof -I $iterate $weightopt $treeinopt $algoptit $treealg -p $parallelizationstrategy  $scoreoutarg < pre     > /dev/null || exit 1
1344                         fi
1345                 fi
1346
1347                 if [ $coreout -eq 1 ]; then
1348                         "$prefix/setcore" -w $corewin -i $corethr $coreext < pre > pre2
1349                         mv pre2 pre
1350                 elif [ $anysymbol -eq 1 ]; then
1351                         "$prefix/restoreu" -a pre -i orig > restored || exit 1
1352                         mv restored pre
1353                 fi
1354
1355                 if [ $quiet -eq 0 ]; then
1356                         echo '' 1>&2
1357                         if [ $mccaskill -eq 1 ]; then
1358                                 echo "RNA base pairing probaility was calculated by the McCaskill algorithm (1)" 1>&2
1359                                 echo "implemented in Vienna RNA package (2) and MXSCARNA (3), and then" 1>&2
1360                                 echo "incorporated in the iterative alignment process (4)." 1>&2
1361                                 echo "(1) McCaskill, 1990, Biopolymers 29:1105-1119" 1>&2
1362                                 echo "(2) Hofacker et al., 2002, J. Mol. Biol. 319:3724-3732" 1>&2
1363                                 echo "(3) Tabei et al., 2008, BMC Bioinformatics 9:33" 1>&2
1364                                 echo "(4) Katoh and Toh, 2008, BMC Bioinformatics 9:212" 1>&2
1365                                 echo "" 1>&2
1366                         elif [ $contrafold -eq 1 ]; then
1367                                 echo "RNA base pairing probaility was calculated by the CONTRAfold algorithm (1)" 1>&2
1368                                 echo "and then incorporated in the iterative alignment process (4)." 1>&2
1369                                 echo "(1) Do et al., 2006, Bioinformatics 22:e90-98" 1>&2
1370                                 echo "(2) Katoh and Toh, 2008, BMC Bioinformatics 9:212" 1>&2
1371                                 echo "" 1>&2
1372                         fi
1373                         if [ $distance = "fasta" -o $partdist = "fasta" ]; then
1374                                 echo "Pairwise alignments were computed by FASTA" 1>&2
1375                                 echo "(Pearson & Lipman, 1988, PNAS 85:2444-2448)" 1>&2
1376                         fi
1377                         if [ $distance = "blast" ]; then
1378                                 echo "Pairwise alignments were computed by BLAST" 1>&2
1379                                 echo "(Altschul et al., 1997, NAR 25:3389-3402)" 1>&2
1380                         fi
1381                         if [ $distance = "scarna" ]; then
1382                                 echo "Pairwise alignments were computed by MXSCARNA" 1>&2
1383                                 echo "(Tabei et al., 2008, BMC Bioinformatics 9:33)." 1>&2
1384                         fi
1385                         if [ $distance = "lara" -o $distance = "slara" ]; then
1386                                 echo "Pairwise alignments were computed by LaRA" 1>&2
1387                                 echo "(Bauer et al., 2007, BMC Bioinformatics 8:271)." 1>&2
1388                         fi
1389                         if [ $distance = "foldalignlocal" ]; then
1390                                 echo "Pairwise alignments were computed by FOLDALIGN (local)" 1>&2
1391                                 echo "(Havgaard et al., 2007, PLoS Computational Biology 3:e193)." 1>&2
1392                         fi
1393                         if [ $distance = "foldalignglobal" ]; then
1394                                 echo "Pairwise alignments were computed by FOLDALIGN (global)" 1>&2
1395                                 echo "(Havgaard et al., 2007, PLoS Computational Biology 3:e193)." 1>&2
1396                         fi
1397                         printf "\n" 1>&2
1398                         echo 'Strategy:' 1>&2
1399                         printf ' '$strategy 1>&2
1400                         echo ' ('$performance')' 1>&2
1401                         echo ' '$explanation 1>&2
1402                         echo '' 1>&2
1403                         echo "If unsure which option to use, try 'mafft --auto input > output'." 1>&2
1404 #                       echo "If long gaps are expected, try 'mafft --ep 0.0 --auto input > output'." 1>&2
1405                         echo "If the possibility of long gaps can be excluded, add '--ep 0.123'." 1>&2
1406                         echo "For more information, see 'mafft --help', 'mafft --man' and the mafft page." 1>&2
1407                         echo '' 1>&2
1408                 fi
1409         )
1410
1411         if [ "$outputfile" = "" ]; then
1412                 if [ "$outputopt" = "null" ]; then
1413                         cat < $TMPFILE/pre || exit 1
1414                 else
1415                         "$prefix/f2cl" -n $namelength $outputopt < $TMPFILE/pre || exit 1
1416                 fi
1417         else
1418                 if [ "$outputopt" = "null" ]; then
1419                         cat < $TMPFILE/pre > "$outputfile" || exit 1
1420                 else
1421                         "$prefix/f2cl" -n $namelength $outputopt < $TMPFILE/pre > "$outputfile" || exit 1
1422                 fi
1423         fi
1424
1425         if [ $treeout -eq 1 ]; then
1426                 cp $TMPFILE/infile.tree "$infilename.tree"
1427         fi
1428
1429         if [ $distout -eq 1 ]; then
1430                 cp $TMPFILE/hat2 "$infilename.hat2"
1431         fi
1432
1433         exit 0;
1434 fi
1435
1436 prog="awk"
1437
1438 tmpawk=`which nawk 2>/dev/null | awk '{print $1}'`
1439 if [ -x "$tmpawk" ]; then
1440         prog="$tmpawk"
1441 fi
1442
1443 tmpawk=`which gawk 2>/dev/null | awk '{print $1}'`
1444 if [ -x "$tmpawk" ]; then
1445         prog="$tmpawk"
1446 fi
1447
1448 #echo "prog="$prog 1>&2
1449
1450 umask 077
1451 (
1452 $prog '
1453 BEGIN {
1454         prefix = ENVIRON["prefix"];
1455         version = ENVIRON["version"];
1456         myself = ENVIRON["myself"];
1457         while( 1 )
1458         {
1459                 options = ""
1460                 printf( "\n" ) > "/dev/tty";
1461                 printf( "---------------------------------------------------------------------\n" )      > "/dev/tty";
1462                 printf( "\n" )                                                                           > "/dev/tty";
1463                 printf( "   MAFFT %s\n", version )                                                       > "/dev/tty";
1464                 printf( "\n" )                                                                           > "/dev/tty";
1465                 printf( "        Copyright (c) 2011 Kazutaka Katoh\n" )                                  > "/dev/tty";
1466                 printf( "        NAR 30:3059-3066, NAR 33:511-518\n" )                                   > "/dev/tty";
1467                 printf( "        http://mafft.cbrc.jp/alignment/software/\n" )       > "/dev/tty";
1468                 printf( "---------------------------------------------------------------------\n" )      > "/dev/tty";
1469                 printf( "\n" ) > "/dev/tty";
1470         
1471                 while( 1 )
1472                 {
1473                         printf( "\n" ) > "/dev/tty";
1474                         printf( "Input file? (fasta format)\n@ " ) > "/dev/tty";
1475                         res = getline < "/dev/tty";
1476                         close( "/dev/tty" )
1477                         if( res == 0 || NF == 0 )
1478                                 continue;
1479                         infile = sprintf( "%s", $0 );
1480         
1481                         res = getline < infile;
1482                         close( infile );
1483                         if( res == -1 )
1484                         {
1485                                 printf( "%s: No such file.\n\n", infile ) > "/dev/tty";
1486                                 printf( "Filename extension (eg., .txt) must be typed, if any.\n\n" ) > "/dev/tty";
1487                         }
1488                         else if( res == 0 )
1489                                 printf( "%s: Empty.\n", infile ) > "/dev/tty";
1490                         else
1491                         {
1492                                 printf( "OK. infile = %s\n\n", infile ) > "/dev/tty";
1493                                 break;
1494                         }
1495                 }
1496                 nseq = 0;
1497         
1498                 while( 1 )
1499                 {
1500                         printf( "\n" ) > "/dev/tty";
1501                         printf( "Output file?\n" ) > "/dev/tty";
1502                         printf( "@ " ) > "/dev/tty";
1503                         res = getline < "/dev/tty";
1504                         close( "/dev/tty" );
1505                         if( res == 0 || NF == 0 )
1506                                 continue;
1507                         else
1508                         {
1509                                 outfile = sprintf( "%s", $0 );
1510                                 printf( "OK. outfile = %s\n\n", outfile ) > "/dev/tty";
1511                                 break;
1512                         }
1513                 }
1514         
1515                 while( 1 )
1516                 {
1517                         outargs = "";
1518                         printf( "\n" ) > "/dev/tty";
1519                         printf( "Output format?\n" ) > "/dev/tty";
1520                         printf( "  1. Clustal format / Sorted\n" ) > "/dev/tty";
1521                         printf( "  2. Clustal format / Input order\n" ) > "/dev/tty";
1522                         printf( "  3. Fasta format   / Sorted\n" ) > "/dev/tty";
1523                         printf( "  4. Fasta format   / Input order\n" ) > "/dev/tty";
1524                         printf( "  5. Phylip format  / Sorted\n" ) > "/dev/tty";
1525                         printf( "  6. Phylip format  / Input order\n" ) > "/dev/tty";
1526                         printf( "@ " ) > "/dev/tty";
1527                         res = getline < "/dev/tty";
1528                         close( "/dev/tty" );
1529 #                       printf( "res=%d, NF=%d\n", res, NF );
1530
1531                         resnum = 0 + $1;
1532 #                       printf( "resnum=%d\n", resnum );
1533
1534                         if( resnum < 1 || 6 < resnum )
1535                                 continue;
1536                         else
1537                         {
1538                                 if( resnum == 1 )
1539                                         outargs = "--clustalout --reorder";
1540                                 else if( resnum == 2 )
1541                                         outargs = "--clustalout --inputorder";
1542                                 else if( resnum == 3 )
1543                                         outargs = "--reorder";
1544                                 else if( resnum == 4 )
1545                                         outargs = "--inputorder";
1546                                 else if( resnum == 5 )
1547                                         outargs = "--phylipout --reorder";
1548                                 else if( resnum == 6 )
1549                                         outargs = "--phylipout --inputorder";
1550                                 else
1551                                         continue;
1552                                 printf( "OK. arguments = %s\n\n", outargs ) > "/dev/tty";
1553                                 break;
1554                         }
1555                 }
1556         
1557                 while( 1 )
1558                 {
1559                         arguments = "";
1560                         printf( "\n" ) > "/dev/tty";
1561                         printf( "Strategy?\n" ) > "/dev/tty";
1562                         printf( "  1. --auto\n" ) > "/dev/tty";
1563                         printf( "  2. FFT-NS-1 (fast)\n" ) > "/dev/tty";
1564                         printf( "  3. FFT-NS-2 (default)\n" ) > "/dev/tty";
1565                         printf( "  4. G-INS-i  (accurate)\n" ) > "/dev/tty";
1566                         printf( "  5. L-INS-i  (accurate)\n" ) > "/dev/tty";
1567                         printf( "  6. E-INS-i  (accurate)\n" ) > "/dev/tty";
1568                         printf( "@ " ) > "/dev/tty";
1569                         res = getline < "/dev/tty";
1570                         close( "/dev/tty" );
1571 #                       printf( "res=%d, NF=%d\n", res, NF );
1572
1573                         resnum = 0 + $1;
1574 #                       printf( "resnum=%d\n", resnum );
1575
1576                         if( resnum < 1 || 6 < resnum )
1577                                 continue;
1578                         else
1579                         {
1580                                 if( resnum == 1 )
1581                                         arguments = "--auto";
1582                                 else if( resnum == 2 )
1583                                         arguments = "--retree 1";
1584                                 else if( resnum == 3 )
1585                                         arguments = "--retree 2";
1586                                 else if( resnum == 4 )
1587                                         arguments = "--globalpair --maxiterate 16";
1588                                 else if( resnum == 5 )
1589                                         arguments = "--localpair  --maxiterate 16";
1590                                 else if( resnum == 6 )
1591                                         arguments = "--genafpair  --maxiterate 16";
1592                                 else
1593                                         arguments = sprintf( "%s", $0 );
1594                                 printf( "OK. arguments = %s %s\n\n", arguments, outargs ) > "/dev/tty";
1595                                 break;
1596                         }
1597                 }
1598
1599
1600                 while( 1 )
1601                 {
1602                         printf( "\n" ) > "/dev/tty";
1603                         printf( "Additional arguments? (--ep #, --op #, --kappa #, etc)\n" ) > "/dev/tty";
1604                         printf( "@ " ) > "/dev/tty";
1605                         res = getline < "/dev/tty";
1606                         close( "/dev/tty" );
1607                         if( res == 0 || NF == 0 )
1608                         {
1609                                 break;
1610                         }
1611                         else
1612                         {
1613                                 addargs = sprintf( "%s", $0 );
1614                                 printf( "OK. arguments = %s %s %s\n\n", addargs, arguments, outargs ) > "/dev/tty";
1615                                 break;
1616                         }
1617                 }
1618
1619                 arguments = sprintf( "%s %s %s", addargs, arguments, outargs );
1620
1621                 print ""
1622                 command = sprintf( "\"%s\" %s \"%s\" > \"%s\"", myself, arguments, infile, outfile );
1623                 gsub( /\\/, "/", command );
1624
1625
1626                 printf( "command=\n%s\n", command ) > "/dev/tty";
1627         
1628         
1629                 while( 1 )
1630                 {
1631                         go = 0;
1632                         printf( "OK?\n" ) > "/dev/tty";
1633                         printf( "@ [Y] " ) > "/dev/tty";
1634                         res = getline < "/dev/tty";
1635                         close( "/dev/tty" );
1636                         if( res == 0 )
1637                                 continue;
1638                         else if( NF == 0 || $0 ~ /^[Yy]/ )
1639                         {
1640                                 go=1;
1641                                 break;
1642                         }
1643                         else
1644                                 break;
1645                 }
1646                 if( go ) break;
1647                 printf( "\n" ) > "/dev/tty";
1648                 printf( "\n" ) > "/dev/tty";
1649         }
1650         system( command );
1651         command = sprintf( "less \"%s\"", outfile );
1652         system( command );
1653         printf( "Press Enter to exit." ) > "/dev/tty";
1654         res = getline < "/dev/tty";
1655 }
1656 '
1657 )
1658 exit 0;