JWS-112 Bumping version of Mafft to version 7.310.
[jabaws.git] / binaries / src / mafft / core / mafft
1 #! /bin/bash
2
3 er=0;
4 myself=`dirname "$0"`/`basename "$0"`; export myself
5 version="v7.310 (2017/Mar/17)"; export version
6 LANG=C; export LANG
7 os=`uname`
8 progname=`basename "$0"`
9 if [ `echo $os | grep -i cygwin` ]; then
10         os="cygwin"
11 elif [ `echo $os | grep -i mingw` ]; then
12         os="mingw"
13 elif [ `echo $os | grep -i darwin` ]; then
14         os="darwin"
15 elif [ `echo $os | grep -i sunos` ]; then
16         os="sunos"
17 elif [ `echo $os | grep -i linux` ]; then
18         os="linux"
19 else
20         os="unix"
21 fi
22 export os
23
24 if [ "$MAFFT_BINARIES" ]; then
25         prefix="$MAFFT_BINARIES"
26 else
27         prefix=/usr/local/libexec/mafft
28 fi
29 export prefix
30
31 if [ $# -gt 0 ]; then
32         if [ "$1" = "--man" ]; then 
33                 man "$prefix/mafft.1"
34                 exit 0;
35         fi
36 fi
37
38 if [ -x "$prefix/version" ]; then
39                 versionbin=`"$prefix/version"` # for cygwin 2.7
40         else
41                 versionbin="0.000"
42 fi
43
44 if ! expr "$version" : v"$versionbin" > /dev/null ; then
45         echo "" 1>&2
46         echo "v$versionbin != $version" 1>&2
47         echo "" 1>&2
48         echo "There is a problem in the configuration of your shell." 1>&2
49         echo "Check the MAFFT_BINARIES environmental variable by" 1>&2
50         echo "$ echo \$MAFFT_BINARIES" 1>&2
51         echo "" 1>&2
52         echo "This variable must be *unset*, unless you have installed MAFFT" 1>&2
53         echo "with a special configuration.  To unset this variable, type" 1>&2
54         echo "$ unset MAFFT_BINARIES" 1>&2
55         echo "or" 1>&2
56         echo "% unsetenv MAFFT_BINARIES" 1>&2
57         echo "Then retry" 1>&2
58         echo "$ mafft input > output" 1>&2
59         echo "" 1>&2
60         echo "To keep this change permanently, edit setting files" 1>&2
61         echo "(.bash_profile, .profile, .cshrc, etc) in your home directory" 1>&2
62         echo "to delete the MAFFT_BINARIES line." 1>&2
63         echo "On MacOSX, also edit or remove the .MacOSX/environment.plist file" 1>&2
64         echo "and then re-login (MacOSX 10.6) or reboot (MacOSX 10.7)." 1>&2
65         echo "" 1>&2
66         echo "Please send a problem report to kazutaka.katoh@aist.go.jp," 1>&2
67         echo "if this problem remains." 1>&2
68         echo "" 1>&2
69         exit 1
70         er=1
71 fi
72
73 defaultiterate=0
74 defaultcycle=2
75 defaultgop="1.53"
76 #defaultaof="0.123"
77 defaultaof="0.000"
78 defaultlaof="0.100"
79 defaultlgop="-2.00"
80 defaultfft=1
81 defaultrough=0
82 defaultdistance="ktuples"
83 #defaultdistance="local"
84 defaultweighti="2.7"
85 defaultweightr="0.0"
86 defaultweightm="1.0"
87 defaultdafs=0
88 defaultmccaskill=0
89 defaultcontrafold=0
90 defaultalgopt="  "
91 defaultalgoptit="  "
92 defaultsbstmodel=" -b 62 "
93 defaultfmodel=" "
94 defaultkappa=" "
95 if [ $progname = "xinsi" -o $progname = "mafft-xinsi" ]; then
96         defaultfft=1
97         defaultcycle=1
98         defaultiterate=1000
99         defaultdistance="scarna"
100         defaultweighti="3.2"
101         defaultweightr="8.0"
102         defaultweightm="2.0"
103         defaultmccaskill=1
104         defaultcontrafold=0
105         defaultdafs=0
106         defaultalgopt=" -A "
107         defaultalgoptit=" -AB " ## chui
108         defaultaof="0.0"
109         defaultsbstmodel=" -b 62 "
110         defaultkappa=" "
111         defaultfmodel="    "  # 2013/06/18
112 elif [ $progname = "qinsi" -o $progname = "mafft-qinsi" ]; then
113         defaultfft=1
114         defaultcycle=1
115         defaultiterate=1000
116         defaultdistance="global"
117         defaultweighti="3.2"
118         defaultweightr="8.0"
119         defaultweightm="2.0"
120         defaultmccaskill=1
121         defaultcontrafold=0
122         defaultdafs=0
123         defaultalgopt=" -A "
124         defaultalgoptit=" -AB " ## chui
125         defaultaof="0.0"
126         defaultsbstmodel=" -b 62 "
127         defaultkappa=" "
128         defaultfmodel="    "  # 2013/06/18
129 elif [ $progname = "linsi" -o $progname = "mafft-linsi" ]; then
130         defaultfft=0
131         defaultcycle=1
132         defaultiterate=1000
133         defaultdistance="local"
134 elif [ $progname = "ginsi" -o $progname = "mafft-ginsi" ]; then
135         defaultfft=1
136         defaultcycle=1
137         defaultiterate=1000
138         defaultdistance="global"
139 elif [ $progname = "einsi" -o $progname = "mafft-einsi" ]; then
140         defaultfft=0
141         defaultcycle=1
142         defaultiterate=1000
143         defaultdistance="localgenaf"
144 elif [ $progname = "fftns" -o $progname = "mafft-fftns" ]; then
145         defaultfft=1
146         defaultcycle=2
147         defaultdistance="ktuples"
148 elif [ $progname = "fftnsi" -o $progname = "mafft-fftnsi" ]; then
149         defaultfft=1
150         defaultcycle=2
151         defaultiterate=2
152         defaultdistance="ktuples"
153 elif [ $progname = "nwns" -o $progname = "mafft-nwns" ]; then
154         defaultfft=0
155         defaultcycle=2
156         defaultdistance="ktuples"
157 elif [ $progname = "nwnsi" -o $progname = "mafft-nwnsi" ]; then
158         defaultfft=0
159         defaultcycle=2
160         defaultiterate=2
161         defaultdistance="ktuples"
162 fi
163 outputfile=""
164 namelength=-1
165 anysymbol=0
166 parallelizationstrategy="BAATARI2"
167 kappa=$defaultkappa
168 sbstmodel=$defaultsbstmodel
169 fmodel=$defaultfmodel
170 nmodel=" "
171 gop=$defaultgop
172 gopdist=$defaultgop
173 aof=$defaultaof
174 cycle=$defaultcycle
175 iterate=$defaultiterate
176 fft=$defaultfft
177 rough=$defaultrough
178 distance=$defaultdistance
179 forcefft=0
180 memopt=" "
181 weightopt=" "
182 GGOP="-6.00"
183 LGOP="-6.00"
184 LEXP="-0.000"
185 GEXP="-0.000"
186 lgop=$defaultlgop
187 lexp="-0.100"
188 laof=$defaultlaof
189 pggop="-2.00"
190 pgexp="-0.10"
191 pgaof="0.10"
192 rgop="-1.530"
193 rgep="-0.000"
194 seqtype="  "
195 weighti=$defaultweighti
196 weightr=$defaultweightr
197 weightm=$defaultweightm
198 rnaalifold=0
199 dafs=$defaultdafs
200 mccaskill=$defaultmccaskill
201 contrafold=$defaultcontrafold
202 progressfile="/dev/stderr"
203 debug=0
204 sw=0
205 algopt=$defaultalgopt
206 algoptit=$defaultalgoptit
207 #algspecified=0
208 pairspecified=0
209 scorecalcopt=" "
210 coreout=0
211 corethr="0.5"
212 corewin="100"
213 coreext=" "
214 outputformat="pir"
215 f2clext="-N"
216 outorder="input"
217 seed="x"
218 seedtable="x"
219 auto=0
220 groupsize=-1
221 partsize=50
222 partdist="ktuples"
223 partorderopt=" -x "
224 treeout=0
225 distout=0
226 treein=0
227 topin=0
228 treeinopt="  "
229 seedfiles="/dev/null"
230 seedtablefile="/dev/null"
231 pdblist="/dev/null"
232 ownlist="/dev/null"
233 strdir="$PWD"
234 aamatrix="/dev/null"
235 treeinfile="/dev/null"
236 rnascoremtx=" "
237 laraparams="/dev/null"
238 foldalignopt=" "
239 treealg=" -X 0.1 "
240 sueff="1.0"
241 scoreoutarg=" "
242 numthreads=0
243 numthreadsit=-1
244 numthreadstb=-1
245 randomseed=0
246 addfile="/dev/null"
247 addarg0=" "
248 addarg=" "
249 addsinglearg=" "
250 add2ndhalfarg=" "
251 mapoutfile="/dev/null"
252 fragment=0
253 legacygapopt=" "
254 mergetable="/dev/null"
255 mergearg=" "
256 seedoffset=0
257 outnum=" "
258 last_e=5000
259 last_m=3
260 last_subopt=" "
261 last_once=" "
262 adjustdirection=0
263 tuplesize=6
264 termgapopt=" -O "
265 #termgapopt=" " # gap/gap ga kakenai node
266 similarityoffset="0.0"
267 unalignlevel="0.0"
268 unalignspecified=0
269 spfactor="100.0"
270 shiftpenaltyspecified=0
271 opdistspecified=0
272 allowshift=0
273 enrich=0
274 enrichseq=0
275 enrichstr=0
276 seektarget=""
277 fixthreshold="0.0"
278 bunkatsuopt=" "
279 npickup=0
280 minimumweight="0.00001" # 2016/Mar
281 usenaivepairscore=" "
282 oldgenafparam=0
283 sprigorous=0
284 pileuporshuffle="l"
285 initialramusage="20GB"
286 focusarg=" "
287 if [ $# -gt 0 ]; then
288         if [ "$1" = "--version" ]; then
289                 echo "$version" 1>&2
290                 exit 0;
291         elif [ "$1" = "--help" -o "$1" = "--info" ]; then 
292                 shift
293                 er=1;
294         fi
295         while [ $# -gt 1 ];
296         do
297                 if [ "$1" = "--auto" ]; then 
298                         auto=1
299                 elif [ "$1" = "--anysymbol" ]; then 
300                         anysymbol=1
301                 elif [ "$1" = "--preservecase" ]; then 
302                         anysymbol=1
303                 elif [ "$1" = "--clustalout" ]; then 
304                         outputformat="clustal"
305                 elif [ "$1" = "--phylipout" ]; then 
306                         outputformat="phylip"
307                 elif [ "$1" = "--reorder" ]; then 
308                         outorder="aligned"
309                         partorderopt=" "
310                 elif [ "$1" = "--inputorder" ]; then 
311                         outorder="input"
312                         partorderopt=" -x "
313                 elif [ "$1" = "--unweight" ]; then 
314                         weightopt=" -u "
315                 elif [ "$1" = "--termgappenalty" ]; then 
316                         termgapopt=" "
317                 elif [ "$1" = "--alga" ]; then 
318                         algopt=" "
319                         algoptit=" "
320 #                       algspecified=1
321                 elif [ "$1" = "--algq" ]; then 
322                         algopt=" -Q "
323                         algoptit=" "
324                         echo "" 1>&2
325                         echo "--algq is no longer supported!" 1>&2
326                         echo "" 1>&2
327                         exit 1;
328 #                       algspecified=1
329                 elif [ "$1" = "--namelength" ]; then 
330                         shift   
331                         namelength=`expr "$1" - 0`
332                         if ! expr "$1" : "[0-9]" > /dev/null ; then
333                                 echo "Specify the length of name in clustal format output!" 1>&2
334                                 exit
335                         fi
336                 elif [ "$1" = "--groupsize" ]; then 
337                         shift   
338                         groupsize=`expr "$1" - 0`
339                         if ! expr "$1" : "[0-9]" > /dev/null ; then
340                                 echo "Specify groupsize!" 1>&2
341                                 exit
342                         fi
343                 elif [ "$1" = "--partsize" ]; then 
344                         shift   
345                         partsize=`expr "$1" - 0`
346                         if ! expr "$1" : "[0-9]" > /dev/null ; then
347                                 echo "Specify partsize!" 1>&2
348                                 exit
349                         fi
350                 elif [ "$1" = "--parttree" ]; then 
351                         distance="parttree"
352                         partdist="ktuples"
353                 elif [ "$1" = "--dpparttree" ]; then 
354                         distance="parttree"
355                         partdist="localalign"
356                 elif [ "$1" = "--fastaparttree" ]; then 
357                         distance="parttree"
358                         partdist="fasta"
359                 elif [ "$1" = "--treeout" ]; then 
360                         treeout=1
361                 elif [ "$1" = "--distout" ]; then 
362                         distout=1
363                 elif [ "$1" = "--fastswpair" ]; then
364                         distance="fasta"
365                         pairspecified=1
366                         sw=1
367                 elif [ "$1" = "--fastapair" ]; then
368                         distance="fasta"
369                         pairspecified=1
370                         sw=0
371                 elif [ "$1" = "--averagelinkage" ]; then
372                         treealg=" -X 1.0 "
373                         sueff="1.0"
374                 elif [ "$1" = "--minimumlinkage" ]; then
375                         treealg=" -X 0.0 "
376                         sueff="0.0"
377                 elif [ "$1" = "--mixedlinkage" ]; then
378                         shift   
379                         sueff="$1"
380                         treealg=" -X $1"
381                 elif [ "$1" = "--noscore" ]; then
382                         scorecalcopt=" -Z "
383                 elif [ "$1" = "--6mermultipair" ]; then
384                         distance="ktuplesmulti"
385                         tuplesize=6
386                         pairspecified=1
387                 elif [ "$1" = "--10mermultipair" ]; then
388                         distance="ktuplesmulti"
389                         tuplesize=10
390                         pairspecified=1
391                 elif [ "$1" = "--6merpair" ]; then
392                         distance="ktuples"
393                         tuplesize=6
394                         pairspecified=1
395                 elif [ "$1" = "--10merpair" ]; then
396                         distance="ktuples"
397                         tuplesize=10
398                         pairspecified=1
399                 elif [ "$1" = "--blastpair" ]; then
400                         distance="blast"
401                         pairspecified=1
402                 elif [ "$1" = "--lastmultipair" ]; then
403                         distance="lastmulti"
404                         pairspecified=1
405                 elif [ "$1" = "--globalpair" ]; then
406                         distance="global"
407                         pairspecified=1
408                 elif [ "$1" = "--shortlongpair" ]; then
409                         distance="local"
410                         usenaivepairscore="-Z"
411                         laof=0.0  # addfull no tokini tsukawareru.
412                         lexp=0.0  # addfull no tokini tsukawareru.
413                         pgaof=0.0 # local nara iranai
414                         pgexp=0.0 # local nara iranai
415                         pairspecified=1
416                 elif [ "$1" = "--longshortpair" ]; then
417                         distance="local"
418                         usenaivepairscore="-Z"
419                         laof=0.0  # addfull no tokini tsukawareru.
420                         lexp=0.0  # addfull no tokini tsukawareru.
421                         pgaof=0.0 # local nara iranai
422                         pgexp=0.0 # local nara iranai
423                         pairspecified=1
424                 elif [ "$1" = "--localpair" ]; then
425                         distance="local"
426                         pairspecified=1
427                 elif [ "$1" = "--lastpair" ]; then
428                         distance="last"
429                         pairspecified=1
430                 elif [ "$1" = "--multipair" ]; then
431                         distance="multi"
432                         pairspecified=1
433                 elif [ "$1" = "--hybridpair" ]; then
434                         distance="hybrid"
435                         pairspecified=1
436                 elif [ "$1" = "--scarnapair" ]; then
437                         distance="scarna"
438                         pairspecified=1
439                 elif [ "$1" = "--dafspair" ]; then
440                         distance="dafs"
441                         pairspecified=1
442                 elif [ "$1" = "--larapair" ]; then
443                         distance="lara"
444                         pairspecified=1
445                 elif [ "$1" = "--slarapair" ]; then
446                         distance="slara"
447                         pairspecified=1
448                 elif [ "$1" = "--foldalignpair" ]; then
449                         distance="foldalignlocal"
450                         pairspecified=1
451                 elif [ "$1" = "--foldalignlocalpair" ]; then
452                         distance="foldalignlocal"
453                         pairspecified=1
454                 elif [ "$1" = "--foldalignglobalpair" ]; then
455                         distance="foldalignglobal"
456                         pairspecified=1
457                 elif [ "$1" = "--globalgenafpair" ]; then
458                         distance="globalgenaf"
459                         pairspecified=1
460                         echo "" 1>&2
461                         echo "--globalgenaf is no longer supported!" 1>&2
462                         echo "" 1>&2
463                         exit 1;
464                 elif [ "$1" = "--localgenafpair" ]; then
465                         distance="localgenaf"
466                         pairspecified=1
467                 elif [ "$1" = "--genafpair" ]; then
468                         distance="localgenaf"
469                         pairspecified=1
470                 elif [ "$1" = "--oldgenafpair" ]; then
471                         distance="localgenaf"
472                         pairspecified=1
473                         oldgenafparam=1
474                 elif [ "$1" = "--memsave" ]; then
475                         memopt=" -M -B "         # -B (bunkatsunashi no riyu ga omoidasenai)
476                 elif [ "$1" = "--nomemsave" ]; then
477                         memopt=" -N "
478                 elif [ "$1" = "--nuc" ]; then 
479                         seqtype=" -D "
480                 elif [ "$1" = "--amino" ]; then 
481                         seqtype=" -P "
482                 elif [ "$1" = "--fft" ]; then 
483                         fft=1
484                         forcefft=1
485                 elif [ "$1" = "--nofft" ]; then 
486                         fft=0
487                 elif [ "$1" = "--quiet" ]; then 
488                         if [ $os = "mingw" ]; then
489                                 progressfile="nul"
490                         else
491                                 progressfile="/dev/null"
492                         fi
493                 elif [ "$1" = "--debug" ]; then 
494                         debug=1
495                 elif [ "$1" = "--coreext" ]; then 
496                         coreext=" -c "
497                 elif [ "$1" = "--core" ]; then 
498                         coreout=1
499                 elif [ "$1" = "--adjustdirection" ]; then 
500                         adjustdirection=1
501                 elif [ "$1" = "--adjustdirectionaccurately" ]; then 
502                         adjustdirection=2
503                 elif [ "$1" = "--progress" ]; then 
504                         shift   
505                         progressfile="$1"
506                         if ! ( expr "$progressfile" : "\/" > /dev/null || expr "$progressfile" : "[A-Za-z]\:" > /dev/null ) ; then
507                                 echo "Specify a progress file name with the absolute path!" 1>&2
508                                 exit
509                         fi
510                 elif [ "$1" = "--out" ]; then 
511                         shift   
512                         outputfile="$1"
513                 elif [ "$1" = "--thread" ]; then 
514                         shift
515                         if ! expr "$1" : "[0-9\-]" > /dev/null ; then
516                                 echo "Specify the number of threads.  Or, use --thread -1" 1>&2
517                                 exit
518                         fi
519                         numthreads=`expr "$1" - 0` 
520                 elif [ "$1" = "--threadtb" ]; then 
521                         shift
522                         if ! expr "$1" : "[0-9\-]" > /dev/null ; then
523                                 echo "Specify the number of threads for the iterative step!" 1>&2
524                                 exit
525                         fi
526                         numthreadstb=`expr "$1" - 0` 
527                 elif [ "$1" = "--threadit" ]; then 
528                         shift
529                         if ! expr "$1" : "[0-9\-]" > /dev/null ; then
530                                 echo "Specify the number of threads for the iterative step!" 1>&2
531                                 exit
532                         fi
533                         numthreadsit=`expr "$1" - 0` 
534                 elif [ "$1" = "--last_subopt" ]; then 
535                         last_subopt="-S"
536                 elif [ "$1" = "--last_once" ]; then 
537                         last_once="-U"
538                 elif [ "$1" = "--last_m" ]; then 
539                         shift
540                         last_m=`expr "$1" - 0` 
541                 elif [ "$1" = "--last_e" ]; then 
542                         shift
543                         last_e=`expr "$1" - 0` 
544                 elif [ "$1" = "--randomseed" ]; then 
545                         shift
546                         randomseed=`expr "$1" - 0` 
547                 elif [ "$1" = "--bestfirst" ]; then 
548                         parallelizationstrategy="BESTFIRST"
549                 elif [ "$1" = "--adhoc0" ]; then 
550                         parallelizationstrategy="BAATARI0"
551                 elif [ "$1" = "--adhoc1" ]; then 
552                         parallelizationstrategy="BAATARI1"
553                 elif [ "$1" = "--adhoc2" ]; then 
554                         parallelizationstrategy="BAATARI2"
555                 elif [ "$1" = "--simplehillclimbing" ]; then 
556                         parallelizationstrategy="BAATARI2"
557                 elif [ "$1" = "--scoreout" ]; then 
558                         scoreoutarg="-S -B"
559                 elif [ "$1" = "--outnum" ]; then 
560                         outnum="-n"
561                 elif [ "$1" = "--leavegappyregion" ]; then 
562                         legacygapopt="-L"
563                 elif [ "$1" = "--legacygappenalty" ]; then 
564                         legacygapopt="-L"
565                 elif [ "$1" = "--merge" ]; then
566                         shift
567                         mergetable="$1"
568                         if [ ! -e "$mergetable" ]; then
569                                 echo "Cannot open $mergetable" 1>&2
570                                 echo "" 1>&2
571                                 exit
572                         fi
573                 elif [ "$1" = "--addprofile" ]; then 
574                         shift   
575                         addarg0="-I"
576                         addfile="$1"
577                 elif [ "$1" = "--add" ]; then 
578                         shift   
579                         addarg0="-K -I"
580                         addfile="$1"
581                 elif [ "$1" = "--addfragments" ]; then 
582                         shift   
583                         addarg0="-K -I"
584                         addfile="$1"
585                         fragment=1
586                 elif [ "$1" = "--addfull" ]; then 
587                         shift   
588                         addarg0="-K -I"
589                         addfile="$1"
590                         fragment=-1
591                 elif [ "$1" = "--addlong" ]; then 
592                         shift   
593                         addarg0="-K -I"
594                         addfile="$1"
595                         fragment=-2
596                 elif [ "$1" = "--smoothing" ]; then 
597                         add2ndhalfarg=$add2ndhalfarg" -p "
598                 elif [ "$1" = "--keeplength" ]; then 
599                         add2ndhalfarg=$add2ndhalfarg" -Y "
600                 elif [ "$1" = "--mapout" ]; then 
601                         add2ndhalfarg=$add2ndhalfarg" -Z -Y "
602                 elif [ "$1" = "--mapoutfile" ]; then 
603                         shift
604                         add2ndhalfarg=$add2ndhalfarg" -Z -Y "
605                         mapoutfile="$1"
606                 elif [ "$1" = "--maxiterate" ]; then 
607                         shift   
608                         iterate=`expr "$1" - 0` 
609                         if ! expr "$1" : "[0-9]" > /dev/null ; then
610                                 echo "Specify the number of iterations!" 1>&2
611                                 exit
612                         fi
613                 elif [ "$1" = "--retree" ]; then 
614                         shift   
615                         cycle=`expr "$1" - 0`
616                         if ! expr "$1" : "[0-9]" > /dev/null ; then
617                                 echo "Specify the number of tree rebuilding!" 1>&2
618                                 exit
619                         fi
620                 elif [ "$1" = "--text" ]; then 
621                         sbstmodel=" -b -2 -a "
622                         f2clext="-E"
623                         seqtype="-P"
624                         fft=0
625                 elif [ "$1" = "--aamatrix" ]; then 
626                         shift   
627                         sbstmodel=" -b -1 "
628                         aamatrix="$1"
629                         if [ ! -e "$aamatrix" ]; then
630                                 echo "Cannot open $aamatrix" 1>&2
631                                 echo "" 1>&2
632                                 exit
633                         fi
634                 elif [ "$1" = "--treein" ]; then 
635                         shift   
636                         treeinopt=" -U "
637                         treein=1
638                         treeinfile="$1"
639                         if [ ! -e "$treeinfile" ]; then
640                                 echo "Cannot open $treeinfile" 1>&2
641                                 echo "" 1>&2
642                                 exit
643                         fi
644                 elif [ "$1" = "--pileup" ]; then 
645                         treeinopt=" -U "
646                         treein=1
647                         pileuporshuffle="p"
648                 elif [ "$1" = "--randomchain" ]; then 
649                         treeinopt=" -U "
650                         treein=1
651                         pileuporshuffle="s"
652                 elif [ "$1" = "--topin" ]; then 
653                         shift   
654                         treeinopt=" -V "
655                         treein=1
656                         treeinfile="$1"
657                         echo "The --topin option has been disabled." 1>&2
658                         echo "There was a bug in version < 6.530."   1>&2
659                         echo "This bug has not yet been fixed."      1>&2
660                         exit 1
661                 elif [ "$1" = "--memsavetree" ]; then
662                         treeinopt=" -U "
663                         treein=1
664                         pileuporshuffle="C"
665                 elif [ "$1" = "--memsavetreex" ]; then
666                         treeinopt=" -U "
667                         treein=1
668                         pileuporshuffle="c"
669                 elif [ "$1" = "--initialramusage" ]; then 
670                         shift   
671                         treeinopt=" -U "
672                         treein=1
673                         initialramusage="$1"
674                         pileuporshuffle="c"
675                 elif [ "$1" = "--kappa" ]; then 
676                         shift   
677                         kappa=" -k $1 "
678                         if ! expr "$1" : "[0-9]" > /dev/null ; then
679                                 echo "Specify kappa value!" 1>&2
680                                 exit
681                         fi
682                 elif [ "$1" = "--fmodel" ]; then 
683                         fmodel=" -a "
684                 elif [ "$1" = "--nwildcard" ]; then 
685                         nmodel=" -: "
686                 elif [ "$1" = "--nzero" ]; then 
687                         nmodel="  "
688                 elif [ "$1" = "--jtt" ]; then 
689                         shift   
690                         sbstmodel=" -j $1"
691 #                       if ! expr "$1" : "[0-9]" > /dev/null ; then
692 #                               echo "Specify pam value!" 1>&2
693 #                               exit
694 #                       fi
695                 elif [ "$1" = "--kimura" ]; then 
696                         shift   
697                         sbstmodel=" -j $1"
698 #                       if ! expr "$1" : "[0-9]" > /dev/null ; then
699 #                               echo "Specify pam value!" 1>&2
700 #                               exit
701 #                       fi
702                 elif [ "$1" = "--tm" ]; then 
703                         shift   
704                         sbstmodel=" -m $1"
705 #                       if ! expr "$1" : "[0-9]" > /dev/null ; then
706 #                               echo "Specify pam value!" 1>&2
707 #                               exit
708 #                       fi
709                 elif [ "$1" = "--bl" ]; then 
710                         shift   
711                         sbstmodel=" -b $1"
712                         if ! expr "$1" : "[0-9]" > /dev/null ; then
713                                 echo "blosum $1?" 1>&2
714                                 exit
715                         fi
716                 elif [ "$1" = "--weighti" ]; then
717                         shift   
718                         weighti="$1"
719                         if ! expr "$1" : "[0-9]" > /dev/null ; then
720                                 echo "Specify weighti value!" 1>&2
721                                 exit
722                         fi
723                 elif [ "$1" = "--weightr" ]; then
724                         shift   
725                         weightr="$1"
726                         if ! expr "$1" : "[0-9]" > /dev/null ; then
727                                 echo "Specify weightr value!" 1>&2
728                                 exit
729                         fi
730                 elif [ "$1" = "--weightm" ]; then
731                         shift   
732                         weightm="$1"
733                         if ! expr "$1" : "[0-9]" > /dev/null ; then
734                                 echo "Specify weightm value!" 1>&2
735                                 exit
736                         fi
737                 elif [ "$1" = "--rnaalifold" ]; then
738                         rnaalifold=1
739                 elif [ "$1" = "--mccaskill" ]; then
740                         mccaskill=1
741                         contrafold=0
742                         dafs=0
743                 elif [ "$1" = "--contrafold" ]; then
744                         mccaskill=0
745                         contrafold=1
746                         dafs=0
747                 elif [ "$1" = "--dafs" ]; then
748                         mccaskill=0
749                         contrafold=0
750                         dafs=1
751                 elif [ "$1" = "--ribosum" ]; then
752                         rnascoremtx=" -s "
753                 elif [ "$1" = "--op" ]; then 
754                         shift   
755                         gop="$1"
756                         if ! expr "$1" : "[0-9]" > /dev/null ; then
757                                 echo "Specify op!" 1>&2
758                                 exit
759                         fi
760                 elif [ "$1" = "--opdist" ]; then 
761                         shift   
762                         gopdist="$1"
763                         if ! expr "$1" : "[0-9]" > /dev/null ; then
764                                 echo "Specify opdist!" 1>&2
765                                 exit
766                         fi
767                         opdistspecified=1
768                 elif [ "$1" = "--allowshift" ]; then 
769                         allowshift=1
770                 elif [ "$1" = "--shiftpenalty" ]; then 
771                         shift   
772                         spfactor="$1"
773                         if ! expr "$1" : "[0-9]" > /dev/null ; then
774                                 echo "Specify sf!" 1>&2
775                                 exit
776                         fi
777                         shiftpenaltyspecified=1
778                 elif [ "$1" = "--ep" ]; then 
779                         shift   
780 #                       aof="$1"
781                         tmpval="$1"
782                         aof=`awk "BEGIN{ print -1.0 * \"$tmpval\"}"`
783                         if ! expr "$aof" : "[0-9\-]" > /dev/null ; then
784                                 printf "\nSpecify a number for ep, like --ep 0.1\n" 1>&2
785                                 printf "'$1' cannot be interpreted as a number..\n\n" 1>&2
786                                 exit
787                         fi
788                 elif [ "$1" = "--rop" ]; then 
789                         shift   
790                         rgop="$1"
791 # Atode check
792                 elif [ "$1" = "--rep" ]; then 
793                         shift   
794                         rgep="$1"
795                 elif [ "$1" = "--lop" ]; then 
796                         shift   
797                         lgop="$1"
798                 elif [ "$1" = "--LOP" ]; then 
799                         shift   
800                         LGOP="$1"
801                 elif [ "$1" = "--lep" ]; then 
802                         shift   
803                         laof="$1"
804                 elif [ "$1" = "--lexp" ]; then 
805                         shift   
806                         lexp="$1"
807                 elif [ "$1" = "--LEXP" ]; then 
808                         shift   
809                         LEXP="$1"
810                 elif [ "$1" = "--GEXP" ]; then 
811                         shift   
812                         GEXP="$1"
813                 elif [ "$1" = "--GOP" ]; then 
814                         shift   
815                         GGOP="$1"
816                 elif [ "$1" = "--gop" ]; then 
817                         shift   
818                         pggop="$1"
819                 elif [ "$1" = "--gep" ]; then 
820                         shift   
821                         pgaof="$1"
822                 elif [ "$1" = "--gexp" ]; then 
823                         shift   
824                         pgexp="$1"
825                 elif [ "$1" = "--laraparams" ]; then 
826                         shift   
827                         laraparams="$1"
828                 elif [ "$1" = "--corethr" ]; then 
829                         shift   
830                         corethr="$1"
831                 elif [ "$1" = "--corewin" ]; then 
832                         shift   
833                         corewin="$1"
834                 elif [ "$1" = "--strdir" ]; then
835                         shift
836                         strdir="$1"
837                 elif [ "$1" = "--pdbidlist" ]; then
838                         shift
839                         pdblist="$1"
840                         if [ ! -e "$pdblist" ]; then
841                                 echo "Cannot open $pdblist" 1>&2
842                                 echo "" 1>&2
843                                 exit
844                         fi
845                 elif [ "$1" = "--pdbfilelist" ]; then
846                         shift
847                         ownlist="$1"
848                         if [ ! -e "$ownlist" ]; then
849                                 echo "Cannot open $ownlist" 1>&2
850                                 echo "" 1>&2
851                                 exit
852                         fi
853                 elif [ "$1" = "--enrich" ]; then
854                         enrich=1
855                         enrichseq=1
856                         enrichstr=1
857                         seektarget=""
858                 elif [ "$1" = "--enrichseq" ]; then
859                         enrich=1
860                         enrichseq=1
861                         enrichstr=0
862                         seektarget="-seq"
863                 elif [ "$1" = "--enrichstr" ]; then
864                         enrich=1
865                         enrichseq=0
866                         enrichstr=1
867                         seektarget="-str"
868                 elif [ "$1" = "--seedtable" ]; then
869                         shift
870                         seedtable="y"
871                         seedtablefile="$1"
872                 elif [ "$1" = "--seed" ]; then
873                         shift
874                         seed="m"
875                         seedfiles="$seedfiles $1"
876                 elif [ "$1" = "--minimumweight" ]; then
877                         shift
878                         minimumweight="$1"
879                 elif [ "$1" = "--similaritylevel" ]; then
880                         shift
881                         similarityoffset="$1"
882                 elif [ "$1" = "--unalignlevel" ]; then
883                         shift
884                         unalignlevel="$1"
885                         unalignspecified=1
886                 elif [ "$1" = "--skipiterate" ]; then
887                         shift
888                         fixthreshold="$1"
889                 elif [ "$1" = "--bunkatsunashi" ]; then
890                         bunkatsuopt=" -B "
891                 elif [ "$1" = "--sp" ]; then
892                         sprigorous=1
893                 elif [ "$1" = "--focus" ]; then
894                         focusarg=" -= "
895                 elif [ "$1" = "--sparsepickup" ]; then
896                         shift
897                         npickup="$1"
898                 elif [ $progname = "fftns" -o  $progname = "nwns" ]; then
899                         if [ "$1" -gt 0 ]; then
900                                 cycle=`expr "$1" - 0`
901                         fi
902                 else
903                         echo "Unknown option:  $1" 1>&2
904                         er=1;
905 #                       exit 1;
906                 fi
907                 shift   
908         done;
909
910
911         echo "" 1>"$progressfile"
912
913 #       TMPFILE=/tmp/$progname.$$
914         TMPFILE=`mktemp -dt $progname.XXXXXXXXXX`
915         if [ $? -ne 0 ]; then
916                 echo "mktemp seems to be obsolete. Re-trying without -t" 1>&2
917                 TMPFILE=`mktemp -d /tmp/$progname.XXXXXXXXXX`
918         fi      
919
920 #       if [ $os = "cygwin" ]; then
921 #               TMPFILE=`cygpath -w $TMPFILE` unnecessary for cygwin2.7
922 #       fi
923
924         umask 077
925 #       mkdir  $TMPFILE  || er=1
926         if [ $debug -eq 1 ]; then
927 #               trap "tar cfvz debuginfo.tgz $TMPFILE; rm -rf $TMPFILE " 0 # does not work in msys
928                 trap "tar cfv - $TMPFILE | gzip -c > debuginfo.tgz; rm -rf $TMPFILE " 0
929         else
930                 trap "rm -rf $TMPFILE" 0
931         fi
932         if [ $# -eq 1 ]; then
933                 if [ -r "$1" -o "$1" = - ]; then
934
935                         if [ -r "$addfile" ]; then
936                                 printf '';
937                         else
938                                 echo "$0": Cannot open "$addfile". 1>&2
939                                 echo "" 1>&2
940                                 exit 1;
941                         fi
942
943                         cat "$1"              | tr "\r" "\n" > $TMPFILE/infile 
944                         echo ""                             >> $TMPFILE/infile
945                         cat "$addfile"        | tr "\r" "\n" | grep -v "^$" >> $TMPFILE/infile
946                         cat "$addfile"        | tr "\r" "\n" | grep -v "^$" > $TMPFILE/_addfile
947                         cat "$aamatrix"       | tr "\r" "\n" | grep -v "^$" > $TMPFILE/_aamtx
948                         cat "$mergetable"     | tr "\r" "\n" | grep -v "^$" > $TMPFILE/_subalignmentstable
949                         cat "$treeinfile"     | tr "\r" "\n" | grep -v "^$" > $TMPFILE/_guidetree
950                         cat "$seedtablefile"  | tr "\r" "\n" | grep -v "^$" > $TMPFILE/_seedtablefile
951                         cat "$laraparams"     | tr "\r" "\n" | grep -v "^$" > $TMPFILE/_lara.params
952                         cat "$pdblist"        | tr "\r" "\n" | grep -v "^$" > $TMPFILE/pdblist
953                         cat "$ownlist"        | tr "\r" "\n" | grep -v "^$" > $TMPFILE/ownlist
954
955 #                       echo $seedfiles
956                         infilename="$1"
957                         seedfilesintmp="/dev/null"
958                         seednseq="0"
959                         set $seedfiles > /dev/null
960                         while [ $# -gt 1 ];
961                         do
962                                 shift
963                                 if [ -r "$1" ]; then
964                                         cat "$1" | tr "\r" "\n" >  $TMPFILE/seed$#
965                                 else
966                                         echo "$0": Cannot open "$1". 1>&2
967                                         echo "" 1>&2
968                                         exit 1;
969                                 fi
970                                 seednseq=$seednseq" "`grep -c '^[>|=]' $TMPFILE/seed$#`
971                                 seedfilesintmp=$seedfilesintmp" "seed$#
972                         done
973 #                       ls $TMPFILE
974 #                       echo $seedfilesintmp
975 #                       echo $seednseq
976
977
978                 else
979                         echo "$0": Cannot open "$1". 1>&2
980                         echo "" 1>&2
981                         er=1
982 #                       exit 1;
983                 fi
984         else
985 #               echo '$#'"=$#" 1>&2
986                 er=1
987         fi
988
989
990
991         if [ $numthreads -lt 0 ]; then
992                 if [ $os = "linux" ]; then
993                         nlogicalcore=`cat /proc/cpuinfo | grep "^processor" | uniq | wc -l`
994                         ncoresinacpu=`cat /proc/cpuinfo | grep 'cpu cores' | uniq | awk '{print $4}'`
995                         nphysicalcpu=`cat /proc/cpuinfo | grep 'physical id' | sort | uniq | wc -l`
996                         if [ $nlogicalcore -eq 0 ]; then
997                                 echo "Cannot get the number of processors from /proc/cpuinfo" 1>>"$progressfile"
998                                 exit 1
999                         fi
1000                         if [ ${#ncoresinacpu} -gt 0 -a $nphysicalcpu -gt 0 ]; then
1001                                 numthreads=`expr $ncoresinacpu '*' $nphysicalcpu`
1002 #                               if [ $nlogicalcore -gt $numthreads ]; then    # Hyperthreading
1003 #                                       numthreads=`expr $numthreads '+' 1`
1004 #                               fi
1005                         else
1006                                 numthreads=$nlogicalcore
1007                         fi
1008                 elif [ $os = "darwin" ]; then
1009                         numthreads=`sysctl -n hw.physicalcpu`
1010                         if [ -z $numthreads ]; then
1011                                 echo "Cannot get the number of physical cores from sysctl" 1>>"$progressfile"
1012                                 exit 1
1013                         fi
1014 #                       nlogicalcore=`sysctl -n hw.logicalcpu`
1015 #                       if [ $nlogicalcore -gt $numthreads ]; then    # Hyperthreading
1016 #                               numthreads=`expr $numthreads '+' 1`
1017 #                       fi
1018                 elif [ $os = "mingw" -o $os = "cygwin" ]; then
1019                         numthreads=`wmic cpu get NumberOfCores | head -2 | tail -1 | awk '{print $1}'`
1020                 else
1021                         echo "Cannot count the number of physical cores." 1>>"$progressfile"
1022                         exit 1
1023                 fi
1024                 echo "OS = "$os 1>>"$progressfile"
1025                 echo "The number of physical cores = " $numthreads 1>>"$progressfile"
1026         fi
1027
1028         if [ $numthreadstb -lt 0 ]; then
1029                 numthreadstb=$numthreads
1030         fi
1031
1032         if [ $numthreadsit -lt 0 ]; then
1033                 if [ $numthreads -lt 11 ]; then
1034                         numthreadsit=$numthreads
1035                 else
1036                         numthreadsit=10
1037                 fi
1038         fi
1039
1040         if [ $numthreadsit -eq 0 -a $parallelizationstrategy = "BESTFIRST" ]; then
1041                 echo 'Impossible' 1>&2;
1042                 exit 1;
1043         fi
1044
1045         if [ "$addarg0" != " " ]; then
1046                 iterate=0  # 2013/03/23
1047                 "$prefix/countlen" < $TMPFILE/_addfile > $TMPFILE/addsize 2>>"$progressfile"
1048                 nadd=`awk '{print $1}' $TMPFILE/addsize`
1049                 if [ $nadd -eq "0" ]; then
1050                         echo Check $addfile 1>&2
1051                         exit 1;
1052                 fi
1053                 if [ $seed != "x" -o $seedtable != "x" ]; then
1054                         echo 'Impossible' 1>&2;
1055                         echo 'Use either ONE of --seed, --seedtable, --addprofile and --add.' 1>&2
1056                         exit 1;
1057                 fi
1058         else
1059                 nadd="0"
1060         fi
1061
1062         if [ $auto -eq 1 ]; then
1063                 "$prefix/countlen" < $TMPFILE/infile > $TMPFILE/size 2>>"$progressfile"
1064                 nseq=`awk '{print $1}' $TMPFILE/size`
1065                 nlen=`awk '{print $3}' $TMPFILE/size`
1066
1067                 if [ $nlen -lt 3000 -a $nseq -lt 100 ]; then
1068                         distance="local"
1069                         iterate=1000
1070                         cycle=1
1071                 elif [ $nlen -lt 1000 -a $nseq -lt 200 ]; then
1072                         distance="local"
1073                         iterate=2
1074                         cycle=1
1075                 elif [ $nlen -lt 10000 -a $nseq -lt 500 ]; then
1076                         distance="ktuples"
1077                         iterate=2
1078                         cycle=2
1079                 elif [ $nseq -lt 50000 ]; then  # changed from 10000 2014/Oct/4
1080                         distance="ktuples"
1081                         iterate=0
1082                         cycle=2
1083                 elif [ $nseq -lt 90000 ]; then  # changed from 30000 2014/Oct/4
1084                         distance="ktuples"
1085                         iterate=0
1086                         cycle=1
1087                 elif [ $nlen -lt 3000 ]; then
1088                         distance="parttree"
1089                         partdist="localalign"
1090                         algopt=" "
1091                         algoptit=" "
1092 #                       algspecified=1
1093                         cycle=1
1094                 else
1095                         distance="parttree"
1096                         partdist="ktuples"
1097                         algopt=" "
1098                         algoptit=" "
1099 #                       algspecified=1
1100                         cycle=1
1101                 fi
1102
1103
1104 #               if [ $nlen -lt 3000 -a $nseq -lt 100 ]; then
1105 #                       distance="local"
1106 #                       iterate=1000
1107 #                       cycle=1
1108 #               elif [ $nlen -lt 1000 -a $nseq -lt 200 ]; then
1109 #                       distance="local"
1110 #                       iterate=2
1111 #                       cycle=1
1112 #               elif [ $nlen -lt 10000 -a $nseq -lt 500 ]; then
1113 #                       distance="ktuples"
1114 #                       iterate=2
1115 #                       cycle=2
1116 #               elif [ $nseq -lt 200000 ]; then
1117 #                       distance="ktuples"
1118 #                       iterate=0
1119 #                       treeinopt=" -U "
1120 #                       treein=1
1121 #                       pileuporshuffle="a"
1122 #               elif [ $nlen -lt 3000 ]; then
1123 #                       distance="parttree"
1124 #                       partdist="localalign"
1125 #                       algopt=" "
1126 #                       algoptit=" "
1127 ##                      algspecified=1
1128 #                       cycle=1
1129 #               else
1130 #                       distance="parttree"
1131 #                       partdist="ktuples"
1132 #                       algopt=" "
1133 #                       algoptit=" "
1134 ##                      algspecified=1
1135 #                       cycle=1
1136 #               fi
1137
1138
1139                 if [ $fragment -ne 0 ]; then
1140                         norg=`expr $nseq '-' $nadd`
1141                         npair=`expr $norg '*' $nadd`
1142                         echo "nadd = " $nadd               1>>"$progressfile"
1143                         echo "npair = " $npair             1>>"$progressfile"
1144                         echo "nseq = " $nseq               1>>"$progressfile"
1145                         echo "nlen = " $nlen               1>>"$progressfile"
1146 # nagasa check!
1147 #
1148                         if [ $npair -gt 10000000 -o $nlen -gt 500000 ]; then  # 2015/Jun
1149                                 distance="ktuples"
1150                                 echo "use ktuples, size=$tuplesize!" 1>>"$progressfile"
1151                         elif [ $npair -gt 3000000 -o $nlen -gt 100000 ]; then  # 2015/Jun
1152                                 distance="multi"
1153                                 weighti="0.0"
1154                                 echo "use multipair, weighti=0.0!" 1>>"$progressfile"
1155                         else
1156                                 distance="multi"
1157                                 echo "use multipair, weighti=$weighti!" 1>>"$progressfile"
1158                         fi
1159                         pairspecified=1
1160                 fi
1161         fi
1162
1163         if [ `awk "BEGIN {print( 0.0+\"$sueff\" < 0.0 || 0.0+\"$sueff\" > 1.0 )}"` -gt 0 ]; then
1164                 printf "\n%s\n\n" "The argument of --mixedlinkage must be between 0.0 and 1.0" 1>>"$progressfile"
1165                 exit 1;
1166         fi
1167
1168         if [ $allowshift -eq 1 ]; then
1169                 if [ $unalignspecified -ne 1 ]; then
1170                         unalignlevel="0.8"
1171                 fi
1172                 if [ $shiftpenaltyspecified -ne 1 ]; then
1173                         spfactor="2.00"
1174                 fi
1175         fi
1176
1177         if [ $opdistspecified -ne 1 ]; then
1178                 gopdist=$gop
1179         fi
1180
1181         if [ $unalignlevel != "0.0" -o `awk "BEGIN {print( 0.0+\"$spfactor\" < 100.0 )}"` -gt 0 ]; then
1182                 nmodel=" -: "
1183                 termgapopt=" "
1184                 if [ $distance = "localgenaf" ]; then
1185                         printf "\n%s\n" "The combination of --allowshift and --genafpair (E-INS-i/-1) is not supported." 1>>"$progressfile"
1186                         printf "%s\n" "Instead, please try --allowshift --globalpair (G-INS-i/-1 in the web version)," 1>>"$progressfile"
1187                         printf "%s\n\n" "which covers the situation for --genafpair (E-INS-i/-1), too." 1>>"$progressfile"
1188                         exit 1;
1189                 fi
1190                 if [ $distance != "global" -o `awk "BEGIN {print( 0.0+\"$weighti\" < 1.0 )}"` -gt 0 ]; then
1191                         printf "\n%s\n\n" "At present, --unalignlevel # or --allowshift is supported only with the --globalpair option." 1>>"$progressfile"
1192                         exit 1;
1193                 fi
1194                 if [ $fragment -ne 0 ]; then
1195                         printf "\n%s\n\n" "At present, --unalignlevel # or --allowshift is not supported with the --addfragments option." 1>>"$progressfile"
1196                         exit 1;
1197                 fi
1198         fi
1199
1200         if [ `awk "BEGIN {print( 0.0+\"$spfactor\" < 1.0 )}"` -gt 0 ]; then
1201                         printf "\n%s\n" "shiftpenalty must be >1." 1>>"$progressfile"
1202                         exit 1;
1203         fi
1204
1205         if [ `awk "BEGIN {print( 0.0+\"$fixthreshold\" < 0.0 )}"` -gt 0 ]; then
1206                 printf "\n%s\n\n" "The 'fix' parameter must be >= 0.0" 1>>"$progressfile"
1207                 exit 1;
1208         fi
1209
1210         if [ `awk "BEGIN {print( 0.0+\"$unalignlevel\" < 0.0 || 0.0+\"$unalignlevel\" > 1.0 )}"` -gt 0 ]; then
1211                 printf "\n%s\n\n" "The 'unalignlevel' parameter must be between 0.0 and 1.0" 1>>"$progressfile"
1212                 exit 1;
1213         fi
1214         if [ `awk "BEGIN {print( 0.0+\"$unalignlevel\" > 0.0 )}"` -gt 0 ]; then
1215                 laof="0"
1216                 lexp="0"
1217                 pgaof="0"
1218                 pgexp="0"
1219                 LEXP="0"
1220                 GEXP="0"
1221                 termgapopt=" "
1222 #               if [ $auto -eq 1 -o $fragment -ne 0 -o $iterate -gt 0 ]; then
1223                 if [ $fragment -ne 0 ]; then
1224                         printf "\n%s\n\n" "At present, the 'unalignlevel > 0' mode is not supported with the --addfragments option." 1>>"$progressfile"
1225                         exit 1;
1226                 fi
1227                 if [ $distance = "parttree" ]; then
1228                         printf "\n%s\n\n" "At present, the 'unalignlevel > 0' mode is not supported in the (dp)parttree option." 1>>"$progressfile"
1229                         exit 1;
1230                 fi
1231                 if [ $distance = "localgenaf" ]; then
1232                         printf "\n%s\n" "The --genafpair is not supported in the 'unalignlevel > 0' mode." 1>>"$progressfile"
1233                         printf "%s\n" "Instead, please try --unalignlevel xx --globalpair," 1>>"$progressfile"
1234                         printf "%s\n\n" "which covers the situation for --genafpair (E-INS-i), too." 1>>"$progressfile"
1235                         exit 1;
1236                 fi
1237 #               if [ $distance != "ktuples" -a `awk "BEGIN {print( 0.0+\"$weighti\" > 0.0 )}"` -gt 0 -a $iterate -gt 0 ]; then
1238 #                       printf "\n%s\n\n" "Please add --weighti 0.0, for now." 1>>"$progressfile"
1239 #                       exit 1;
1240 #               fi
1241         fi
1242
1243         if [ `awk "BEGIN {print( 0.0+\"$similarityoffset\" != 0.0 && 0.0+\"$unalignlevel\" != 0.0 )}"` -gt 0 ]; then
1244                 printf "\n%s\n\n" "Do not simultaneously specify --similaritylevel and --unalignlevel" 1>>"$progressfile"
1245                 exit 1;
1246         fi
1247
1248         if [ `awk "BEGIN {print( 0.0+\"$similarityoffset\" < -1.0 || 0.0+\"$similarityoffset\" > 1.0 )}"` -gt 0 ]; then
1249                 printf "\n%s\n\n" "Similarity must be between -1.0 and +1.0" 1>>"$progressfile"
1250                 exit 1;
1251         fi
1252         aof=`awk "BEGIN{print 0.0 + \"$similarityoffset\" + $aof}"`
1253         laof=`awk "BEGIN{print 0.0 + \"$similarityoffset\" + $laof}"`
1254         pgaof=`awk "BEGIN{print 0.0 + \"$similarityoffset\" + $pgaof}"`
1255
1256
1257         if [ $parallelizationstrategy = "BESTFIRST" -o  $parallelizationstrategy = "BAATARI0" ]; then
1258                 iteratelimit=254
1259         else
1260                 iteratelimit=16
1261         fi
1262         if [ $iterate -gt $iteratelimit ]; then    #??
1263                 iterate=$iteratelimit
1264         fi
1265
1266         if [ $rnaalifold -eq 1 ]; then
1267                 rnaopt=" -e $rgep -o $rgop -c $weightm -r $weightr -R $rnascoremtx "
1268 #               rnaoptit=" -o $rgop -BT -c $weightm -r $weightr -R "
1269                 rnaoptit=" -o $rgop -F -c $weightm -r $weightr -R "
1270         elif [ $mccaskill -eq 1 -o $dafs -eq 1 -o $contrafold -eq 1 ]; then
1271                 rnaopt=" -o $rgop -c $weightm -r $weightr "
1272 #               rnaoptit=" -e $rgep -o $rgop -BT -c $weightm -r $weightr $rnascoremtx "
1273                 rnaoptit=" -e $rgep -o $rgop -F -c $weightm -r $weightr $rnascoremtx "
1274         else
1275                 rnaopt="  "
1276                 rnaoptit=" -F "
1277         fi
1278
1279 #       if [ $algspecified -eq 0 ]; then
1280 #               if [ $distance = "parttree" ]; then 
1281 #                       algopt=" -Q "
1282 #                       algoptit=" "
1283 #               else
1284 #                       algopt=" "
1285 #                       algoptit=" "
1286 #               fi
1287 #       fi
1288
1289         if [ $sprigorous -eq 1 ]; then
1290                 algopt=" -@ "
1291                 if [ $iterate -gt 0 ]; then
1292                         if [ $numthreadsit -eq 0 ]; then
1293                                 algoptit=" -@ -B -Z -z 1000 "
1294                         else
1295                                 echo "" 1>>"$progressfile"
1296                                 echo "At present, the combination of --sp and iterative refinement is supported only in a single thread." 1>>"$progressfile"
1297                                 echo "Please try \"--thread -1 --threadit 0\", which runs the iterative refinment calculation on a single thread." 1>>"$progressfile"
1298                                 echo "" 1>>"$progressfile"
1299                                 exit 1;
1300 #                               algoptit=" -@ -B -z 1000 "
1301                         fi
1302                 fi
1303                 termgapopt=" "
1304                 fft=0
1305                 memopt=" -N "
1306         fi
1307
1308         model="$sbstmodel $kappa $fmodel $nmodel"
1309
1310         if [ $er -eq 1 ]; then
1311                 echo "------------------------------------------------------------------------------" 1>&2
1312                 echo "  MAFFT" $version 1>&2
1313 #               echo "" 1>&2
1314 #               echo "  Input format: fasta" 1>&2
1315 #               echo ""  1>&2
1316 #               echo "  Usage: `basename $0` [options] inputfile > outputfile" 1>&2
1317             echo "  http://mafft.cbrc.jp/alignment/software/" 1>&2
1318                 echo "  MBE 30:772-780 (2013), NAR 30:3059-3066 (2002)"        1>&2
1319 #               echo "------------------------------------------------------------------------------" 1>&2
1320 #               echo "  % mafft in > out" 1>&2
1321                 echo "------------------------------------------------------------------------------" 1>&2
1322 #               echo ""  1>&2
1323                 echo "High speed:" 1>&2
1324                 echo "  % mafft in > out" 1>&2
1325                 echo "  % mafft --retree 1 in > out (fast)" 1>&2
1326                 echo "" 1>&2
1327                 echo "High accuracy (for <~200 sequences x <~2,000 aa/nt):" 1>&2
1328                 echo "  % mafft --maxiterate 1000 --localpair  in > out (% linsi in > out is also ok)" 1>&2
1329                 echo "  % mafft --maxiterate 1000 --genafpair  in > out (% einsi in > out)" 1>&2
1330                 echo "  % mafft --maxiterate 1000 --globalpair in > out (% ginsi in > out)" 1>&2
1331                 echo "" 1>&2
1332                 echo "If unsure which option to use:" 1>&2
1333                 echo "  % mafft --auto in > out" 1>&2
1334                 echo "" 1>&2
1335 #               echo "Other options:" 1>&2
1336                 echo "--op # :         Gap opening penalty, default: 1.53" 1>&2
1337                 echo "--ep # :         Offset (works like gap extension penalty), default: 0.0" 1>&2
1338                 echo "--maxiterate # : Maximum number of iterative refinement, default: 0" 1>&2
1339                 echo "--clustalout :   Output: clustal format, default: fasta" 1>&2
1340                 echo "--reorder :      Outorder: aligned, default: input order" 1>&2
1341                 echo "--quiet :        Do not report progress" 1>&2
1342                 echo "--thread # :     Number of threads (if unsure, --thread -1)" 1>&2
1343 #               echo "" 1>&2
1344 #               echo " % mafft --maxiterate 1000 --localpair in > out (L-INS-i)" 1>&2
1345 #               echo " most accurate in many cases, assumes only one alignable domain" 1>&2 
1346 #               echo "" 1>&2
1347 #               echo " % mafft --maxiterate 1000 --genafpair in > out (E-INS-i)" 1>&2
1348 #               echo " works well if many unalignable residues exist between alignable domains" 1>&2
1349 #               echo "" 1>&2
1350 #               echo " % mafft --maxiterate 1000 --globalpair in > out (G-INS-i)" 1>&2
1351 #               echo " suitable for globally alignable sequences            " 1>&2
1352 #               echo "" 1>&2
1353 #               echo " % mafft --maxiterate 1000 in > out (FFT-NS-i)" 1>&2
1354 #               echo " accurate and slow, iterative refinement method      " 1>&2
1355 #               echo "" 1>&2
1356 #               echo "If the input sequences are long (~1,000,000nt)," 1>&2
1357 #               echo " % mafft --retree 1 --memsave --fft in > out (FFT-NS-1-memsave, new in v5.8)" 1>&2
1358 #               echo "" 1>&2
1359 #               echo "If many (~5,000) sequences are to be aligned," 1>&2
1360 #               echo "" 1>&2
1361 #               echo " % mafft --retree 1 [--memsave] --nofft in > out (NW-NS-1, new in v5.8)" 1>&2
1362 #               echo "" 1>&2
1363 #               echo " --localpair :      All pairwise local alignment information is included"  1>&2
1364 #               echo "                    to the objective function, default: off"  1>&2
1365 #               echo " --globalpair :     All pairwise global alignment information is included"  1>&2
1366 #               echo "                    to the objective function, default: off"  1>&2
1367 #               echo " --op # :           Gap opening penalty, default: $defaultgop " 1>&2
1368 #               echo " --ep # :           Offset (works like gap extension penalty), default: $defaultaof " 1>&2
1369 #               echo " --bl #, --jtt # :  Scoring matrix, default: BLOSUM62" 1>&2
1370 #               echo "                    Alternatives are BLOSUM (--bl) 30, 45, 62, 80, " 1>&2
1371 #               echo "                    or JTT (--jtt) # PAM. " 1>&2
1372 #               echo " --nuc or --amino : Sequence type, default: auto" 1>&2
1373 #               echo " --retree # :       The number of tree building in progressive method " 1>&2
1374 #               echo "                    (see the paper for detail), default: $defaultcycle " 1>&2
1375 #               echo " --maxiterate # :   Maximum number of iterative refinement, default: $defaultiterate " 1>&2
1376 #               if [ $defaultfft -eq 1 ]; then
1377 #                       echo " --fft or --nofft:  FFT is enabled or disabled, default: enabled" 1>&2
1378 #               else
1379 #                       echo " --fft or --nofft:  FFT is enabled or disabled, default: disabled" 1>&2
1380 #               fi
1381 #               echo " --memsave:         Memory saving mode" 1>&2
1382 #               echo "                    (for long genomic sequences), default: off" 1>&2
1383 #               echo " --clustalout :     Output: clustal format, default: fasta" 1>&2
1384 #               echo " --reorder :        Outorder: aligned, default: input order" 1>&2
1385 #               echo " --quiet :          Do not report progress" 1>&2
1386 #               echo "-----------------------------------------------------------------------------" 1>&2
1387                 exit 1; 
1388         fi
1389         if [ $sw -eq 1 ]; then
1390                 swopt=" -A "
1391         else
1392                 swopt=" "
1393         fi
1394
1395         if [ $distance = "fasta" -o $partdist = "fasta" ]; then
1396                 if [ ! "$FASTA_4_MAFFT" ]; then
1397                         FASTA_4_MAFFT=`which fasta34`
1398                 fi
1399
1400                 if [ ! -x "$FASTA_4_MAFFT" ]; then
1401                         echo ""       1>&2
1402                         echo "== Install FASTA ========================================================" 1>&2
1403                         echo "This option requires the fasta34 program (FASTA version x.xx or higher)"   1>&2
1404                         echo "installed in your PATH.  If you have the fasta34 program but have renamed" 1>&2
1405                         echo "(like /usr/local/bin/myfasta), set the FASTA_4_MAFFT environment variable" 1>&2
1406                         echo "to point your fasta34 (like setenv FASTA_4_MAFFT /usr/local/bin/myfasta)." 1>&2
1407                         echo "=========================================================================" 1>&2
1408                         echo "" 1>&2
1409                         exit 1
1410                 fi
1411         fi
1412         if [ $distance = "last" -o $distance = "lastmulti" ]; then
1413                 if [ ! -x "$prefix/lastal" -o ! -x "$prefix/lastdb" ]; then
1414                         echo ""       1>&2
1415                         echo "== Install LAST ============================================================" 1>&2
1416                         echo "LAST (Kielbasa, Wan, Sato, Horton, Frith 2011 Genome Res. 21:487) is required." 1>&2
1417                         echo "http://last.cbrc.jp/"                                                       1>&2
1418                         echo "http://mafft.cbrc.jp/alignment/software/xxxxxxx.html "                      1>&2
1419                         echo "============================================================================" 1>&2
1420                         echo "" 1>&2
1421                         exit 1
1422                 fi
1423         fi
1424         if [ $distance = "lara" -o $distance = "slara" ]; then
1425                 if [ ! -x "$prefix/mafft_lara" ]; then
1426                         echo ""       1>&2
1427                         echo "== Install LaRA =========================================================" 1>&2
1428                         echo "This option requires LaRA (Bauer et al. http://www.planet-lisa.net/)."     1>&2
1429                         echo "The executable have to be renamed to 'mafft_lara' and installed into "     1>&2
1430                         echo "the $prefix directory. "                                                   1>&2
1431                         echo "A configuration file of LaRA also have to be given"                        1>&2
1432                         echo "mafft-xinsi --larapair --laraparams parameter_file"                        1>&2
1433                         echo "mafft-xinsi --slarapair --laraparams parameter_file"                       1>&2
1434                         echo "=========================================================================" 1>&2
1435                         echo "" 1>&2
1436                         exit 1
1437                 fi
1438                 if [ ! -s "$laraparams" ]; then
1439                         echo ""       1>&2
1440                         echo "== Configure LaRA =======================================================" 1>&2
1441                         echo "A configuration file of LaRA have to be given"                             1>&2
1442                         echo "mafft-xinsi --larapair --laraparams parameter_file"                        1>&2
1443                         echo "mafft-xinsi --slarapair --laraparams parameter_file"                       1>&2
1444                         echo "=========================================================================" 1>&2
1445                         echo "" 1>&2
1446                         exit 1
1447                 fi
1448         fi
1449         if [ $distance = "foldalignlocal" -o $distance = "foldalignglobal" ]; then
1450         if [ ! -x "$prefix/foldalign210" ]; then
1451                         echo ""       1>&2
1452                         echo "== Install FOLDALIGN ====================================================" 1>&2
1453                         echo "This option requires FOLDALIGN (Havgaard et al. http://foldalign.ku.dk/)." 1>&2
1454                         echo "The executable have to be renamed to 'foldalign210' and installed into "   1>&2
1455                         echo "the $prefix directory. "                                                   1>&2
1456                         echo "=========================================================================" 1>&2
1457                         echo "" 1>&2
1458                         exit 1
1459                 fi
1460         fi
1461         if [ $distance = "scarna" -o $mccaskill -eq 1 ]; then
1462                 if [ ! -x "$prefix/mxscarnamod" ]; then
1463                         echo ""       1>&2
1464                         echo "== Install MXSCARNA ======================================================" 1>&2
1465                         echo "MXSCARNA (Tabei et al. BMC Bioinformatics 2008 9:33) is required."          1>&2
1466                         echo "Please 'make' at the 'extensions' directory of the MAFFT source package,"   1>&2
1467                         echo "which contains the modified version of MXSCARNA."                           1>&2
1468                         echo "http://mafft.cbrc.jp/alignment/software/source.html "                1>&2
1469                         echo "==========================================================================" 1>&2
1470                         echo "" 1>&2
1471                         exit 1
1472                 fi
1473         fi
1474         if [ $distance = "dafs" -o $dafs -eq 1 ]; then
1475                 if [ ! -x "$prefix/dafs" ]; then
1476                         echo ""       1>&2
1477                         echo "== Install DAFS===========================================================" 1>&2
1478                         echo "DAFS (Sato et al. Journal 2012 issue:page) is required."                    1>&2
1479                         echo "http://www.ncrna.org/ "                                                     1>&2
1480                         echo "==========================================================================" 1>&2
1481                         echo "" 1>&2
1482                         exit 1
1483                 fi
1484         fi
1485         if [ $contrafold -eq 1 ]; then
1486                 if [ ! -x "$prefix/contrafold" ]; then
1487                         echo ""       1>&2
1488                         echo "== Install CONTRAfold ===================================================" 1>&2
1489                         echo "This option requires CONTRAfold"                                           1>&2
1490                         echo "(Do et al. http://contra.stanford.edu/contrafold/)."                       1>&2
1491                         echo "The executable 'contrafold' have to be installed into "                    1>&2
1492                         echo "the $prefix directory. "                                                   1>&2
1493                         echo "=========================================================================" 1>&2
1494                         echo "" 1>&2
1495                         exit 1
1496                 fi
1497         fi
1498
1499 #old
1500 #       if [ $treeout -eq 1 ]; then
1501 #               parttreeoutopt="-t"
1502 #               if [ $cycle -eq 0 ]; then
1503 #                       treeoutopt="-t -T"
1504 #                       groupsize=1
1505 #                       iterate=0 
1506 #                       if [ $distance = "global" -o $distance = "local" -o $distance = "localgenaf" -o $distance = "globalgenaf" ]; then
1507 #                               distance="distonly"
1508 #                       fi
1509 #               else
1510 #                       treeoutopt="-t"
1511 #               fi
1512 #       else
1513 #               parttreeoutopt=" "
1514 #               if [ $cycle -eq 0 ]; then
1515 #                       treeoutopt="-t -T"
1516 #                       iterate=0 
1517 #                       if [ $distance = "global" -o $distance = "local" -o $distance = "localgenaf" -o $distance = "globalgenaf" ]; then
1518 #                               distance="distonly"
1519 #                       fi
1520 #               else
1521 #                       treeoutopt=" "
1522 #               fi
1523 #       fi
1524
1525 #new
1526         if [ $cycle -eq 0 ]; then
1527                 treeoutopt="-t -T"
1528                 iterate=0 
1529                 weighti="0.0"  # 2016Jul31, tbfast.c kara idou
1530 #               if [ $distance = "global" -o $distance = "local" -o $distance = "localgenaf" -o $distance = "globalgenaf" ]; then # 2012/04, localpair --> local alignment distance
1531 #               if [ $distance = "global" ]; then
1532 #                       distance="distonly"
1533 #               fi
1534                 if [ $treeout -eq 1 ]; then
1535                         parttreeoutopt="-t"
1536                         groupsize=1
1537                 else
1538                         parttreeoutopt=" "
1539                 fi
1540                 if [ $distout -eq 1 ]; then
1541                         distoutopt="-y -T"
1542                         if [ $treeout -eq 0 ]; then
1543                                 treeoutopt=""
1544                         fi
1545                 fi
1546         else
1547                 if [ $treeout -eq 1 ]; then
1548                         parttreeoutopt="-t"
1549                         treeoutopt="-t"
1550                 else
1551                         parttreeoutopt=" "
1552                         treeoutopt=" "
1553                 fi
1554                 if [ $distout -eq 1 ]; then
1555                         distoutopt="-y"
1556                 fi
1557         fi
1558 #
1559
1560         formatcheck=`grep -c '^[[:blank:]]\+>' $TMPFILE/infile | head -1 `
1561         if [ $formatcheck -gt 0 ]; then
1562                 echo "The first character of a description line must be " 1>&2
1563                 echo "the greater-than (>) symbol, not a blank."           1>&2
1564                 echo "Please check the format around the following line(s):"  1>&2
1565                 grep -n '^[[:blank:]]\+>' $TMPFILE/infile  1>&2
1566                 exit 1
1567         fi
1568
1569         nseq=`grep -c '^[>|=]' $TMPFILE/infile | head -1 ` 
1570         if [ $nseq -eq 2 ]; then
1571                 cycle=1
1572         fi
1573         if [ $cycle -gt 3 ]; then
1574                 cycle=3
1575         fi
1576
1577         if [ $nseq -gt 60000 -a $iterate -gt 1 ]; then   # 2014/Oct/22, test
1578                 echo "Too many sequences to perform iterative refinement!" 1>&2
1579                 echo "Please use a progressive method." 1>&2
1580                 exit 1
1581         fi
1582         if [ $distance = "lastmulti" -o $distance = "multi" ]; then
1583                 if [ $fragment -eq 0 ]; then
1584                         echo 'Specify --addfragments too' 1>&2
1585                         exit 1
1586                 fi
1587         fi
1588
1589         if [ $fragment -ne 0 ]; then
1590                 if [ $pairspecified -eq 0 ]; then
1591                         distance="multi"
1592                 fi
1593                 if [ $distance != "multi" -a $distance != "hybrid" -a $distance != "lastmulti" -a $distance != "local" -a $distance != "last" -a  $distance != "ktuples" -a $distance != "ktuplesmulti" ]; then
1594                         echo 'Specify --multipair, --lastmultipair, --lastpair, --localpair, --6merpair, --6mermultipair or --hybridpair' 1>&2
1595                         exit 1
1596                 fi
1597         fi
1598
1599         if [ "$memopt" = " -M -B " -a "$distance" != "ktuples" ]; then
1600                 echo "Impossible" 1>&2
1601                 exit 1
1602         fi
1603
1604         if [ $distance = "parttree" ]; then
1605                 if [ $mergetable != "/dev/null" ]; then
1606                         echo "The combination of (dp)parttree and merge is Impossible.  " 1>&2
1607                         exit 1
1608                 fi
1609                 if [ $addfile != "/dev/null" ]; then
1610                         echo "The combination of (dp)parttree and add(fragments) is Impossible.  " 1>&2
1611                         exit 1
1612                 fi
1613                 if [ $seed != "x" -o $seedtable != "x" ]; then
1614                         echo "Impossible" 1>&2
1615                         exit 1
1616                 fi
1617                 if [ $iterate -gt 1 ]; then
1618                         echo "Impossible" 1>&2
1619                         exit 1
1620                 fi
1621                 if [ $outorder = "aligned" ]; then
1622                         outorder="input"
1623                 fi
1624                 outorder="input"   # partorder ga kiku
1625                 if [ $partdist = "localalign" ]; then
1626                         splitopt=" -U "    # -U -l -> fast 
1627                         cycle=1
1628                 elif [ $partdist = "fasta" ]; then
1629                         splitopt=" -S "
1630                         cycle=1
1631                 else
1632                         splitopt="  "
1633                 fi
1634         fi
1635
1636
1637         if [ \( $distance = "ktuples" -o $distance = "ktuplesmulti" \) -a \( $seed = "x" -a $seedtable = "x" -a $ownlist = "/dev/null" -a $pdblist = "/dev/null" -a $enrichstr -eq 0 \) ]; then
1638                 localparam=""
1639                 weighti="0.0"
1640         elif [ \( $distance = "ktuples" -o $distance = "ktuplesmulti" \) -a \( $seed != "x" -o $seedtable != "x" -o $ownlist != "/dev/null" -o $pdblist != "/dev/null" -o $enrichstr -eq 1 \) ]; then
1641                 if [ $cycle -lt 2 ]; then
1642                         cycle=2                # disttbfast ha seed hi-taiou #  chuui 2014Aug21
1643                 fi
1644                 if [ $iterate -lt 2 ]; then
1645                         echo "############################################################################" 1>&2
1646                         echo "# Warning:" 1>&2
1647                         echo "#   Progressive alignment method is incompatible with the --seed option." 1>&2
1648                         echo "#   Automatically switched to the iterative refinement method." 1>&2
1649                         echo "#   " 1>&2
1650                         echo "# Also consider using the '--add' option, which is compatible with" 1>&2
1651                         echo "#   the progressive method and FASTER than the '--seed' option." 1>&2
1652                         echo "#   Usage is:" 1>&2
1653                         echo "#   % mafft --add newSequences existingAlignment > output" 1>&2
1654                         echo "############################################################################" 1>&2
1655                         iterate=2
1656                 fi
1657                 localparam="-l "$weighti
1658         elif [ $distance = "parttree" ]; then
1659                 localparam=""
1660                 weighti="0.0"
1661                 if [ $groupsize -gt -1 ]; then
1662                         cycle=1
1663                 fi
1664         else
1665                 localparam="-B -l "$weighti   # weighti=0 demo bunkatsu nashi
1666                 if [ $cycle -gt 1 ]; then  # 09/01/08
1667                         cycle=1
1668                 fi
1669         fi
1670
1671
1672         if [ $distance = "localgenaf" -o $distance = "globalgenaf" ]; then
1673                 aof="0.000"
1674                 if [ $oldgenafparam -ne 1 ]; then
1675                         laof="0.0"
1676                         lexp="0.0"
1677 #                       LEXP="0.0" # default = 0.0
1678                         usenaivepairscore="-Z"
1679                 fi
1680         fi
1681
1682
1683 #       if [ $nseq -gt 5000 ]; then
1684 #               fft=0
1685 #       fi
1686         if [ $forcefft -eq 1 ]; then
1687                 param_fft=" -G "
1688                 fft=1
1689         elif [ $fft -eq 1 ]; then
1690                 param_fft=" -F "
1691         else
1692                 param_fft=" "
1693         fi
1694
1695         if [ $seed != "x" -a $seedtable != "x" ]; then
1696                         echo 'Use either one of seedtable and seed.  Not both.' 1>&2
1697                         exit 1
1698         fi
1699         if [ $f2clext = "-E" -a $anysymbol -gt 0 ]; then
1700                         echo '' 1>&2
1701                         echo 'At present, the combination of --text and ( --anysymbol or --preservecase ) is impossible.' 1>&2
1702                         echo '' 1>&2
1703                         exit 1
1704         fi
1705
1706         if [ $f2clext = "-E" -a $aamatrix != "/dev/null" ]; then
1707                         echo '' 1>&2
1708                         echo 'At present, the combination of --text and (--aamatrix) is impossible.' 1>&2
1709                         echo '' 1>&2
1710                         exit 1
1711         fi
1712
1713         if [ $treein -eq 1 ]; then
1714 #               if [ $iterate -gt 0 ]; then
1715 #                       echo 'Not supported yet.' 1>&2
1716 #                       exit 1
1717 #               fi
1718                 if [ ! -s $TMPFILE/_guidetree ]; then
1719                         if [ $distance != "ktuples" ]; then
1720                                 echo "Not supported yet"  1>>"$progressfile"
1721                                 exit 1
1722                         fi
1723                         if [ $pileuporshuffle = "p" ]; then
1724                                 echo "pileup" > $TMPFILE/_guidetree
1725 #                               weightopt=" -u " -> disttbfast.c?
1726 #                               numthreadstb=0 -> disttbfast.c
1727                                 cycle=1       #  disttbfast. shitei
1728                         elif [ $pileuporshuffle = "s" ]; then
1729                                 echo "shuffle $randomseed" > $TMPFILE/_guidetree
1730 #                               numthreadstb=0 -> disttbfast.c
1731 #                               weightopt=" -u " -> disttbfast.c?
1732                                 cycle=1       #  disttbfast.c dem shitei
1733                         elif [ $pileuporshuffle = "C" ]; then
1734                                 echo "very compact" > $TMPFILE/_guidetree
1735                         elif [ $pileuporshuffle = "c" ]; then
1736                                 echo "compact " "$initialramusage" > $TMPFILE/_guidetree
1737                         elif [ $pileuporshuffle = "a" ]; then
1738                                 echo "auto $randomseed 200" > $TMPFILE/_guidetree
1739                         fi
1740                 fi
1741         fi
1742
1743         if [ $nadd -gt "0" ]; then
1744                 if [ $fragment -eq "1" ]; then
1745                         addarg="$addarg0 $nadd -g -0.01"
1746                         addsinglearg=""
1747                         cycle=1 # chuui 2014Aug25
1748                 elif [ $fragment -eq "-1" ]; then
1749                         addarg="$addarg0 $nadd"
1750                         addsinglearg="-V"       # allowlongadds, 2014/04/02
1751                         cycle=1 # chuui 2014Aug25
1752                 elif [ $fragment -eq "-2" ]; then
1753                         addarg="$addarg0 $nadd"
1754                         addsinglearg="-V"       # allowlongadds + smoothing
1755                         add2ndhalfarg=$add2ndhalfarg" -p "
1756                         cycle=1 # chuui 2014Aug25
1757                         usenaivepairscore="-Z" # 2015Jun01
1758                         laof=0.0               # 2015Jun01
1759                         lexp=0.0               # 2015Jun01
1760                 else
1761                         addarg="$addarg0 $nadd"
1762                         addsinglearg=""
1763                 fi
1764
1765 #               cycle=1 # chuui 2014Aug19
1766                 iterate=0
1767 #               treealg=" -q "  ## 2012/01/24  ## removed 2012/02/06
1768         fi
1769
1770
1771         if [ -z "$localparam" -a $fragment -eq 0 -a $distance != "parttree" ]; then
1772 #               echo "use disttbfast"
1773 #               echo cycle = $cycle
1774                 cycletbfast=1            # tbfast wo jikkou shinai
1775                 cycledisttbfast=$cycle   # disttbfast ni -E cycle wo watasu
1776                 if [ $cycledisttbfast -eq 0 ]; then # --treeout de tsukau
1777                         cycledisttbfast=1
1778                 fi
1779         else
1780 #               echo "use tbfast"
1781 #               echo cycle = $cycle
1782                 cycletbfast=$cycle       # 1 ijou nara jikkou
1783                 cycledisttbfast=1        # disttbfast ha ikkai dake
1784         fi
1785
1786 #       echo localparam=
1787 #       echo $localparam
1788 #       echo cycletbfast=
1789 #       echo $cycletbfast
1790 #       echo cycledisttbfast=
1791 #       echo $cycledisttbfast
1792
1793 #exit
1794
1795         if [ $adjustdirection -gt 0 -a $seed != "x" ]; then
1796                         echo '' 1>&2
1797                         echo 'The combination of --adjustdirection(accurately) and --seed is not supported.' 1>&2
1798                         echo '' 1>&2
1799                         exit 1
1800         fi
1801
1802
1803         if [ $mccaskill -eq 1 -o $dafs -eq 1 -o $rnaalifold -eq 1 -o $contrafold -eq 1 ]; then
1804                 if [ $distance = "ktuples" ]; then
1805                         echo 'Not supported.' 1>&2
1806                         echo 'Please add --globalpair, --localpair, --scarnapair, --dafspair' 1>&2
1807                         echo '--larapair, --slarapair, --foldalignlocalpair or --foldalignglobalpair' 1>&2
1808                         exit 1
1809                 fi
1810                 if [ $f2clext = "-E" ]; then
1811                                 echo '' 1>&2
1812                                 echo 'For RNA alignment, the --text mode is impossible.' 1>&2
1813                                 echo '' 1>&2
1814                                 exit 1
1815                 fi
1816         fi
1817
1818 # cycle ga atode henkou sareru node koko de strategy no namae wo kimeru.
1819 # kokokara
1820         if [ $pileuporshuffle = "p" ]; then
1821                 strategy="Pileup-"
1822         elif [ $pileuporshuffle = "s" ]; then
1823                 strategy="Randomchain-"
1824         elif [ $mccaskill -eq 1 -o $dafs -eq 1 -o $rnaalifold -eq 1 -o $contrafold -eq 1 ]; then
1825                 if [ $distance = "scarna" -o $distance = "dafs" -o $distance = "lara" -o $distance = "slara" -o $distance = "foldalignlocal" -o $distance = "foldalignglobal" ]; then
1826                         strategy="X-"
1827                 elif [ $distance = "global" -o $distance = "local" -o $distance = "localgenaf" -o "globalgenaf" ]; then
1828                         strategy="Q-"
1829                 fi
1830         elif [ $distance = "fasta" -a $sw -eq 0 ]; then
1831                 strategy="F-"
1832         elif [ $distance = "fasta" -a $sw -eq 1 ]; then
1833                 strategy="H-"
1834         elif [ $distance = "blast" ]; then
1835                 strategy="B-"
1836         elif [ $distance = "global" -o $distance = "distonly" ]; then
1837                 strategy="G-"
1838         elif [ $distance = "local" ]; then
1839                 strategy="L-"
1840         elif [ $distance = "last" ]; then
1841                 strategy="Last-"
1842         elif [ $distance = "hybrid" ]; then
1843                 strategy="Hybrid-"
1844         elif [ $distance = "multi" ]; then
1845                 strategy="Multi-"
1846         elif [ $distance = "lastmulti" ]; then
1847                 strategy="LastMulti-"
1848         elif [ $distance = "localgenaf" ]; then
1849                 strategy="E-"
1850         elif [ $distance = "globalgenaf" ]; then
1851                 strategy="K-"
1852         elif [ $fft -eq 1 ]; then
1853                 strategy="FFT-"
1854         else
1855                 strategy="NW-"
1856         fi
1857 #       if [ `echo "$weighti>0.0" | bc` -gt 0 ]; then
1858         if [ `awk "BEGIN {print(0.0+\"$weighti\">0.0)}"` -gt 0 ]; then
1859                 strategy=$strategy"I"
1860         fi
1861         strategy=$strategy"NS-"
1862         if [ $iterate -gt 0 ]; then
1863                 strategy=$strategy"i"
1864         elif [ $distance = "parttree" ]; then
1865                 if [ $partdist = "fasta" ]; then
1866                         strategy=$strategy"FastaPartTree-"$cycle
1867                 elif [ $partdist = "localalign" ]; then
1868                         strategy=$strategy"DPPartTree-"$cycle
1869                 else
1870                         strategy=$strategy"PartTree-"$cycle
1871                 fi
1872         elif [ $fragment -eq 1 ]; then
1873                 strategy=$strategy"fragment"
1874         elif [ $fragment -eq -1 ]; then
1875                 strategy=$strategy"full"
1876         elif [ $fragment -eq -2 ]; then
1877                 strategy=$strategy"long"
1878         else
1879                 strategy=$strategy$cycle
1880         fi
1881
1882         explanation='?'
1883         performance='Not tested.'
1884         if [ $strategy = "F-INS-i" ]; then
1885                 explanation='Iterative refinement method (<'$iterate') with LOCAL pairwise alignment information'
1886                 performance='Most accurate, but very slow'
1887         elif [ $strategy = "L-INS-i" ]; then
1888                 explanation='Iterative refinement method (<'$iterate') with LOCAL pairwise alignment information'
1889                 performance='Probably most accurate, very slow'
1890         elif [ $strategy = "E-INS-i" ]; then
1891                 explanation='Iterative refinement method (<'$iterate') with LOCAL pairwise alignment with generalized affine gap costs (Altschul 1998)'
1892                 performance='Suitable for sequences with long unalignable regions, very slow'
1893         elif [ $strategy = "G-INS-i" ]; then
1894                 explanation='Iterative refinement method (<'$iterate') with GLOBAL pairwise alignment information'
1895                 performance='Suitable for sequences of similar lengths, very slow'
1896         elif [ $strategy = "X-INS-i" ]; then
1897                 explanation='RNA secondary structure information is taken into account.'
1898                 performance='For short RNA sequences only, extremely slow'
1899         elif [ $strategy = "F-INS-1" ]; then
1900                 explanation='Progressive method incorporating LOCAL pairwise alignment information'
1901         elif [ $strategy = "L-INS-1" ]; then
1902                 explanation='Progressive method incorporating LOCAL pairwise alignment information'
1903         elif [ $strategy = "G-INS-1" ]; then
1904                 explanation='Progressive method incorporating GLOBAL pairwise alignment information'
1905         elif [ $strategy = "FFT-NS-i" -o $strategy = "NW-NS-i" ]; then
1906                 explanation='Iterative refinement method (max. '$iterate' iterations)'
1907                 if [ $iterate -gt 2 ]; then
1908                         performance='Accurate but slow'
1909                 else
1910                         performance='Standard'
1911                 fi
1912         elif [ $strategy = "FFT-NS-2" -o $strategy = "NW-NS-2" ]; then
1913                 explanation='Progressive method (guide trees were built '$cycle' times.)'
1914                 performance='Fast but rough'
1915         elif [ $strategy = "FFT-NS-1" -o $strategy = "NW-NS-1" ]; then
1916                 explanation='Progressive method (rough guide tree was used.)'
1917                 performance='Very fast but very rough'
1918         fi
1919
1920         if [ $outputformat = "clustal" -a $outorder = "aligned" ]; then
1921                 outputopt=" -c $strategy -r $TMPFILE/order $f2clext "
1922         elif [ $outputformat = "clustal" -a $outorder = "input" ]; then
1923                 outputopt=" -c $strategy  $f2clext "
1924         elif [ $outputformat = "phylip" -a $outorder = "aligned" ]; then
1925                 outputopt=" -y -r $TMPFILE/order "
1926         elif [ $outputformat = "phylip" -a $outorder = "input" ]; then
1927                 outputopt=" -y "
1928         elif [ $outputformat = "pir" -a $outorder = "aligned" ]; then
1929                 outputopt=" -f -r $TMPFILE/order "
1930         else
1931                 outputopt="null"
1932         fi
1933 # kokomade
1934
1935         
1936         
1937 #       ( # 2017/Mar/17
1938                 pushd $TMPFILE > /dev/null;
1939
1940                 cat /dev/null > pre
1941
1942 #               echo "nseq = " $nseq              1>>"$progressfile"
1943 #               echo "distance = " $distance      1>>"$progressfile"
1944 #               echo "iterate = " $iterate        1>>"$progressfile"
1945 #               echo "cycle = " $cycle            1>>"$progressfile"
1946
1947                 if [ $anysymbol -eq 1 ]; then
1948                         mv infile orig
1949                         "$prefix/replaceu" $seqtype -i orig > infile 2>>"$progressfile" || exit 1
1950                 fi
1951
1952                 if [ $mergetable != "/dev/null" ]; then
1953                         if [ $nadd -gt "0" ]; then
1954                                 echo "Impossible" 1>&2
1955                                 exit 1
1956                         fi
1957 #                       if [ $seed != "x" -o $seedtable != "x" ]; then
1958 #                               echo "This version does not support the combination of merge and seed." 1>&2
1959 #                               exit 1
1960 #                       fi
1961 #                       iterate=0 # 2013/04/16
1962                         mergearg="-H $seedoffset"
1963                 fi
1964
1965                 if [ $adjustdirection -gt 0 ]; then
1966                         if [ $fragment -ne 0 ]; then
1967                                 fragarg="-F" #
1968                         else
1969                                 fragarg="-F" # 2014/02/06, do not consider other additional sequences, even in the case of --add
1970                         fi
1971                         if [ $adjustdirection -eq 1 ]; then
1972                                 "$prefix/makedirectionlist" $fragarg -C $numthreads -m -I $nadd -i infile -t 0.00 -r 5000 -o a > _direction 2>>"$progressfile" 
1973                         elif [ $adjustdirection -eq 2 ]; then
1974                                 "$prefix/makedirectionlist" $fragarg -C $numthreads -m -I $nadd -i infile -t 0.00 -r 100 -o a -d > _direction 2>>"$progressfile" 
1975                         fi
1976                         "$prefix/setdirection" $mergearg -d _direction -i infile > infiled 2>>"$progressfile" || exit
1977                         mv infiled infile
1978                         if [ $anysymbol -eq 1 ]; then
1979                                 "$prefix/setdirection" $mergearg -d _direction -i orig -r  > origd 2>>"$progressfile" || exit
1980                                 mv origd orig
1981                         fi
1982                 fi
1983
1984                 if [ $seed != "x" -o $seedtable != "x" ]; then
1985                         if [ $pdblist != "/dev/null" -o $ownlist != "/dev/null" ]; then
1986                                 echo "The combination of --seed and (--pdbidlist or --pdbfilelist) is impossible."  1>>"$progressfile"
1987                                 exit 1
1988                         fi
1989                         if [ $enrich -eq 1 ]; then
1990                                 echo "The combination of --seed and (--enrich, --enrichseq or --enrichstr) is impossible at present."  1>>"$progressfile"
1991                                 exit 1
1992                         fi
1993                 fi
1994
1995                 if [ $enrich -eq 1 ]; then
1996                         if [ $ownlist != "/dev/null" ]; then
1997                                 echo "Warning: Sequence homologs of the structures given with the --pdbfilelist option cannot be collected.\n" 1>>"$progressfile"
1998                         fi
1999                         echo "SEEKQUENCER (http://sysimm.ifrec.osaka-u.ac.jp/seekquencer/) is" 1>>"$progressfile"
2000                         if [ $pdblist != "/dev/null" ]; then
2001                                 echo "collecting homoplogs of the input sequences and the structures given with the --pdbidlist option." 1>>"$progressfile"
2002                                 perl "$prefix/seekquencer_premafft.pl" $seektarget -run thread -trd 2 -seqd uniref90 -blim 1000 -noin -seqf infile -idf pdblist -out seekout -mod mafftash-split 2>>"seekerr"
2003                                 seekres="$?"
2004                         else
2005                                 echo "collecting homologs of the input sequences." 1>>"$progressfile"
2006                                 perl "$prefix/seekquencer_premafft.pl" $seektarget -run thread -trd 2 -seqd uniref90 -blim 1000 -noin -seqf infile -out seekout -mod mafftash-split 2>>"seekerr"
2007                                 seekres="$?"
2008                         fi
2009                         cat seekerr  1>>"$progressfile"
2010
2011                         if [ $seekres -ne "0" ]; then
2012                                 echo "Error in SEEKQUENCER" 1>>"$progressfile"
2013                                 exit 1;
2014                         fi
2015                         echo "Done." 1>>"$progressfile"
2016
2017                         if [ $enrichseq -eq 1 ]; then
2018 #                               cat seekout.seq >> infile
2019                                 if [ $anysymbol -eq 1 ]; then
2020                                         "$prefix/replaceu" $seqtype -i seekout.seq -o $nseq >> infile
2021                                         cat seekout.seq >> orig
2022                                 else
2023                                         "$prefix/replaceu" $seqtype -i seekout.seq | sed 's/_os_[0-9]*_oe_//' >> infile
2024                                 fi
2025
2026                         fi
2027                         if [ $enrichstr -eq 1 ]; then
2028                                 nseekstr=`wc -l < seekout.str`
2029                                 if [ $nseekstr -gt 1 ]; then
2030                                         cat seekout.str >> pdblist
2031                                         pdblist="tsukaimasu"
2032                                 fi
2033                         fi
2034                 fi
2035
2036                 if [ $seed != "x" ]; then
2037                         mv infile infile2
2038                         if [ $anysymbol -eq 1 ]; then
2039                                 mv orig orig2
2040                                 cat /dev/null > orig
2041                         fi
2042                         cat /dev/null > infile
2043                         cat /dev/null > hat3.seed
2044                         seedoffset=0
2045 #                       echo "seednseq="$seednseq
2046 #                       echo "seedoffset="$seedoffset
2047                         set $seednseq >> "$progressfile"
2048 #                       echo $#
2049                         while [ $# -gt 1 ]
2050                         do
2051                                 shift
2052 #                               echo "num="$#
2053
2054                                 if [ $anysymbol -eq 1 ]; then
2055                                         cat seed$# >> orig
2056                                         "$prefix/replaceu" $seqtype -i seed$# -o $seedoffset > clean 2>>"$progressfile" || exit 1
2057                                         mv clean seed$#
2058                                 fi
2059                                 "$prefix/multi2hat3s" -t $nseq -o $seedoffset -i seed$# >> infile 2>>"$progressfile" || exit 1
2060                                 cat hat3 >> hat3.seed
2061 #                               echo "$1"
2062                                 seedoffset=`expr $seedoffset + $1`
2063 #                               echo "$1"
2064 #                               echo "seedoffset="$seedoffset
2065                         done;
2066 #                       echo "seedoffset="$seedoffset
2067                         if [ $anysymbol -eq 1 ]; then
2068                                 "$prefix/replaceu" $seqtype -i orig2 -o $seedoffset >> infile 2>>"$progressfile" || exit 1  # yarinaoshi
2069                                 cat orig2 >> orig
2070                         else
2071                                 cat infile2 >> infile
2072                         fi
2073                 elif [ $seedtable != "x" ]; then
2074                         cat _seedtablefile > hat3.seed
2075                 elif [ $pdblist != "/dev/null" -o $ownlist != "/dev/null" ]; then
2076                         mv infile infile2
2077                         if [ $anysymbol -eq 1 ]; then
2078                                 mv orig orig2
2079                                 cat /dev/null > orig
2080                         fi
2081                         cat /dev/null > infile
2082
2083                         echo "strdir = " 1>>"$progressfile"
2084                         echo $strdir 1>>"$progressfile"
2085
2086                         echo "Calling DASH (http://sysimm.ifrec.osaka-u.ac.jp/dash/)" 1>>"$progressfile"
2087                         perl "$prefix/mafftash_premafft.pl" -p pdblist -o ownlist -d "$strdir" 2>>"dasherr"
2088                         dashres="$?"
2089                         cat dasherr  1>>"$progressfile"
2090
2091                         if [ $dashres -ne "0" ]; then
2092                                 echo "Error in DASH" 1>>"$progressfile"
2093                                 exit 1;
2094                         fi
2095                         echo "Done." 1>>"$progressfile"
2096
2097                         seedoffset=`grep -c '^[>|=]' instr | head -1 ` 
2098
2099                         echo "# of structures = " 1>>"$progressfile"
2100                         echo $seedoffset 1>>"$progressfile"
2101                         mv hat3 hat3.seed
2102
2103                         if [ $anysymbol -eq 1 ]; then
2104                                 cat instr >> orig
2105                                 "$prefix/replaceu" $seqtype -i instr -o 0 > clean 2>>"$progressfile" || exit 1
2106                                 mv clean infile
2107
2108                                 "$prefix/replaceu" $seqtype -i orig2 -o $seedoffset >> infile 2>>"$progressfile" || exit 1  # yarinaoshi
2109                                 cat orig2 >> orig
2110                         else
2111                                 cat instr > infile
2112                                 cat infile2 >> infile
2113                         fi
2114                 else
2115                         cat /dev/null > hat3.seed
2116                 fi
2117 #               cat hat3.seed
2118
2119
2120
2121
2122                 if [ $mccaskill -eq 1 ]; then
2123                         "$prefix/mccaskillwrap" -s -C $numthreads -d "$prefix" -i infile > hat4 2>>"$progressfile" || exit 1
2124                 elif [ $dafs -eq 1 ]; then
2125                         "$prefix/mccaskillwrap" -G -C $numthreads -d "$prefix" -i infile > hat4 2>>"$progressfile" || exit 1
2126                 elif [ $contrafold -eq 1 ]; then
2127                         "$prefix/contrafoldwrap" -d "$prefix" -i infile > hat4 2>>"$progressfile" || exit 1
2128                 fi
2129                 if [ $distance = "fasta" ]; then
2130                         "$prefix/dndfast7" $swopt < infile > /dev/null  2>>"$progressfile"    || exit 1
2131                         cat hat3.seed hat3 > hatx
2132                         mv hatx hat3
2133                         "$prefix/tbfast" -W $minimumweight -V "-"$gopdist -s $unalignlevel $legacygapopt $mergearg $outnum $addarg $add2ndhalfarg -C $numthreadstb $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop -Q $spfactor -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2134                 elif [ $distance = "blast" ]; then
2135                         "$prefix/dndblast" < infile > /dev/null  2>>"$progressfile"      || exit 1
2136                         cat hat3.seed hat3 > hatx
2137                         mv hatx hat3
2138                         "$prefix/tbfast" -W $minimumweight -V "-"$gopdist -s $unalignlevel $legacygapopt $mergearg $outnum $addarg $add2ndhalfarg -C $numthreadstb $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop -Q $spfactor -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2139                 elif [ $distance = "foldalignlocal" ]; then
2140                         "$prefix/pairlocalalign" -C $numthreads $seqtype $foldalignopt $model -g $lexp -f $lgop -Q $spfactor -h $laof -H -d "$prefix" < infile > /dev/null  2>>"$progressfile"      || exit 1
2141                         cat hat3.seed hat3 > hatx
2142                         mv hatx hat3
2143                         "$prefix/tbfast" -W $minimumweight -V "-"$gopdist -s $unalignlevel $legacygapopt $mergearg $outnum $addarg $add2ndhalfarg -C $numthreadstb $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop -Q $spfactor -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2144                 elif [ $distance = "foldalignglobal" ]; then
2145                         "$prefix/pairlocalalign" -C $numthreads $seqtype $foldalignopt $model -g $pgexp -f $pggop -Q $spfactor -h $pgaof -H -o -global -d "$prefix" < infile > /dev/null  2>>"$progressfile"      || exit 1
2146                         cat hat3.seed hat3 > hatx
2147                         mv hatx hat3
2148                         "$prefix/tbfast" -W $minimumweight -V "-"$gopdist -s $unalignlevel $legacygapopt $mergearg $outnum $addarg $add2ndhalfarg -C $numthreadstb $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop -Q $spfactor -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2149                 elif [ $distance = "slara" ]; then
2150                         "$prefix/pairlocalalign" -C $numthreads -p $laraparams  $seqtype $model  -f $lgop -Q $spfactor -T -d "$prefix" < infile > /dev/null  2>>"$progressfile"      || exit 1
2151                         cat hat3.seed hat3 > hatx
2152                         mv hatx hat3
2153                         "$prefix/tbfast" -W $minimumweight -V "-"$gopdist -s $unalignlevel $legacygapopt $mergearg $outnum $addarg $add2ndhalfarg -C $numthreadstb $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop -Q $spfactor -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2154                 elif [ $distance = "lara" ]; then
2155                         "$prefix/pairlocalalign" -C $numthreads -p $laraparams  $seqtype $model  -f $lgop -Q $spfactor -B -d "$prefix" < infile > /dev/null  2>>"$progressfile"      || exit 1
2156                         cat hat3.seed hat3 > hatx
2157                         mv hatx hat3
2158                         "$prefix/tbfast" -W $minimumweight -V "-"$gopdist -s $unalignlevel $legacygapopt $mergearg $outnum $addarg $add2ndhalfarg -C $numthreadstb $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop -Q $spfactor -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2159                 elif [ $distance = "scarna" ]; then
2160 #                       "$prefix/pairlocalalign"   -C $numthreads $seqtype $model  -f $pggop -Q $spfactor -s -d "$prefix" < infile > /dev/null  2>>"$progressfile"      || exit 1
2161 #                       cat hat3.seed hat3 > hatx
2162 #                       mv hatx hat3
2163 #                       "$prefix/tbfast" -W $minimumweight -V "-"$gopdist -s $unalignlevel $legacygapopt $mergearg $outnum $addarg $add2ndhalfarg -C $numthreadstb $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop -Q $spfactor -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2164                         "$prefix/tbfast" _  -C $numthreads $seqtype $model  -f $pggop -Q $spfactor -s -d "$prefix" _ -+ $iterate -W $minimumweight -V "-"$gopdist -s $unalignlevel $legacygapopt $mergearg $outnum $addarg $add2ndhalfarg -C $numthreadstb $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop -Q $spfactor -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2165                 elif [ $distance = "dafs" ]; then
2166                         "$prefix/pairlocalalign"  -C $numthreads $seqtype $model  -f $pggop -Q $spfactor -G -d "$prefix" < infile > /dev/null  2>>"$progressfile"      || exit 1
2167                         cat hat3.seed hat3 > hatx
2168                         mv hatx hat3
2169                         "$prefix/tbfast" -W $minimumweight -V "-"$gopdist -s $unalignlevel $legacygapopt $mergearg $outnum $addarg $add2ndhalfarg -C $numthreadstb $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop -Q $spfactor -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2170                 elif [ $distance = "global" ]; then
2171 #                       "$prefix/pairlocalalign" -u $unalignlevel $localparam  -C $numthreads $seqtype $model -g $pgexp -f $pggop -Q $spfactor -h $pgaof  -A  $usenaivepairscore $focusarg < infile > /dev/null  2>>"$progressfile"      || exit 1
2172 #                       cat hat3.seed hat3 > hatx
2173 #                       mv hatx hat3
2174 #                       "$prefix/tbfast" -W $minimumweight -V "-"$gopdist -s $unalignlevel $legacygapopt $mergearg $outnum $addarg $add2ndhalfarg -C $numthreadstb $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop -Q $spfactor -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg $focusarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2175                         "$prefix/tbfast" _  -u $unalignlevel $localparam  -C $numthreads $seqtype $model -g $pgexp -f $pggop -Q $spfactor -h $pgaof  -A  $usenaivepairscore $focusarg  _ -+ $iterate -W $minimumweight -V "-"$gopdist -s $unalignlevel $legacygapopt $mergearg $outnum $addarg $add2ndhalfarg -C $numthreadstb $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop -Q $spfactor -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg $focusarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2176                         
2177                 elif [ $distance = "local" ]; then
2178                         if [ $fragment -ne 0 ]; then 
2179                                 "$prefix/pairlocalalign" $localparam $addarg   -C $numthreads $seqtype $model  -g $lexp -f $lgop -Q $spfactor -h $laof -L $usenaivepairscore < infile > /dev/null  2>>"$progressfile"      || exit 1
2180                                 cat hat3.seed hat3 > hatx
2181                                 mv hatx hat3
2182                                 "$prefix/addsingle" -Q 100 $legacygapopt -O $outnum $addsinglearg $addarg $add2ndhalfarg -C $numthreads $memopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2183                         else
2184 #                               "$prefix/pairlocalalign" -u $unalignlevel $localparam -C $numthreads $seqtype $model  -g $lexp -f $lgop -Q $spfactor -h $laof -L $usenaivepairscore $focusarg < infile > /dev/null  2>>"$progressfile"      || exit 1
2185 #                               addarg wo watasanai
2186 #                               cat hat3.seed hat3 > hatx
2187 #                               mv hatx hat3
2188 #                               "$prefix/tbfast" -W $minimumweight -V "-"$gopdist -s $unalignlevel $legacygapopt $mergearg $termgapopt $outnum $addarg $add2ndhalfarg -C $numthreadstb $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop -Q $spfactor -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg $focusarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2189                                 "$prefix/tbfast" _  -u $unalignlevel $localparam -C $numthreads $seqtype $model  -g $lexp -f $lgop -Q $spfactor -h $laof -L $usenaivepairscore $focusarg _ -+ $iterate -W $minimumweight -V "-"$gopdist -s $unalignlevel $legacygapopt $mergearg $termgapopt $outnum $addarg $add2ndhalfarg -C $numthreadstb $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop -Q $spfactor -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg $focusarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2190                         fi
2191                 elif [ $distance = "globalgenaf" ]; then
2192                         "$prefix/pairlocalalign"  -u $unalignlevel $localparam -C $numthreads $seqtype $model  -g $pgexp -f $pggop -Q $spfactor -h $pgaof -O $GGOP -E $GEXP -K $usenaivepairscore < infile > /dev/null 2>>"$progressfile"    || exit 1
2193                         cat hat3.seed hat3 > hatx
2194                         mv hatx hat3
2195                         "$prefix/tbfast" -W $minimumweight -V "-"$gopdist -s $unalignlevel $legacygapopt $mergearg $outnum $addarg $add2ndhalfarg -C $numthreadstb $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop -Q $spfactor -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2196                 elif [ $distance = "localgenaf" ]; then
2197 #                       "$prefix/pairlocalalign"  -u $unalignlevel $localparam -C $numthreads $seqtype $model -g $lexp -f $lgop -Q $spfactor -h $laof -O $LGOP -E $LEXP -N $usenaivepairscore $focusarg < infile > /dev/null  2>>"$progressfile"      || exit 1
2198 #                       cat hat3.seed hat3 > hatx
2199 #                       mv hatx hat3
2200 #                       "$prefix/tbfast" -W $minimumweight -V "-"$gopdist -s $unalignlevel $legacygapopt $mergearg $termgapopt $outnum $addarg $add2ndhalfarg -C $numthreadstb $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop -Q $spfactor -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg $focusarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2201                         "$prefix/tbfast" _ -u $unalignlevel $localparam -C $numthreads $seqtype $model -g $lexp -f $lgop -Q $spfactor -h $laof -O $LGOP -E $LEXP -N $usenaivepairscore $focusarg _ -+ $iterate -W $minimumweight -V "-"$gopdist -s $unalignlevel $legacygapopt $mergearg $termgapopt $outnum $addarg $add2ndhalfarg -C $numthreadstb $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop -Q $spfactor -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg $focusarg < infile > /dev/null  2>>"$progressfile"      || exit 1
2202                 elif [ $distance = "last" ]; then
2203                         if [ $fragment -ne 0 ]; then 
2204                                 "$prefix/pairlocalalign" $addarg   -C $numthreads $seqtype $model -e $last_e -w $last_m -g $lexp -f $lgop -Q $spfactor -h $laof -R $last_subopt $last_once -d "$prefix" < infile > /dev/null  2>>"$progressfile"      || exit 1
2205                                 cat hat3.seed hat3 > hatx
2206                                 mv hatx hat3
2207                                 "$prefix/addsingle" -Q 100 $legacygapopt -O $outnum $addsinglearg $addarg $add2ndhalfarg -C $numthreads $memopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2208                         else
2209                                 "$prefix/pairlocalalign" -C $numthreads $seqtype $model -e $last_e -w $last_m -g $lexp -f $lgop -Q $spfactor -h $laof -R $last_subopt $last_once -d "$prefix" < infile > /dev/null  2>>"$progressfile"      || exit 1
2210 #                               addarg wo watasanai
2211                                 cat hat3.seed hat3 > hatx
2212                                 mv hatx hat3
2213                                 "$prefix/tbfast" -W $minimumweight -V "-"$gopdist -s $unalignlevel $legacygapopt $mergearg $termgapopt $outnum $addarg $add2ndhalfarg -C $numthreadstb $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop -Q $spfactor -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2214                         fi
2215                 elif [ $distance = "lastmulti" ]; then
2216                         "$prefix/dndpre" $model -M 2 $addarg -C $numthreads $seqtype $model -g $lexp -f $lgop -Q $spfactor -h $laof < infile > /dev/null 2>>"$progressfile"      || exit 1
2217                         mv hat2 hat2i
2218                         "$prefix/pairlocalalign" $addarg   -C $numthreads $seqtype $model -e $last_e -w $last_m -g $lexp -f $lgop -Q $spfactor -h $laof -r $last_subopt $last_once -d "$prefix" < infile > /dev/null  2>>"$progressfile"      || exit 1
2219                         cat hat3.seed hat3 > hatx
2220                         mv hat2 hat2n
2221                         mv hatx hat3
2222                         if [ $fragment -ne 0 ]; then 
2223                                 "$prefix/addsingle" -Q 100 $legacygapopt -d -O $outnum $addsinglearg $addarg $add2ndhalfarg -C $numthreads $memopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2224                         else
2225                                 echo "Impossible" 1>&2
2226                                 exit 1
2227                         fi
2228                 elif [ $distance = "multi" ]; then
2229                         "$prefix/dndpre" $model -M 2 $addarg -C $numthreads $seqtype $model -g $lexp -f $lgop -h $laof  $usenaivepairscore < infile > /dev/null 2>>"$progressfile"      || exit 1
2230                         mv hat2 hat2i
2231                         "$prefix/pairlocalalign" $localparam $addarg   -C $numthreads $seqtype $model  -g $lexp -f $lgop -Q $spfactor -h $laof -Y $usenaivepairscore < infile > /dev/null  2>>"$progressfile"      || exit 1
2232                         cat hat3.seed hat3 > hatx
2233                         mv hat2 hat2n
2234                         mv hatx hat3
2235                         if [ $fragment -ne 0 ]; then 
2236                                 "$prefix/addsingle" -Q 100 $legacygapopt -d -O $outnum $addsinglearg $addarg $add2ndhalfarg -C $numthreads $memopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2237                         else
2238                                 echo "Impossible" 1>&2
2239                                 exit 1
2240                         fi
2241                 elif [ $distance = "hybrid" ]; then
2242                         "$prefix/pairlocalalign" $addarg   -C $numthreads $seqtype $model  -g $lexp -f $lgop -Q $spfactor -h $laof -Y < infile > /dev/null  2>>"$progressfile"      || exit 1
2243                         cat hat3.seed hat3 > hatx
2244                         mv hatx hat3
2245                         "$prefix/disttbfast" -E 1 -s $unalignlevel $legacygapopt -W $tuplesize $termgapopt $outnum $addarg $add2ndhalfarg -C $numthreadstb $memopt $weightopt $treeinopt $treeoutopt -T -y $seqtype $model -f "-"$gop -Q $spfactor -h $aof  $param_fft $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2246                         if [ $fragment -ne 0 ]; then 
2247                                 "$prefix/addsingle" -Q 100 $legacygapopt -O $outnum $addsinglearg $addarg $add2ndhalfarg -C $numthreads $memopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2248                         else
2249                                 "$prefix/tbfast" -W $minimumweight -V "-"$gopdist -s $unalignlevel $legacygapopt $mergearg $termgapopt $outnum $addarg $add2ndhalfarg -C $numthreadstb $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop -Q $spfactor -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2250                         fi
2251 #               elif [ $distance = "distonly" ]; then
2252 #                       "$prefix/pairlocalalign"   -C $numthreads $seqtype $model -g $pgexp -f $pggop -Q $spfactor -h $pgaof  -t < infile > /dev/null  2>>"$progressfile"      || exit 1
2253 #                       "$prefix/tbfast" -W $minimumweight -V "-"$gopdist -s $unalignlevel $legacygapopt $outnum $addarg $add2ndhalfarg -C $numthreadstb $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop -Q $spfactor -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2254                 elif [ $distance = "parttree" ]; then
2255                         "$prefix/splittbfast" $legacygapopt $algopt $splitopt $partorderopt $parttreeoutopt $memopt $seqtype $model -f "-"$gop -Q $spfactor -h $aof -p $partsize -s $groupsize $treealg $outnum -i infile   > pre 2>>"$progressfile" || exit 1
2256                         mv hat3.seed hat3
2257                 elif [ $distance = "ktuplesmulti" ]; then
2258 #                       "$prefix/dndpre" $model -M 1 $addarg -C $numthreads $seqtype $model -g $lexp -f $lgop -h $laof < infile > /dev/null 2>>"$progressfile"      || exit 1
2259 #                       mv hat2 hat2i
2260 #                       "$prefix/disttbfast" -E 1 -s $unalignlevel $legacygapopt -W $tuplesize $termgapopt $outnum $addarg $add2ndhalfarg -C $numthreadstb $memopt $weightopt $treeinopt $treeoutopt -T -y $seqtype $model -f "-"$gop -Q $spfactor -h $aof  $param_fft $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2261 #                       mv hat2 hat2n
2262                         if [ $fragment -ne 0 ]; then 
2263                                 "$prefix/addsingle" -Q 100 $legacygapopt -d -W $tuplesize -O $outnum $addsinglearg $addarg $add2ndhalfarg -C $numthreads $memopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2264 #                               "$prefix/addsingle" -Q 100 $legacygapopt -d -O $outnum $addsinglearg $addarg $add2ndhalfarg -C $numthreads $memopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2265                         else
2266                                 echo "Impossible" 1>&2
2267                                 exit 1
2268                         fi
2269                 else
2270                         if [ $fragment -ne 0 ]; then 
2271                                 "$prefix/addsingle" -Q 100 $legacygapopt -W $tuplesize -O $outnum $addsinglearg $addarg $add2ndhalfarg -C $numthreads $memopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h $aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>>"$progressfile" || exit 1
2272                         else
2273                                 "$prefix/disttbfast" -q $npickup -E $cycledisttbfast -V "-"$gopdist  -s $unalignlevel $legacygapopt $mergearg -W $tuplesize $termgapopt $outnum $addarg $add2ndhalfarg -C $numthreadstb $memopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop -Q $spfactor -h $aof  $param_fft $algopt $treealg $scoreoutarg < infile   > pre 2>>"$progressfile" || exit 1
2274                                 mv hat3.seed hat3
2275                         fi
2276                 fi
2277                 while [ $cycletbfast -gt 1 ]
2278                 do
2279                         if [ $distance = "parttree" ]; then
2280                                 mv pre infile
2281                                 "$prefix/splittbfast" $legacygapopt -Z $algopt $splitopt $partorderopt $parttreeoutopt $memopt $seqtype $model -f "-"$gop -Q $spfactor -h $aof  -p $partsize -s $groupsize $treealg $outnum -i infile   > pre 2>>"$progressfile" || exit 1
2282                         else
2283                                 "$prefix/tbfast" -W $minimumweight -V "-"$gopdist -s $unalignlevel $legacygapopt $mergearg $termgapopt $outnum -C $numthreadstb $rnaopt $weightopt $treeoutopt $distoutopt $memopt $seqtype $model  -f "-"$gop -Q $spfactor -h $aof $param_fft  $localparam $algopt -J $treealg $scoreoutarg < pre > /dev/null 2>>"$progressfile" || exit 1
2284 # fragment>0 no baai, nanimoshinai
2285 # seed youchuui!!
2286                         fi
2287                         cycletbfast=`expr $cycletbfast - 1`
2288                 done
2289                 if [ $iterate -gt 0 ]; then
2290                         if [ $distance = "ktuples" ]; then
2291                             "$prefix/dndpre" $model -M 2 -C $numthreads < pre     > /dev/null 2>>"$progressfile" || exit 1
2292                         fi
2293                         "$prefix/dvtditr" -W $minimumweight $bunkatsuopt -E $fixthreshold -s $unalignlevel  $legacygapopt $mergearg $outnum -C $numthreadsit -t $randomseed $rnaoptit $memopt $scorecalcopt $localparam -z 50 $seqtype $model -f "-"$gop -Q $spfactor -h $aof  -I $iterate $weightopt $treeinopt $algoptit $treealg -p $parallelizationstrategy  $scoreoutarg < pre     > /dev/null 2>>"$progressfile" || exit 1
2294                 fi
2295                 if [ $coreout -eq 1 ]; then
2296                         "$prefix/setcore" -w $corewin -i $corethr $coreext < pre > pre2
2297                         mv pre2 pre
2298                 elif [ $anysymbol -eq 1 ]; then
2299                         "$prefix/restoreu" $add2ndhalfarg -a pre -i orig > restored || exit 1
2300                         mv restored pre
2301                 fi
2302
2303
2304
2305
2306                 echo '' 1>>"$progressfile"
2307                 if [ $mccaskill -eq 1 ]; then
2308                         echo "RNA base pairing probaility was calculated by the McCaskill algorithm (1)" 1>>"$progressfile"
2309                         echo "implemented in Vienna RNA package (2) and MXSCARNA (3), and then" 1>>"$progressfile"
2310                         echo "incorporated in the iterative alignment process (4)." 1>>"$progressfile"
2311                         echo "(1) McCaskill, 1990, Biopolymers 29:1105-1119" 1>>"$progressfile"
2312                         echo "(2) Hofacker et al., 2002, J. Mol. Biol. 319:3724-3732" 1>>"$progressfile"
2313                         echo "(3) Tabei et al., 2008, BMC Bioinformatics 9:33" 1>>"$progressfile"
2314                         echo "(4) Katoh and Toh, 2008, BMC Bioinformatics 9:212" 1>>"$progressfile"
2315                         echo "" 1>>"$progressfile"
2316                 elif [ $contrafold -eq 1 ]; then
2317                         echo "RNA base pairing probaility was calculated by the CONTRAfold algorithm (1)" 1>>"$progressfile"
2318                         echo "and then incorporated in the iterative alignment process (4)." 1>>"$progressfile"
2319                         echo "(1) Do et al., 2006, Bioinformatics 22:e90-98" 1>>"$progressfile"
2320                         echo "(2) Katoh and Toh, 2008, BMC Bioinformatics 9:212" 1>>"$progressfile"
2321                         echo "" 1>>"$progressfile"
2322                 fi
2323                 if [ $pdblist != "/dev/null" -o $ownlist != "/dev/null" ]; then
2324                         echo "Input structures are decomposed into structural domains using" 1>>"$progressfile"
2325                         echo "Protein Domain Parser (Alexandrov & Shindyalov 2003)."         1>>"$progressfile"
2326                         echo "Domain pairs are aligned using the rash function in"           1>>"$progressfile"
2327                         echo "the ASH structural alignment package (Standley et al. 2007)."  1>>"$progressfile"
2328                 fi
2329                 if [ $pdblist != "/dev/null" ]; then
2330                         echo "Pre-computed alignments stored in "                            1>>"$progressfile"
2331                         echo "DASH (http://sysimm.ifrec.osaka-u.ac.jp/dash/) are used. "     1>>"$progressfile"
2332                 fi
2333                 if [ $distance = "fasta" -o $partdist = "fasta" ]; then
2334                         echo "Pairwise alignments were computed by FASTA" 1>>"$progressfile"
2335                         echo "(Pearson & Lipman, 1988, PNAS 85:2444-2448)" 1>>"$progressfile"
2336                 fi
2337                 if [ $distance = "blast" ]; then
2338                         echo "Pairwise alignments were computed by BLAST" 1>>"$progressfile"
2339                         echo "(Altschul et al., 1997, NAR 25:3389-3402)" 1>>"$progressfile"
2340                 fi
2341                 if [ $distance = "last" -o $distance = "lastmulti" ]; then
2342                         echo "Pairwise alignments were computed by LAST" 1>>"$progressfile"
2343                         echo "http://last.cbrc.jp/" 1>>"$progressfile"
2344                         echo "Kielbasa, Wan, Sato, Horton, Frith 2011 Genome Res. 21:487" 1>>"$progressfile"
2345                 fi
2346                 if [ $distance = "scarna" ]; then
2347                         echo "Pairwise alignments were computed by MXSCARNA" 1>>"$progressfile"
2348                         echo "(Tabei et al., 2008, BMC Bioinformatics 9:33)." 1>>"$progressfile"
2349                 fi
2350                 if [ $distance = "dafs" ]; then
2351                         echo "Pairwise alignments were computed by DAFS" 1>>"$progressfile"
2352                         echo "(Sato et al., 2012,,,,)." 1>>"$progressfile"
2353                 fi
2354                 if [ $distance = "lara" -o $distance = "slara" ]; then
2355                         echo "Pairwise alignments were computed by LaRA" 1>>"$progressfile"
2356                         echo "(Bauer et al., 2007, BMC Bioinformatics 8:271)." 1>>"$progressfile"
2357                 fi
2358                 if [ $distance = "foldalignlocal" ]; then
2359                         echo "Pairwise alignments were computed by FOLDALIGN (local)" 1>>"$progressfile"
2360                         echo "(Havgaard et al., 2007, PLoS Computational Biology 3:e193)." 1>>"$progressfile"
2361                 fi
2362                 if [ $distance = "foldalignglobal" ]; then
2363                         echo "Pairwise alignments were computed by FOLDALIGN (global)" 1>>"$progressfile"
2364                         echo "(Havgaard et al., 2007, PLoS Computational Biology 3:e193)." 1>>"$progressfile"
2365                 fi
2366 #               printf "\n" 1>>"$progressfile"
2367                 echo 'Strategy:' 1>>"$progressfile"
2368                 printf ' '$strategy 1>>"$progressfile"
2369                 echo ' ('$performance')' 1>>"$progressfile"
2370                 echo ' '$explanation 1>>"$progressfile"
2371                 echo '' 1>>"$progressfile"
2372                 echo "If unsure which option to use, try 'mafft --auto input > output'." 1>>"$progressfile"
2373                 echo "For more information, see 'mafft --help', 'mafft --man' and the mafft page." 1>>"$progressfile"
2374                 echo "" 1>>"$progressfile"
2375                 echo "The default gap scoring scheme has been changed in version 7.110 (2013 Oct)." 1>>"$progressfile"
2376                 echo "It tends to insert more gaps into gap-rich regions than previous versions." 1>>"$progressfile"
2377                 echo "To disable this change, add the --leavegappyregion option." 1>>"$progressfile"
2378 #               echo "If long gaps are expected, try 'mafft --ep 0.0 --auto input > output'." 1>>"$progressfile"
2379 #               echo "If the possibility of long gaps can be excluded, add '--ep 0.123'." 1>>"$progressfile"
2380                 if [ $distance = "localgenaf" -o $distance = "globalgenaf" ]; then
2381                         echo "" 1>>"$progressfile"
2382                         if [ $oldgenafparam -eq 1 ]; then
2383                                 echo "Obsolete parameters used for this calculation." 1>>"$progressfile"
2384                                 echo "Also try the new parameters for E-INS-i, by not specifying --oldgenafpair." 1>>"$progressfile"
2385                         else
2386                                 echo "Parameters for the E-INS-i option have been changed in version 7.243 (2015 Jun)." 1>>"$progressfile"
2387                                 echo "To switch to the old parameters, use --oldgenafpair, instead of --genafpair." 1>>"$progressfile"
2388                         fi
2389                 fi
2390                 echo '' 1>>"$progressfile"
2391
2392                 
2393                 if [ $pdblist != "/dev/null" -o $ownlist != "/dev/null" ]; then
2394                         cat dasherr >>"$progressfile"
2395                 fi
2396
2397 #       ) # 2017/Mar/17
2398         popd > /dev/null;
2399
2400
2401         if [ "$outputfile" = "" ]; then
2402                 if [ "$outputopt" = "null" ]; then
2403                         cat < $TMPFILE/pre || exit 1
2404                 else
2405                         "$prefix/f2cl" -n $namelength $outputopt < $TMPFILE/pre 2>>/dev/null || exit 1
2406                 fi
2407         else
2408                 if [ "$outputopt" = "null" ]; then
2409                         cat < $TMPFILE/pre > "$outputfile" || exit 1
2410                 else
2411                         "$prefix/f2cl" -n $namelength $outputopt < $TMPFILE/pre > "$outputfile" 2>>/dev/null || exit 1
2412                 fi
2413         fi
2414
2415         if [ $treeout -eq 1 ]; then
2416                 cp $TMPFILE/infile.tree "$infilename.tree"
2417         fi
2418
2419         if [ -s $TMPFILE/GuideTree ]; then # --merge no toki dake
2420                 cp $TMPFILE/GuideTree .
2421         fi
2422
2423         if [ $distout -eq 1 ]; then
2424                 cp $TMPFILE/hat2 "$infilename.hat2"
2425         fi
2426
2427         if [ $npickup -ne 0 ]; then
2428                 cp $TMPFILE/notused "$infilename.notused"
2429         fi
2430
2431         if [ -s $TMPFILE/_deletemap ]; then
2432                 if [ "$mapoutfile" = "/dev/null" ]; then
2433                         cp $TMPFILE/_deletemap "$addfile.map"
2434                 else
2435                         cp $TMPFILE/_deletemap "$mapoutfile"
2436                 fi
2437         fi
2438
2439         exit 0;
2440 fi
2441
2442 prog="awk"
2443
2444 tmpawk=`which nawk 2>/dev/null | awk '{print $1}'`
2445 if [ -x "$tmpawk" ]; then
2446         prog="$tmpawk"
2447 fi
2448
2449 tmpawk=`which gawk 2>/dev/null | awk '{print $1}'`
2450 if [ -x "$tmpawk" ]; then
2451         prog="$tmpawk"
2452 fi
2453
2454 #echo "prog="$prog 1>&2
2455
2456 umask 077
2457 (
2458 $prog '
2459 BEGIN {
2460         prefix = ENVIRON["prefix"];
2461         version = ENVIRON["version"];
2462         myself = ENVIRON["myself"];
2463         while( 1 )
2464         {
2465                 options = ""
2466                 printf( "\n" ) > "/dev/tty";
2467                 printf( "---------------------------------------------------------------------\n" )      > "/dev/tty";
2468                 printf( "\n" )                                                                           > "/dev/tty";
2469                 printf( "   MAFFT %s\n", version )                                                       > "/dev/tty";
2470                 printf( "\n" )                                                                           > "/dev/tty";
2471                 printf( "        Copyright (c) 2016 Kazutaka Katoh\n" )                                  > "/dev/tty";
2472                 printf( "        MBE 30:772-780 (2013), NAR 30:3059-3066 (2002)\n" )                     > "/dev/tty";
2473                 printf( "        http://mafft.cbrc.jp/alignment/software/\n" )                           > "/dev/tty";
2474                 printf( "---------------------------------------------------------------------\n" )      > "/dev/tty";
2475                 printf( "\n" ) > "/dev/tty";
2476         
2477                 while( 1 )
2478                 {
2479                         printf( "\n" ) > "/dev/tty";
2480                         printf( "Input file? (fasta format)\n@ " ) > "/dev/tty";
2481                         res = getline < "/dev/tty";
2482                         close( "/dev/tty" )
2483                         if( res == 0 || NF == 0 )
2484                                 continue;
2485                         infile = sprintf( "%s", $0 );
2486         
2487                         res = getline < infile;
2488                         close( infile );
2489                         if( res == -1 )
2490                         {
2491                                 printf( "%s: No such file.\n\n", infile ) > "/dev/tty";
2492                                 printf( "Filename extension (eg., .txt) must be typed, if any.\n\n" ) > "/dev/tty";
2493                         }
2494                         else if( res == 0 )
2495                                 printf( "%s: Empty.\n", infile ) > "/dev/tty";
2496                         else
2497                         {
2498                                 printf( "OK. infile = %s\n\n", infile ) > "/dev/tty";
2499                                 break;
2500                         }
2501                 }
2502                 nseq = 0;
2503         
2504                 while( 1 )
2505                 {
2506                         printf( "\n" ) > "/dev/tty";
2507                         printf( "Output file?\n" ) > "/dev/tty";
2508                         printf( "@ " ) > "/dev/tty";
2509                         res = getline < "/dev/tty";
2510                         close( "/dev/tty" );
2511                         if( res == 0 || NF == 0 )
2512                                 continue;
2513                         else
2514                         {
2515                                 outfile = sprintf( "%s", $0 );
2516                                 printf( "OK. outfile = %s\n\n", outfile ) > "/dev/tty";
2517                                 break;
2518                         }
2519                 }
2520         
2521                 while( 1 )
2522                 {
2523                         outargs = "";
2524                         printf( "\n" ) > "/dev/tty";
2525                         printf( "Output format?\n" ) > "/dev/tty";
2526                         printf( "  1. Clustal format / Sorted\n" ) > "/dev/tty";
2527                         printf( "  2. Clustal format / Input order\n" ) > "/dev/tty";
2528                         printf( "  3. Fasta format   / Sorted\n" ) > "/dev/tty";
2529                         printf( "  4. Fasta format   / Input order\n" ) > "/dev/tty";
2530                         printf( "  5. Phylip format  / Sorted\n" ) > "/dev/tty";
2531                         printf( "  6. Phylip format  / Input order\n" ) > "/dev/tty";
2532                         printf( "@ " ) > "/dev/tty";
2533                         res = getline < "/dev/tty";
2534                         close( "/dev/tty" );
2535 #                       printf( "res=%d, NF=%d\n", res, NF );
2536
2537                         resnum = 0 + $1;
2538 #                       printf( "resnum=%d\n", resnum );
2539
2540                         if( resnum < 1 || 6 < resnum )
2541                                 continue;
2542                         else
2543                         {
2544                                 if( resnum == 1 )
2545                                         outargs = "--clustalout --reorder";
2546                                 else if( resnum == 2 )
2547                                         outargs = "--clustalout --inputorder";
2548                                 else if( resnum == 3 )
2549                                         outargs = "--reorder";
2550                                 else if( resnum == 4 )
2551                                         outargs = "--inputorder";
2552                                 else if( resnum == 5 )
2553                                         outargs = "--phylipout --reorder";
2554                                 else if( resnum == 6 )
2555                                         outargs = "--phylipout --inputorder";
2556                                 else
2557                                         continue;
2558                                 printf( "OK. arguments = %s\n\n", outargs ) > "/dev/tty";
2559                                 break;
2560                         }
2561                 }
2562         
2563                 while( 1 )
2564                 {
2565                         arguments = "";
2566                         printf( "\n" ) > "/dev/tty";
2567                         printf( "Strategy?\n" ) > "/dev/tty";
2568                         printf( "  1. --auto\n" ) > "/dev/tty";
2569                         printf( "  2. FFT-NS-1 (fast)\n" ) > "/dev/tty";
2570                         printf( "  3. FFT-NS-2 (default)\n" ) > "/dev/tty";
2571                         printf( "  4. G-INS-i  (accurate)\n" ) > "/dev/tty";
2572                         printf( "  5. L-INS-i  (accurate)\n" ) > "/dev/tty";
2573                         printf( "  6. E-INS-i  (accurate)\n" ) > "/dev/tty";
2574                         printf( "@ " ) > "/dev/tty";
2575                         res = getline < "/dev/tty";
2576                         close( "/dev/tty" );
2577 #                       printf( "res=%d, NF=%d\n", res, NF );
2578
2579                         resnum = 0 + $1;
2580 #                       printf( "resnum=%d\n", resnum );
2581
2582                         if( resnum < 1 || 6 < resnum )
2583                                 continue;
2584                         else
2585                         {
2586                                 if( resnum == 1 )
2587                                         arguments = "--auto";
2588                                 else if( resnum == 2 )
2589                                         arguments = "--retree 1";
2590                                 else if( resnum == 3 )
2591                                         arguments = "--retree 2";
2592                                 else if( resnum == 4 )
2593                                         arguments = "--globalpair --maxiterate 16";
2594                                 else if( resnum == 5 )
2595                                         arguments = "--localpair  --maxiterate 16";
2596                                 else if( resnum == 6 )
2597                                         arguments = "--genafpair  --maxiterate 16";
2598                                 else
2599                                         arguments = sprintf( "%s", $0 );
2600                                 printf( "OK. arguments = %s %s\n\n", arguments, outargs ) > "/dev/tty";
2601                                 break;
2602                         }
2603                 }
2604
2605
2606                 while( 1 )
2607                 {
2608                         printf( "\n" ) > "/dev/tty";
2609                         printf( "Additional arguments? (--ep # --op # --kappa # etc)\n" ) > "/dev/tty";
2610                         printf( "@ " ) > "/dev/tty";
2611                         res = getline < "/dev/tty";
2612                         close( "/dev/tty" );
2613                         if( res == 0 || NF == 0 )
2614                         {
2615                                 break;
2616                         }
2617                         else
2618                         {
2619                                 addargs = sprintf( "%s", $0 );
2620                                 printf( "OK. arguments = %s %s %s\n\n", addargs, arguments, outargs ) > "/dev/tty";
2621                                 break;
2622                         }
2623                 }
2624
2625                 arguments = sprintf( "%s %s %s", addargs, arguments, outargs );
2626
2627                 print ""
2628                 command = sprintf( "\"%s\" %s \"%s\" > \"%s\"", myself, arguments, infile, outfile );
2629                 gsub( /\\/, "/", command );
2630
2631
2632                 printf( "command=\n%s\n", command ) > "/dev/tty";
2633         
2634         
2635                 while( 1 )
2636                 {
2637                         go = 0;
2638                         printf( "OK?\n" ) > "/dev/tty";
2639                         printf( "@ [Y] " ) > "/dev/tty";
2640                         res = getline < "/dev/tty";
2641                         close( "/dev/tty" );
2642                         if( res == 0 )
2643                                 continue;
2644                         else if( NF == 0 || $0 ~ /^[Yy]/ )
2645                         {
2646                                 go=1;
2647                                 break;
2648                         }
2649                         else
2650                                 break;
2651                 }
2652                 if( go ) break;
2653                 printf( "\n" ) > "/dev/tty";
2654                 printf( "\n" ) > "/dev/tty";
2655         }
2656         system( command );
2657         command = sprintf( "more \"%s\"", outfile );
2658         system( command );
2659         printf( "Press Enter to exit." ) > "/dev/tty";
2660         res = getline < "/dev/tty";
2661 }
2662 '
2663 )
2664 exit 0;